Skip to content

Commit b88079b

Browse files
committed
Ignore all deprecation errors in deprecated scopes
1 parent 9582775 commit b88079b

22 files changed

+442
-1
lines changed

src/Rules/Deprecations/AccessDeprecatedPropertyRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function getNodeType(): string
3131
*/
3232
public function processNode(Node $node, Scope $scope): array
3333
{
34+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
35+
return [];
36+
}
37+
3438
if (!is_string($node->name)) {
3539
return [];
3640
}

src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function getNodeType(): string
3737
*/
3838
public function processNode(Node $node, Scope $scope): array
3939
{
40+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
41+
return [];
42+
}
43+
4044
if (!is_string($node->name)) {
4145
return [];
4246
}

src/Rules/Deprecations/CallToDeprecatedFunctionRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function getNodeType(): string
3030
*/
3131
public function processNode(Node $node, Scope $scope): array
3232
{
33+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
34+
return [];
35+
}
36+
3337
if (!($node->name instanceof \PhpParser\Node\Name)) {
3438
return [];
3539
}

src/Rules/Deprecations/CallToDeprecatedMethodRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function getNodeType(): string
3131
*/
3232
public function processNode(Node $node, Scope $scope): array
3333
{
34+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
35+
return [];
36+
}
37+
3438
if (!is_string($node->name)) {
3539
return [];
3640
}

src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function getNodeType(): string
3333
*/
3434
public function processNode(Node $node, Scope $scope): array
3535
{
36+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
37+
return [];
38+
}
39+
3640
if (!is_string($node->name)) {
3741
return [];
3842
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Deprecations;
4+
5+
use PHPStan\Analyser\Scope;
6+
use PHPStan\Reflection\DeprecatableReflection;
7+
8+
class DeprecatedScopeHelper
9+
{
10+
11+
public static function isScopeDeprecated(Scope $scope): bool
12+
{
13+
$class = $scope->getClassReflection();
14+
if ($class !== null && $class->isDeprecated()) {
15+
return true;
16+
}
17+
18+
$function = $scope->getFunction();
19+
if ($function instanceof DeprecatableReflection && $function->isDeprecated()) {
20+
return true;
21+
}
22+
23+
return false;
24+
}
25+
26+
}

src/Rules/Deprecations/FetchingClassConstOfDeprecatedClassRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function getNodeType(): string
3131
*/
3232
public function processNode(Node $node, Scope $scope): array
3333
{
34+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
35+
return [];
36+
}
37+
3438
if (!$node->class instanceof Name) {
3539
return [];
3640
}

src/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function processNode(Node $node, Scope $scope): array
4242
return [];
4343
}
4444

45+
if ($class->isDeprecated()) {
46+
return [];
47+
}
48+
4549
foreach ($node->implements as $implement) {
4650
$interfaceName = (string) $implement;
4751

src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function getNodeType(): string
3030
*/
3131
public function processNode(Node $node, Scope $scope): array
3232
{
33+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
34+
return [];
35+
}
36+
3337
if ($node->extends === null) {
3438
return [];
3539
}

src/Rules/Deprecations/InstantiationOfDeprecatedClassRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function getNodeType(): string
3131
*/
3232
public function processNode(Node $node, Scope $scope): array
3333
{
34+
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
35+
return [];
36+
}
37+
3438
if (!$node->class instanceof Name) {
3539
return [];
3640
}

0 commit comments

Comments
 (0)