class AccessDeprecatedPropertyRule
@implements Rule<PropertyFetch>
Hierarchy
- class \PHPStan\Rules\Deprecations\AccessDeprecatedPropertyRule implements \PHPStan\Rules\Rule
Expanded class hierarchy of AccessDeprecatedPropertyRule
File
-
vendor/
phpstan/ phpstan-deprecation-rules/ src/ Rules/ Deprecations/ AccessDeprecatedPropertyRule.php, line 20
Namespace
PHPStan\Rules\DeprecationsView source
class AccessDeprecatedPropertyRule implements Rule {
/** @var ReflectionProvider */
private $reflectionProvider;
/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) {
$this->reflectionProvider = $reflectionProvider;
$this->deprecatedScopeHelper = $deprecatedScopeHelper;
}
public function getNodeType() : string {
return PropertyFetch::class;
}
public function processNode(Node $node, Scope $scope) : array {
if ($this->deprecatedScopeHelper
->isScopeDeprecated($scope)) {
return [];
}
if (!$node->name instanceof Identifier) {
return [];
}
$propertyName = $node->name->name;
$propertyAccessedOnType = $scope->getType($node->var);
$referencedClasses = $propertyAccessedOnType->getObjectClassNames();
foreach ($referencedClasses as $referencedClass) {
try {
$classReflection = $this->reflectionProvider
->getClass($referencedClass);
$propertyReflection = $classReflection->getProperty($propertyName, $scope);
if ($propertyReflection->isDeprecated()
->yes()) {
$description = $propertyReflection->getDeprecatedDescription();
if ($description === null) {
return [
RuleErrorBuilder::message(sprintf('Access to deprecated property $%s of %s %s.', $propertyName, strtolower($propertyReflection->getDeclaringClass()
->getClassTypeDescription()), $propertyReflection->getDeclaringClass()
->getName()))
->identifier('property.deprecated')
->build(),
];
}
return [
RuleErrorBuilder::message(sprintf("Access to deprecated property \$%s of %s %s:\n%s", $propertyName, strtolower($propertyReflection->getDeclaringClass()
->getClassTypeDescription()), $propertyReflection->getDeclaringClass()
->getName(), $description))
->identifier('property.deprecated')
->build(),
];
}
} catch (ClassNotFoundException $e) {
// Other rules will notify if the class is not found
} catch (MissingPropertyFromReflectionException $e) {
// Other rules will notify if the property is not found
}
}
return [];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
AccessDeprecatedPropertyRule::$deprecatedScopeHelper | private | property | @var DeprecatedScopeHelper |
AccessDeprecatedPropertyRule::$reflectionProvider | private | property | @var ReflectionProvider |
AccessDeprecatedPropertyRule::getNodeType | public | function | |
AccessDeprecatedPropertyRule::processNode | public | function | |
AccessDeprecatedPropertyRule::__construct | public | function |