/**
  * @param \PHPStan\Reflection\ClassReflection $classReflection
  * @param string $propertyName
  * @return \PHPStan\Reflection\MethodReflection|null
  */
 private function getMethodByProperty(ClassReflection $classReflection, string $propertyName)
 {
     $getterMethodName = sprintf('get%s', ucfirst($propertyName));
     if (!$classReflection->hasMethod($getterMethodName)) {
         return null;
     }
     return $classReflection->getMethod($getterMethodName);
 }
 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();
 }
 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;
 }
Exemplo n.º 5
0
 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $this->returnType = TypehintHelper::decideType($this->reflection->getReturnType(), $this->phpDocReturnType, $this->declaringClass->getName());
     }
     return $this->returnType;
 }
Exemplo n.º 6
0
 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $returnType = $this->reflection->getReturnType();
         $phpDocReturnType = $this->phpDocReturnType;
         if ($returnType !== null && $phpDocReturnType !== null && $returnType->allowsNull() !== $phpDocReturnType->isNullable()) {
             $phpDocReturnType = null;
         }
         $this->returnType = TypehintHelper::decideTypeFromReflection($returnType, $phpDocReturnType, $this->declaringClass->getName());
     }
     return $this->returnType;
 }
 public function hasMethod(ClassReflection $classReflection, string $methodName) : bool
 {
     return $classReflection->getName() === \Dibi\Fluent::class;
 }
 /**
  * @param \PHPStan\Reflection\ClassReflection $classReflection
  * @return string|boolean
  */
 private function getParentConstructorClass(ClassReflection $classReflection)
 {
     while ($classReflection->getParentClass() !== false) {
         if ($classReflection->getParentClass()->hasMethod('__construct') && $classReflection->getParentClass()->getMethod('__construct')->getDeclaringClass()->getName() === $classReflection->getParentClass()->getName() || $classReflection->getParentClass()->hasMethod($classReflection->getParentClass()->getName()) && $classReflection->getParentClass()->getMethod($classReflection->getParentClass()->getName())->getDeclaringClass()->getName() === $classReflection->getParentClass()->getName()) {
             return $classReflection->getParentClass();
         }
         $classReflection = $classReflection->getParentClass();
     }
     return false;
 }
 public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
 {
     return $classReflection->getName() === Html::class || $classReflection->isSubclassOf(Html::class);
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
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;
 }
 public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
 {
     return $classReflection->isSubclassOf(Node::class) && $classReflection->getNativeReflection()->hasProperty('name') && $propertyName === 'namespacedName';
 }