Copied from ClassGenerator::fromReflection and tweaked slightly

@param ClassReflection $classReflection

@return ClassGenerator
357538
public function getGeneratorFromReflection(ClassReflection $classReflection)
  {
    // class generator
    $cg = new ClassGenerator($classReflection->getName());

    $cg->setSourceContent($cg->getSourceContent());
    $cg->setSourceDirty(false);

    if ($classReflection->getDocComment() != '')
    {
      $docblock
        = DocBlockGenerator::fromReflection($classReflection->getDocBlock());
      $docblock->setIndentation(Generator::$indentation);
      $cg->setDocBlock($docblock);
    }

    $cg->setAbstract($classReflection->isAbstract());

    // set the namespace
    if ($classReflection->inNamespace())
    {
      $cg->setNamespaceName($classReflection->getNamespaceName());
    }

    /* @var \Zend\Code\Reflection\ClassReflection $parentClass */
    $parentClass = $classReflection->getParentClass();
    if ($parentClass)
    {
      $cg->setExtendedClass('\\' . ltrim($parentClass->getName(), '\\'));
      $interfaces = array_diff($classReflection->getInterfaces(),
                               $parentClass->getInterfaces());
    }
    else
    {
      $interfaces = $classReflection->getInterfaces();
    }

    $interfaceNames = array();
    foreach ($interfaces as $interface)
    {
      /* @var \Zend\Code\Reflection\ClassReflection $interface */
      $interfaceNames[] = $interface->getName();
    }

    $cg->setImplementedInterfaces($interfaceNames);

    $properties = array();
    foreach ($classReflection->getProperties() as $reflectionProperty)
    {
      if (
        $reflectionProperty->getDeclaringClass()->getName()
        == $classReflection->getName()
      )
      {
        $property = PropertyGenerator::fromReflection($reflectionProperty);
        $property->setIndentation(Generator::$indentation);
        $properties[] = $property;
      }
    }
    $cg->addProperties($properties);

    $methods = array();
    foreach ($classReflection->getMethods() as $reflectionMethod)
    {
      $className
        = ($cg->getNamespaceName()) ? $cg->getNamespaceName() . "\\" . $cg->getName() : $cg->getName();
      if ($reflectionMethod->getDeclaringClass()->getName() == $className)
      {
        $method = MethodGenerator::fromReflection($reflectionMethod);
        $method->setBody(
          preg_replace(
            "/^" . Generator::$indentation . Generator::$indentation . "/m",
            '',
            $method->getBody()
          )
        );
        $method->setIndentation(Generator::$indentation);
        $methods[] = $method;
      }
    }
    $cg->addMethods($methods);

    return $cg;
  }
847982
protected function getBridgedInterfaceReflection(array $classMethods): ?ReflectionClass
    {
        foreach ($classMethods as $classMethod) {
            if ($classMethod->getName() === '__construct') {
                $constructorComment = $classMethod->getNode()->getComment();

                if (!$constructorComment) {
                    return null;
                }

                $firstParameter = $classMethod->getNode()->getParameters()[0];

                if (!$firstParameter) {
                    return null;
                }

                $pattern = '#@param[\s]+(?<interfaceName>.*)[\s]+' . preg_quote($firstParameter->getName()) . '#is';

                if (preg_match($pattern, $constructorComment, $matches) === 0) {
                    return null;
                }

                //todo: Spryker\Zed\Ratepay\Dependency\Facade\RatepayToSalesAggregatorBridge - need to fix
                return new ReflectionClass($matches['interfaceName']);
            }
        }

        return null;
    }
897191
static function classLikeGetFirstLevelInterfaces(ClassLikeReflectionInterface $classLikeReflection) {
    if ($classLikeReflection->isInterface()) {
      return array($classLikeReflection->getName() => $classLikeReflection);
    }
    $interfaces = $classLikeReflection->getOwnInterfaces();
    if (NULL !== $parentClass = $classLikeReflection->getParentClass()) {
      $interfaces += self::classLikeGetFirstLevelInterfaces($parentClass);
    }
    return $interfaces;
  }
605285
public function getMixins(ClassReflection $reflection) : array
    {
        preg_match_all(
            '/@mixin\s+([\w\\\\]+)/',
            (string) $reflection->getNativeReflection()->getDocComment(),
            $mixins
        );

        return array_map(function ($mixin) {
            return preg_replace('#^\\\\#', '', $mixin);
        }, $mixins[1]);
    }
666155
public function getReflectionClass()
    {
        if ( ! $this->reflClass) {
            $this->reflClass = new \ReflectionClass($this->name);
        }
        return $this->reflClass;
    }
1244645
private function getClassTranslation(\ReflectionClass $classReflection, $parseDocComments)
    {
        if ($parseDocComments) {
            $translation = $this->parseTranslationFromDocComment($classReflection->getDocComment());

            if (!empty($translation)) {
                return $translation;
            }
        }

        return StringsUtil::humanize($this->entityNamer->name($classReflection->getName()));
    }
57068
private function getReflectionClass($className) : ReflectionClass
    {
        if (! class_exists($className)) {
            throw InvalidArgumentException::fromNonExistingClass($className);
        }

        $reflection = new ReflectionClass($className);

        if ($reflection->isAbstract()) {
            throw InvalidArgumentException::fromAbstractClass($reflection);
        }

        return $reflection;
    }
406397
private function createWithReflection($className)
    {
        $class = new ReflectionClass($className);
        $prototypeInstance = $class->newInstanceWithoutConstructor();

        /**
         * @var IPrototype $prototype
         */
        $prototype = new $this->prototypeClass(
            $prototypeInstance,
            $class->getInterfaceNames(),
            $this->getClassConstructorInfo($class),
            $this->getClassOptions($class, $prototypeInstance)
        );

        if (!$prototype instanceof IPrototype) {
            throw new RuntimeException(sprintf(
                'Prototype class "%s" should implement IPrototype.',
                $this->prototypeClass
            ));
        }

        return $prototype;
    }
864543
public function getReflectionMember($objectOrClassName)
    {
        $className = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
        if (!isset($this->reflMember[$className])) {
            $this->reflMember[$className] = $this->newReflectionMember($objectOrClassName);
        }

        return $this->reflMember[$className];
    }
899646
public function getClassReflector($class)
    {
        if (is_object($class)) {
            $class = get_class($class);
        }
        if (!isset($this->reflectors[ $class ])) {
            $this->reflectors[ $class ] = new \ReflectionClass($class);
        }

        return $this->reflectors[ $class ];
    }
1324323
private function getReflection(): \ReflectionClass
    {
        if ($this->_intruderReflection === null) {
            $this->_intruderReflection = new \ReflectionClass($this->_intruderInstance);
        }

        return $this->_intruderReflection;
    }
1341409
private function createMethod(ClassReflection $classReflection, \ReflectionFunction $functionReflection, string $methodName): MethodReflection
    {

        $phpDocParameterTypes = [];
        $phpDocReturnType = null;
        if ($functionReflection->getFileName() !== false && $functionReflection->getDocComment() !== false) {
            $resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc(
                $functionReflection->getFileName(),
                null,
                $functionReflection->getDocComment()
            );

            $phpDocParameterTypes = array_map(function (ParamTag $tag): Type {
                return $tag->getType();
            }, $resolvedPhpDoc->getParamTags());
            $phpDocReturnType = $resolvedPhpDoc->getReturnTag() !== null ? $resolvedPhpDoc->getReturnTag()->getType() : null;
        }

        return $this->methodReflectionFactory->create(
            $classReflection,
            new ReflectionMethodFunctionProxy($classReflection->getName(), $methodName, $functionReflection),
            $phpDocParameterTypes,
            $phpDocReturnType
        );
    }
1109305
private static function getReflectionMethod(string $method, $objectOrClass, $classOverride = null): ReflectionMethod
    {
        $class = $classOverride;
        if ($class === null) {
            if (is_object($objectOrClass)) {
                $class = get_class($objectOrClass);
            } else {
                $class = $objectOrClass;
            }
        }
        return new ReflectionMethod($class, $method);
    }
614432
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) : void
    {
        CanProxyAssertion::assertClassCanBeProxied($originalClass);

        $interfaces = [NullObjectInterface::class];

        if ($originalClass->isInterface()) {
            $interfaces[] = $originalClass->getName();
        } else {
            $classGenerator->setExtendedClass($originalClass->getName());
        }

        $classGenerator->setImplementedInterfaces($interfaces);

        foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass, []) as $method) {
            $classGenerator->addMethodFromGenerator(
                NullObjectMethodInterceptor::generateMethod(
                    new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())
                )
            );
        }

        ClassGeneratorUtils::addMethodIfNotFinal(
            $originalClass,
            $classGenerator,
            new StaticProxyConstructor($originalClass)
        );
    }
199431
private function createReflection(callable $callable)
    {
        if (is_string($callable) && strpos($callable, '::')) {
            $callable = explode('::', $callable);
        }

        if (is_array($callable)) {
            return new ReflectionMethod($callable[0], $callable[1]);
        }

        if (is_object($callable) && method_exists($callable, '__invoke')) {
            return new ReflectionMethod($callable, '__invoke');
        }

        return new ReflectionFunction($callable);
    }
577124
protected function parseClassSpecifications(ClassReflection $class, ArrayObject $serviceSpec)
    {
        if ($class->getParentClass()) {
            $this->parseClassSpecifications($class->getParentClass(), $serviceSpec);
        }
        
        $annotationManager = $this->getAnnotationManager();
        $annotations = $class->getAnnotations($annotationManager);
        
        if (!array_key_exists('version', $serviceSpec)) {
            $serviceSpec['version'] = null;
        }
        
        // Each class must define its own exclusion pattern
        $serviceSpec['exclude_patterns'] = array();
        $serviceSpec['exclude'] = false;
        $serviceSpec['contexts'] = array('native');
        
        if ($annotations instanceof AnnotationCollection) {
            $this->configureService($annotations, $class, $serviceSpec);
        }
        
        // Exit here if service is excluded
        if ($serviceSpec['exclude']) {
            return;
        }
        
        foreach ($class->getMethods() as $method) {
            
            // Skip method if it is not owned by this class
            if ($method->getDeclaringClass()->getName() !== $class->getName()) {
                continue;
            }
            
            // Skip method declared in Trait due to ZF2 bug
            if ($this->isDeclaredInTrait($method)) {
                continue;
            }
            
            try{
                $annotations = $method->getAnnotations($annotationManager);
            } catch(\Doctrine\Common\Annotations\AnnotationException $e) {
                throw new AnnotationException(
                    'Error parsing annotation for class "'.$class->getName().'::'.$method->getName().'"', 0, $e);
            } catch(\Exception $e) {
                // Due to ZF2 bug with parsing annotations for traits, skip related error
                if (strpos($e->getMessage(), 'Argument 3 passed to Zend\Code\Scanner\AnnotationScanner') === 0) {
                    continue;
                }
                
                throw $e;
            }
            
            if (!$annotations instanceof AnnotationCollection) {
                $annotations = new AnnotationCollection();
            }
        
            $this->configureOperation($annotations, $method, $serviceSpec);
        }
    }
1118120
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
    {
        CanProxyAssertion::assertClassCanBeProxied($originalClass, false);

        $classGenerator->setExtendedClass($originalClass->getName());
        $classGenerator->setImplementedInterfaces([AccessInterceptorInterface::class]);
        $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
        $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodSuffixInterceptors());

        array_map(
            static function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) : void {
                ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
            },
            array_merge(
                array_map(
                    $this->buildMethodInterceptor($prefixInterceptors, $suffixInterceptors),
                    ProxiedMethodsFilter::getProxiedMethods(
                        $originalClass,
                        ['__get', '__set', '__isset', '__unset', '__clone', '__sleep']
                    )
                ),
                [
                    new StaticProxyConstructor($originalClass),
                    new BindProxyProperties($originalClass, $prefixInterceptors, $suffixInterceptors),
                    new SetMethodPrefixInterceptor($prefixInterceptors),
                    new SetMethodSuffixInterceptor($suffixInterceptors),
                    new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors),
                    new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors),
                    new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors),
                    new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors),
                    new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors),
                    new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors),
                ]
            )
        );
    }