getNativeReflection() public method

public getNativeReflection ( ) : ReflectionClass
return ReflectionClass
コード例 #1
0
 public function isVariadic() : bool
 {
     $isNativelyVariadic = $this->reflection->isVariadic();
     if (!$isNativelyVariadic && $this->declaringClass->getName() === 'ReflectionMethod' && $this->reflection->getName() === 'invoke') {
         return true;
     }
     if (!$isNativelyVariadic && $this->declaringClass->getNativeReflection()->getFileName() !== false) {
         $key = sprintf('variadic-method-%s-%s-v2', $this->declaringClass->getName(), $this->reflection->getName());
         $cachedResult = $this->cache->load($key);
         if ($cachedResult === null) {
             $nodes = $this->parser->parseFile($this->declaringClass->getNativeReflection()->getFileName());
             $result = $this->callsFuncGetArgs($nodes);
             $this->cache->save($key, $result);
             return $result;
         }
         return $cachedResult;
     }
     return $isNativelyVariadic;
 }
コード例 #2
0
 public function hasMethod(ClassReflection $classReflection, string $methodName) : bool
 {
     $traitNames = $this->getTraitNames($classReflection->getNativeReflection());
     if (!$classReflection->isSubclassOf(Object::class) && !in_array(\Nette\SmartObject::class, $traitNames, true)) {
         return false;
     }
     if (substr($methodName, 0, 2) !== 'on' || strlen($methodName) <= 2) {
         return false;
     }
     return $classReflection->hasProperty($methodName) && $classReflection->getProperty($methodName)->isPublic();
 }
コード例 #3
0
 public function getMethod(ClassReflection $classReflection, string $methodName) : MethodReflection
 {
     $metadata = $this->metadataSource->getMetadataForClass($classReflection->getNativeReflection());
     $sentryMethodSearchResult = $metadata->getSentryMethodByNameAndRequiredVisibility($methodName, Visibility::get(Visibility::VISIBILITY_PRIVATE));
     $property = $sentryMethodSearchResult->getProperty();
     $sentryMethod = $sentryMethodSearchResult->getSentryMethod();
     $sentryAccess = $sentryMethod->getSentryAccess();
     $isSetter = $sentryAccess->equals(new SentryAccess('set'));
     $methodHasParameter = $isSetter || $sentryAccess->equals(new SentryAccess('add')) || $sentryAccess->equals(new SentryAccess('remove')) || $sentryAccess->equals(new SentryAccess('contains'));
     $propertyClass = $this->broker->getClass($property->getClassName());
     return new SentryMethodReflection($methodName, $propertyClass, $sentryMethod->getMethodVisibility(), $this->phpClassReflectionExtension->getProperty($propertyClass, $property->getName())->getType(), $methodHasParameter ? $isSetter ? $property->isNullable() : false : null);
 }
 public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
 {
     if ($classReflection->getNativeReflection()->hasProperty($propertyName)) {
         return false;
     }
     foreach ($this->classes as $className) {
         if ($classReflection->getName() === $className || $classReflection->isSubclassOf($className)) {
             return true;
         }
     }
     return false;
 }
 public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
 {
     $traitNames = $this->getTraitNames($classReflection->getNativeReflection());
     if (!in_array(\Nette\SmartObject::class, $traitNames, true)) {
         return false;
     }
     $property = \Nette\Utils\ObjectMixin::getMagicProperty($classReflection->getName(), $propertyName);
     if ($property === null) {
         return false;
     }
     $getterMethod = $this->getMethodByProperty($classReflection, $propertyName);
     if ($getterMethod === null) {
         return false;
     }
     return $getterMethod->isPublic();
 }
コード例 #6
0
 /**
  * @param \PHPStan\Reflection\ClassReflection $classReflection
  * @return \PHPStan\Reflection\MethodReflection[]
  */
 private function createMethods(ClassReflection $classReflection) : array
 {
     $methods = [];
     foreach ($classReflection->getNativeReflection()->getMethods() as $methodReflection) {
         $declaringClass = $this->broker->getClass($methodReflection->getDeclaringClass()->getName());
         $phpDocParameterTypes = [];
         $phpDocReturnType = null;
         if (!$declaringClass->getNativeReflection()->isAnonymous() && $declaringClass->getNativeReflection()->getFileName() !== false) {
             $typeMap = $this->fileTypeMapper->getTypeMap($declaringClass->getNativeReflection()->getFileName());
             if ($methodReflection->getDocComment() !== false) {
                 $phpDocParameterTypes = TypehintHelper::getPhpDocParameterTypesFromMethod($typeMap, array_map(function (\ReflectionParameter $parameterReflection) : string {
                     return $parameterReflection->getName();
                 }, $methodReflection->getParameters()), $methodReflection->getDocComment());
             }
             if ($methodReflection->getDocComment() !== false) {
                 $phpDocReturnType = TypehintHelper::getPhpDocReturnTypeFromMethod($typeMap, $methodReflection->getDocComment());
             }
         }
         $methods[strtolower($methodReflection->getName())] = $this->methodReflectionFactory->create($declaringClass, $methodReflection, $phpDocParameterTypes, $phpDocReturnType);
     }
     return $methods;
 }
コード例 #7
0
 /**
  * @param \PHPStan\Reflection\ClassReflection $classReflection
  * @return \PHPStan\Reflection\MethodReflection[]
  */
 private function createMethods(ClassReflection $classReflection) : array
 {
     $methods = [];
     foreach ($classReflection->getNativeReflection()->getMethods() as $methodReflection) {
         $declaringClass = $this->broker->getClass($methodReflection->getDeclaringClass()->getName());
         $phpDocParameters = $this->getPhpDocParamsFromMethod($methodReflection);
         $phpDocParameterTypes = [];
         if (!$declaringClass->getNativeReflection()->isAnonymous() && $declaringClass->getNativeReflection()->getFileName() !== false) {
             $typeMap = $this->fileTypeMapper->getTypeMap($declaringClass->getNativeReflection()->getFileName());
             foreach ($methodReflection->getParameters() as $parameterReflection) {
                 $typeString = $this->getMethodParameterAnnotationTypeString($phpDocParameters, $parameterReflection);
                 if ($typeString === null || !isset($typeMap[$typeString])) {
                     continue;
                 }
                 $type = $typeMap[$typeString];
                 $phpDocParameterTypes[$parameterReflection->getName()] = $type;
             }
         }
         $phpDocReturnType = null;
         $returnTypeString = $this->getReturnTypeStringFromMethod($methodReflection);
         if ($returnTypeString !== null && isset($typeMap[$returnTypeString])) {
             $phpDocReturnType = $typeMap[$returnTypeString];
         }
         $methods[strtolower($methodReflection->getName())] = $this->methodReflectionFactory->create($declaringClass, $methodReflection, $phpDocParameterTypes, $phpDocReturnType);
     }
     return $methods;
 }
コード例 #8
0
 public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
 {
     return $classReflection->isSubclassOf(Node::class) && $classReflection->getNativeReflection()->hasProperty('name') && $propertyName === 'namespacedName';
 }