Skip to content

Commit 223f1ab

Browse files
committed
Replace TypeHintDeprecated*Rule with RestrictedDeprecatedClassNameUsageExtension
1 parent 13d3746 commit 223f1ab

11 files changed

+80
-332
lines changed

phpstan-baseline.neon

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ parameters:
3030
count: 1
3131
path: tests/Rules/Deprecations/RestrictedDeprecatedClassNameUsageExtensionTest.php
3232

33+
-
34+
message: '#^Accessing PHPStan\\Rules\\Methods\\ExistingClassesInTypehintsRule\:\:class is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
35+
identifier: phpstanApi.classConstant
36+
count: 1
37+
path: tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php
38+
39+
-
40+
message: '#^Accessing PHPStan\\Rules\\Functions\\ExistingClassesInClosureTypehintsRule\:\:class is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
41+
identifier: phpstanApi.classConstant
42+
count: 1
43+
path: tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php
44+
45+
-
46+
message: '#^Accessing PHPStan\\Rules\\Functions\\ExistingClassesInTypehintsRule\:\:class is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
47+
identifier: phpstanApi.classConstant
48+
count: 1
49+
path: tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php
50+
3351
-
3452
message: '#^Accessing PHPStan\\Rules\\Classes\\ExistingClassInTraitUseRule\:\:class is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
3553
identifier: phpstanApi.classConstant

rules.neon

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ parameters:
22
deprecationRulesInstalled: true
33

44
services:
5-
-
6-
class: PHPStan\Rules\Deprecations\DeprecatedClassHelper
7-
85
-
96
class: PHPStan\DependencyInjection\LazyDeprecatedScopeResolverProvider
107
-
@@ -37,9 +34,6 @@ rules:
3734
- PHPStan\Rules\Deprecations\CallToDeprecatedFunctionRule
3835
- PHPStan\Rules\Deprecations\FetchingClassConstOfDeprecatedClassRule
3936
- PHPStan\Rules\Deprecations\FetchingDeprecatedConstRule
40-
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInClassMethodSignatureRule
41-
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInClosureSignatureRule
42-
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInFunctionSignatureRule
4337
- PHPStan\Rules\Deprecations\UsageOfDeprecatedCastRule
4438

4539
conditionalTags:

src/Rules/Deprecations/DeprecatedClassHelper.php

-54
This file was deleted.

src/Rules/Deprecations/RestrictedDeprecatedClassNameUsageExtension.php

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Rules\ClassNameUsageLocation;
99
use PHPStan\Rules\RestrictedUsage\RestrictedClassNameUsageExtension;
1010
use PHPStan\Rules\RestrictedUsage\RestrictedUsage;
11+
use function rtrim;
1112
use function sprintf;
1213
use function strtolower;
1314

@@ -226,6 +227,19 @@ public function isRestrictedClassNameUsage(
226227
return $defaultUsage;
227228
}
228229

230+
if ($location->value === ClassNameUsageLocation::PARAMETER_TYPE || $location->value === ClassNameUsageLocation::RETURN_TYPE) {
231+
$message = $location->createMessage(
232+
sprintf('deprecated %s %s', strtolower($classReflection->getClassTypeDescription()), $classReflection->getDisplayName()),
233+
);
234+
if ($classReflection->getDeprecatedDescription() !== null) {
235+
$message = rtrim($message, '.') . ":\n" . $classReflection->getDeprecatedDescription();
236+
}
237+
return RestrictedUsage::create(
238+
$message,
239+
$location->createIdentifier($identifierPart),
240+
);
241+
}
242+
229243
if (!$this->bleedingEdge) {
230244
return null;
231245
}

src/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRule.php

-94
This file was deleted.

src/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRule.php

-73
This file was deleted.

src/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRule.php

-75
This file was deleted.

0 commit comments

Comments
 (0)