Skip to content

Commit 5685fe4

Browse files
committed
Report descriptions of @deprecated tags
1 parent f5b1a45 commit 5685fe4

File tree

47 files changed

+450
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+450
-52
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"require": {
99
"php": "~7.1",
1010
"nikic/php-parser": "^4.0",
11-
"phpstan/phpstan": "^0.11.4"
11+
"phpstan/phpstan": "^0.11.8"
1212
},
1313
"require-dev": {
1414
"consistence/coding-standard": "^3.0.1",

Diff for: src/Rules/Deprecations/AccessDeprecatedPropertyRule.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,24 @@ public function processNode(Node $node, Scope $scope): array
5555
}
5656

5757
if ($propertyReflection->isDeprecated()) {
58+
$description = null;
59+
if (method_exists($propertyReflection, 'getDeprecatedDescription')) {
60+
$description = $propertyReflection->getDeprecatedDescription();
61+
}
62+
63+
if ($description === null) {
64+
return [sprintf(
65+
'Access to deprecated property $%s of class %s.',
66+
$propertyName,
67+
$propertyReflection->getDeclaringClass()->getName()
68+
)];
69+
}
70+
5871
return [sprintf(
59-
'Access to deprecated property $%s of class %s.',
72+
"Access to deprecated property $%s of class %s:\n%s",
6073
$propertyName,
61-
$propertyReflection->getDeclaringClass()->getName()
74+
$propertyReflection->getDeclaringClass()->getName(),
75+
$description
6276
)];
6377
}
6478
} catch (\PHPStan\Broker\ClassNotFoundException $e) {

Diff for: src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,24 @@ function (Type $type) use ($propertyName): bool {
8181
}
8282

8383
if ($property instanceof DeprecatableReflection && $property->isDeprecated()) {
84+
$description = null;
85+
if (method_exists($property, 'getDeprecatedDescription')) {
86+
$description = $property->getDeprecatedDescription();
87+
}
88+
89+
if ($description === null) {
90+
return [sprintf(
91+
'Access to deprecated static property $%s of class %s.',
92+
$propertyName,
93+
$referencedClass
94+
)];
95+
}
96+
8497
return [sprintf(
85-
'Access to deprecated static property $%s of class %s.',
98+
"Access to deprecated static property $%s of class %s:\n%s",
8699
$propertyName,
87-
$referencedClass
100+
$referencedClass,
101+
$description
88102
)];
89103
}
90104
}

Diff for: src/Rules/Deprecations/CallToDeprecatedFunctionRule.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,22 @@ public function processNode(Node $node, Scope $scope): array
4646
}
4747

4848
if ($function->isDeprecated()) {
49+
$description = null;
50+
if (method_exists($function, 'getDeprecatedDescription')) {
51+
$description = $function->getDeprecatedDescription();
52+
}
53+
54+
if ($description === null) {
55+
return [sprintf(
56+
'Call to deprecated function %s().',
57+
$function->getName()
58+
)];
59+
}
60+
4961
return [sprintf(
50-
'Call to deprecated function %s().',
51-
$function->getName()
62+
"Call to deprecated function %s():\n%s",
63+
$function->getName(),
64+
$description
5265
)];
5366
}
5467

Diff for: src/Rules/Deprecations/CallToDeprecatedMethodRule.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,29 @@ public function processNode(Node $node, Scope $scope): array
5454
continue;
5555
}
5656

57-
if ($methodReflection->isDeprecated()) {
57+
if (!$methodReflection->isDeprecated()) {
58+
continue;
59+
}
60+
61+
$description = null;
62+
if (method_exists($methodReflection, 'getDeprecatedDescription')) {
63+
$description = $methodReflection->getDeprecatedDescription();
64+
}
65+
66+
if ($description === null) {
5867
return [sprintf(
5968
'Call to deprecated method %s() of class %s.',
6069
$methodReflection->getName(),
6170
$methodReflection->getDeclaringClass()->getName()
6271
)];
6372
}
73+
74+
return [sprintf(
75+
"Call to deprecated method %s() of class %s:\n%s",
76+
$methodReflection->getName(),
77+
$methodReflection->getDeclaringClass()->getName(),
78+
$description
79+
)];
6480
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
6581
// Other rules will notify if the class is not found
6682
} catch (\PHPStan\Reflection\MissingMethodFromReflectionException $e) {

Diff for: src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php

+38-10
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,50 @@ function (Type $type) use ($methodName): bool {
8383
}
8484

8585
if ($class->isDeprecated()) {
86-
$errors[] = sprintf(
87-
'Call to method %s() of deprecated class %s.',
88-
$methodReflection->getName(),
89-
$methodReflection->getDeclaringClass()->getName()
90-
);
86+
$classDescription = null;
87+
if (method_exists($class, 'getDeprecatedDescription')) {
88+
$classDescription = $class->getDeprecatedDescription();
89+
}
90+
91+
if ($classDescription === null) {
92+
$errors[] = sprintf(
93+
'Call to method %s() of deprecated class %s.',
94+
$methodReflection->getName(),
95+
$methodReflection->getDeclaringClass()->getName()
96+
);
97+
} else {
98+
$errors[] = sprintf(
99+
"Call to method %s() of deprecated class %s:\n%s",
100+
$methodReflection->getName(),
101+
$methodReflection->getDeclaringClass()->getName(),
102+
$classDescription
103+
);
104+
}
91105
}
92106

93107
if (!$methodReflection instanceof DeprecatableReflection || !$methodReflection->isDeprecated()) {
94108
continue;
95109
}
96110

97-
$errors[] = sprintf(
98-
'Call to deprecated method %s() of class %s.',
99-
$methodReflection->getName(),
100-
$methodReflection->getDeclaringClass()->getName()
101-
);
111+
$description = null;
112+
if (method_exists($methodReflection, 'getDeprecatedDescription')) {
113+
$description = $methodReflection->getDeprecatedDescription();
114+
}
115+
116+
if ($description === null) {
117+
$errors[] = sprintf(
118+
'Call to deprecated method %s() of class %s.',
119+
$methodReflection->getName(),
120+
$methodReflection->getDeclaringClass()->getName()
121+
);
122+
} else {
123+
$errors[] = sprintf(
124+
"Call to deprecated method %s() of class %s:\n%s",
125+
$methodReflection->getName(),
126+
$methodReflection->getDeclaringClass()->getName(),
127+
$description
128+
);
129+
}
102130
}
103131

104132
return $errors;

Diff for: src/Rules/Deprecations/FetchingClassConstOfDeprecatedClassRule.php

+38-10
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,25 @@ function (Type $type) use ($constantName): bool {
8080
}
8181

8282
if ($class->isDeprecated()) {
83-
$errors[] = sprintf(
84-
'Fetching class constant %s of deprecated class %s.',
85-
$constantName,
86-
$referencedClass
87-
);
83+
$classDescription = null;
84+
if (method_exists($class, 'getDeprecatedDescription')) {
85+
$classDescription = $class->getDeprecatedDescription();
86+
}
87+
88+
if ($classDescription === null) {
89+
$errors[] = sprintf(
90+
'Fetching class constant %s of deprecated class %s.',
91+
$constantName,
92+
$referencedClass
93+
);
94+
} else {
95+
$errors[] = sprintf(
96+
"Fetching class constant %s of deprecated class %s:\n%s",
97+
$constantName,
98+
$referencedClass,
99+
$classDescription
100+
);
101+
}
88102
}
89103

90104
if (!$class->hasConstant($constantName)) {
@@ -97,11 +111,25 @@ function (Type $type) use ($constantName): bool {
97111
continue;
98112
}
99113

100-
$errors[] = sprintf(
101-
'Fetching deprecated class constant %s of class %s.',
102-
$constantName,
103-
$referencedClass
104-
);
114+
$description = null;
115+
if (method_exists($constantReflection, 'getDeprecatedDescription')) {
116+
$description = $constantReflection->getDeprecatedDescription();
117+
}
118+
119+
if ($description === null) {
120+
$errors[] = sprintf(
121+
'Fetching deprecated class constant %s of class %s.',
122+
$constantName,
123+
$referencedClass
124+
);
125+
} else {
126+
$errors[] = sprintf(
127+
"Fetching deprecated class constant %s of class %s:\n%s",
128+
$constantName,
129+
$referencedClass,
130+
$description
131+
);
132+
}
105133
}
106134

107135
return $errors;

Diff for: src/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRule.php

+30-9
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,38 @@ public function processNode(Node $node, Scope $scope): array
5757
$interface = $this->broker->getClass($interfaceName);
5858

5959
if ($interface->isDeprecated()) {
60+
$description = null;
61+
if (method_exists($interface, 'getDeprecatedDescription')) {
62+
$description = $interface->getDeprecatedDescription();
63+
}
6064
if (!$class->isAnonymous()) {
61-
$errors[] = sprintf(
62-
'Class %s implements deprecated interface %s.',
63-
$className,
64-
$interfaceName
65-
);
65+
if ($description === null) {
66+
$errors[] = sprintf(
67+
'Class %s implements deprecated interface %s.',
68+
$className,
69+
$interfaceName
70+
);
71+
} else {
72+
$errors[] = sprintf(
73+
"Class %s implements deprecated interface %s:\n%s",
74+
$className,
75+
$interfaceName,
76+
$description
77+
);
78+
}
6679
} else {
67-
$errors[] = sprintf(
68-
'Anonymous class implements deprecated interface %s.',
69-
$interfaceName
70-
);
80+
if ($description === null) {
81+
$errors[] = sprintf(
82+
'Anonymous class implements deprecated interface %s.',
83+
$interfaceName
84+
);
85+
} else {
86+
$errors[] = sprintf(
87+
"Anonymous class implements deprecated interface %s:\n%s",
88+
$interfaceName,
89+
$description
90+
);
91+
}
7192
}
7293
}
7394
} catch (\PHPStan\Broker\ClassNotFoundException $e) {

Diff for: src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php

+30-9
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,40 @@ public function processNode(Node $node, Scope $scope): array
5454

5555
try {
5656
$parentClass = $this->broker->getClass($parentClassName);
57+
$description = null;
58+
if (method_exists($parentClass, 'getDeprecatedDescription')) {
59+
$description = $parentClass->getDeprecatedDescription();
60+
}
5761

5862
if ($parentClass->isDeprecated()) {
5963
if (!$class->isAnonymous()) {
60-
$errors[] = sprintf(
61-
'Class %s extends deprecated class %s.',
62-
$className,
63-
$parentClassName
64-
);
64+
if ($description === null) {
65+
$errors[] = sprintf(
66+
'Class %s extends deprecated class %s.',
67+
$className,
68+
$parentClassName
69+
);
70+
} else {
71+
$errors[] = sprintf(
72+
"Class %s extends deprecated class %s:\n%s",
73+
$className,
74+
$parentClassName,
75+
$description
76+
);
77+
}
6578
} else {
66-
$errors[] = sprintf(
67-
'Anonymous class extends deprecated class %s.',
68-
$parentClassName
69-
);
79+
if ($description === null) {
80+
$errors[] = sprintf(
81+
'Anonymous class extends deprecated class %s.',
82+
$parentClassName
83+
);
84+
} else {
85+
$errors[] = sprintf(
86+
"Anonymous class extends deprecated class %s:\n%s",
87+
$parentClassName,
88+
$description
89+
);
90+
}
7091
}
7192
}
7293
} catch (\PHPStan\Broker\ClassNotFoundException $e) {

Diff for: src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,28 @@ public function processNode(Node $node, Scope $scope): array
5656
try {
5757
$parentInterface = $this->broker->getClass($parentInterfaceName);
5858

59-
if ($parentInterface->isDeprecated()) {
59+
if (!$parentInterface->isDeprecated()) {
60+
continue;
61+
}
62+
63+
$description = null;
64+
if (method_exists($parentInterface, 'getDeprecatedDescription')) {
65+
$description = $parentInterface->getDeprecatedDescription();
66+
}
67+
68+
if ($description === null) {
6069
$errors[] = sprintf(
6170
'Interface %s extends deprecated interface %s.',
6271
$interfaceName,
6372
$parentInterfaceName
6473
);
74+
} else {
75+
$errors[] = sprintf(
76+
"Interface %s extends deprecated interface %s:\n%s",
77+
$interfaceName,
78+
$parentInterfaceName,
79+
$description
80+
);
6581
}
6682
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
6783
// Other rules will notify if the interface is not found

Diff for: src/Rules/Deprecations/InstantiationOfDeprecatedClassRule.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,23 @@ function (): bool {
8282
continue;
8383
}
8484

85-
$errors[] = sprintf(
86-
'Instantiation of deprecated class %s.',
87-
$referencedClass
88-
);
85+
$description = null;
86+
if (method_exists($class, 'getDeprecatedDescription')) {
87+
$description = $class->getDeprecatedDescription();
88+
}
89+
90+
if ($description === null) {
91+
$errors[] = sprintf(
92+
'Instantiation of deprecated class %s.',
93+
$referencedClass
94+
);
95+
} else {
96+
$errors[] = sprintf(
97+
"Instantiation of deprecated class %s:\n%s",
98+
$referencedClass,
99+
$description
100+
);
101+
}
89102
}
90103

91104
return $errors;

0 commit comments

Comments
 (0)