Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Jan 17, 2023
1 parent c753126 commit 063a7fd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"require-dev": {
"nikic/php-parser": "^4.13.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
},
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- rules.neon
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/Cast/UselessCastRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ErrorType;
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\VerbosityLevel;
use function sprintf;

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

if ($this->treatPhpDocTypesAsCertain) {
$expressionType = $scope->getType($node->expr);
Expand Down
12 changes: 6 additions & 6 deletions src/Rules/StrictCalls/StrictFunctionCallsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Type\Constant\ConstantBooleanType;
use function array_key_exists;
Expand All @@ -24,12 +24,12 @@ class StrictFunctionCallsRule implements Rule
'array_keys' => 2,
];

/** @var Broker */
private $broker;
/** @var ReflectionProvider */
private $reflectionProvider;

public function __construct(Broker $broker)
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->broker = $broker;
$this->reflectionProvider = $reflectionProvider;
}

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

$functionName = $this->broker->resolveFunctionName($node->name, $scope);
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
if ($functionName === null) {
return [];
}
Expand Down
19 changes: 9 additions & 10 deletions src/Rules/VariableVariables/VariablePropertyFetchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@
use PhpParser\Node;
use PhpParser\Node\Expr\PropertyFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\VerbosityLevel;
use function sprintf;

class VariablePropertyFetchRule implements Rule
{

/** @var Broker */
private $broker;
/** @var ReflectionProvider */
private $reflectionProvider;

/** @var string[] */
private $universalObjectCratesClasses;

/**
* @param string[] $universalObjectCratesClasses
*/
public function __construct(Broker $broker, array $universalObjectCratesClasses)
public function __construct(ReflectionProvider $reflectionProvider, array $universalObjectCratesClasses)
{
$this->broker = $broker;
$this->reflectionProvider = $reflectionProvider;
$this->universalObjectCratesClasses = $universalObjectCratesClasses;
}

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

$fetchedOnType = $scope->getType($node->var);
foreach (TypeUtils::getDirectClassNames($fetchedOnType) as $referencedClass) {
if (!$this->broker->hasClass($referencedClass)) {
foreach ($fetchedOnType->getObjectClassNames() as $referencedClass) {
if (!$this->reflectionProvider->hasClass($referencedClass)) {
continue;
}

if ($this->isUniversalObjectCrate($this->broker->getClass($referencedClass))) {
if ($this->isUniversalObjectCrate($this->reflectionProvider->getClass($referencedClass))) {
return [];
}
}
Expand All @@ -69,7 +68,7 @@ private function isUniversalObjectCrate(
): bool
{
foreach ($this->universalObjectCratesClasses as $className) {
if (!$this->broker->hasClass($className)) {
if (!$this->reflectionProvider->hasClass($className)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StrictFunctionCallsRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new StrictFunctionCallsRule($this->createBroker());
return new StrictFunctionCallsRule($this->createReflectionProvider());
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class VariablePropertyFetchRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new VariablePropertyFetchRule($this->createBroker(), [
return new VariablePropertyFetchRule($this->createReflectionProvider(), [
'stdClass',
'SimpleXMLElement',
]);
Expand Down

0 comments on commit 063a7fd

Please sign in to comment.