Skip to content

Commit 063a7fd

Browse files
herndlmondrejmirtes
authored andcommitted
Fix deprecations
1 parent c753126 commit 063a7fd

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"require-dev": {
1313
"nikic/php-parser": "^4.13.0",
1414
"php-parallel-lint/php-parallel-lint": "^1.2",
15+
"phpstan/phpstan-deprecation-rules": "^1.1",
1516
"phpstan/phpstan-phpunit": "^1.0",
1617
"phpunit/phpunit": "^9.5"
1718
},

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
includes:
2+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
23
- vendor/phpstan/phpstan-phpunit/extension.neon
34
- vendor/phpstan/phpstan-phpunit/rules.neon
45
- rules.neon

src/Rules/Cast/UselessCastRule.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Rules\RuleErrorBuilder;
1111
use PHPStan\Type\ErrorType;
1212
use PHPStan\Type\GeneralizePrecision;
13-
use PHPStan\Type\TypeUtils;
1413
use PHPStan\Type\VerbosityLevel;
1514
use function sprintf;
1615

@@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
4039
if ($castType instanceof ErrorType) {
4140
return [];
4241
}
43-
$castType = TypeUtils::generalizeType($castType, GeneralizePrecision::lessSpecific());
42+
$castType = $castType->generalize(GeneralizePrecision::lessSpecific());
4443

4544
if ($this->treatPhpDocTypesAsCertain) {
4645
$expressionType = $scope->getType($node->expr);

src/Rules/StrictCalls/StrictFunctionCallsRule.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PhpParser\Node\Expr\FuncCall;
77
use PhpParser\Node\Name;
88
use PHPStan\Analyser\Scope;
9-
use PHPStan\Broker\Broker;
9+
use PHPStan\Reflection\ReflectionProvider;
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Type\Constant\ConstantBooleanType;
1212
use function array_key_exists;
@@ -24,12 +24,12 @@ class StrictFunctionCallsRule implements Rule
2424
'array_keys' => 2,
2525
];
2626

27-
/** @var Broker */
28-
private $broker;
27+
/** @var ReflectionProvider */
28+
private $reflectionProvider;
2929

30-
public function __construct(Broker $broker)
30+
public function __construct(ReflectionProvider $reflectionProvider)
3131
{
32-
$this->broker = $broker;
32+
$this->reflectionProvider = $reflectionProvider;
3333
}
3434

3535
public function getNodeType(): string
@@ -47,7 +47,7 @@ public function processNode(Node $node, Scope $scope): array
4747
return [];
4848
}
4949

50-
$functionName = $this->broker->resolveFunctionName($node->name, $scope);
50+
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
5151
if ($functionName === null) {
5252
return [];
5353
}

src/Rules/VariableVariables/VariablePropertyFetchRule.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,27 @@
55
use PhpParser\Node;
66
use PhpParser\Node\Expr\PropertyFetch;
77
use PHPStan\Analyser\Scope;
8-
use PHPStan\Broker\Broker;
98
use PHPStan\Reflection\ClassReflection;
9+
use PHPStan\Reflection\ReflectionProvider;
1010
use PHPStan\Rules\Rule;
11-
use PHPStan\Type\TypeUtils;
1211
use PHPStan\Type\VerbosityLevel;
1312
use function sprintf;
1413

1514
class VariablePropertyFetchRule implements Rule
1615
{
1716

18-
/** @var Broker */
19-
private $broker;
17+
/** @var ReflectionProvider */
18+
private $reflectionProvider;
2019

2120
/** @var string[] */
2221
private $universalObjectCratesClasses;
2322

2423
/**
2524
* @param string[] $universalObjectCratesClasses
2625
*/
27-
public function __construct(Broker $broker, array $universalObjectCratesClasses)
26+
public function __construct(ReflectionProvider $reflectionProvider, array $universalObjectCratesClasses)
2827
{
29-
$this->broker = $broker;
28+
$this->reflectionProvider = $reflectionProvider;
3029
$this->universalObjectCratesClasses = $universalObjectCratesClasses;
3130
}
3231

@@ -46,12 +45,12 @@ public function processNode(Node $node, Scope $scope): array
4645
}
4746

4847
$fetchedOnType = $scope->getType($node->var);
49-
foreach (TypeUtils::getDirectClassNames($fetchedOnType) as $referencedClass) {
50-
if (!$this->broker->hasClass($referencedClass)) {
48+
foreach ($fetchedOnType->getObjectClassNames() as $referencedClass) {
49+
if (!$this->reflectionProvider->hasClass($referencedClass)) {
5150
continue;
5251
}
5352

54-
if ($this->isUniversalObjectCrate($this->broker->getClass($referencedClass))) {
53+
if ($this->isUniversalObjectCrate($this->reflectionProvider->getClass($referencedClass))) {
5554
return [];
5655
}
5756
}
@@ -69,7 +68,7 @@ private function isUniversalObjectCrate(
6968
): bool
7069
{
7170
foreach ($this->universalObjectCratesClasses as $className) {
72-
if (!$this->broker->hasClass($className)) {
71+
if (!$this->reflectionProvider->hasClass($className)) {
7372
continue;
7473
}
7574

tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class StrictFunctionCallsRuleTest extends RuleTestCase
1010

1111
protected function getRule(): Rule
1212
{
13-
return new StrictFunctionCallsRule($this->createBroker());
13+
return new StrictFunctionCallsRule($this->createReflectionProvider());
1414
}
1515

1616
public function testRule(): void

tests/Rules/VariableVariables/VariablePropertyFetchRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class VariablePropertyFetchRuleTest extends RuleTestCase
1010

1111
protected function getRule(): Rule
1212
{
13-
return new VariablePropertyFetchRule($this->createBroker(), [
13+
return new VariablePropertyFetchRule($this->createReflectionProvider(), [
1414
'stdClass',
1515
'SimpleXMLElement',
1616
]);

0 commit comments

Comments
 (0)