Skip to content

Commit

Permalink
Improve compatibility with PHPStan 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 23, 2021
1 parent a6a1ed5 commit e5ccafb
Show file tree
Hide file tree
Showing 27 changed files with 90 additions and 111 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
excludes_analyse:
excludePaths:
- tests/*/data/*
12 changes: 6 additions & 6 deletions src/Rules/Deprecations/AccessDeprecatedPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Identifier;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\TypeUtils;

/**
Expand All @@ -15,12 +15,12 @@
class AccessDeprecatedPropertyRule implements \PHPStan\Rules\Rule
{

/** @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 @@ -44,7 +44,7 @@ public function processNode(Node $node, Scope $scope): array

foreach ($referencedClasses as $referencedClass) {
try {
$classReflection = $this->broker->getClass($referencedClass);
$classReflection = $this->reflectionProvider->getClass($referencedClass);
$propertyReflection = $classReflection->getProperty($propertyName, $scope);

if ($propertyReflection->isDeprecated()->yes()) {
Expand Down
12 changes: 6 additions & 6 deletions src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
Expand All @@ -18,15 +18,15 @@
class AccessDeprecatedStaticPropertyRule implements \PHPStan\Rules\Rule
{

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

/** @var RuleLevelHelper */
private $ruleLevelHelper;

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

Expand Down Expand Up @@ -69,7 +69,7 @@ function (Type $type) use ($propertyName): bool {

foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->broker->getClass($referencedClass);
$class = $this->reflectionProvider->getClass($referencedClass);
$property = $class->getProperty($propertyName, $scope);
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
continue;
Expand Down
12 changes: 6 additions & 6 deletions src/Rules/Deprecations/CallToDeprecatedFunctionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;

/**
* @implements \PHPStan\Rules\Rule<FuncCall>
*/
class CallToDeprecatedFunctionRule implements \PHPStan\Rules\Rule
{

/** @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 @@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
}

try {
$function = $this->broker->getFunction($node->name, $scope);
$function = $this->reflectionProvider->getFunction($node->name, $scope);
} catch (\PHPStan\Broker\FunctionNotFoundException $e) {
// Other rules will notify if the function is not found
return [];
Expand Down
12 changes: 6 additions & 6 deletions src/Rules/Deprecations/CallToDeprecatedMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\TypeUtils;

/**
Expand All @@ -15,12 +15,12 @@
class CallToDeprecatedMethodRule implements \PHPStan\Rules\Rule
{

/** @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 @@ -44,7 +44,7 @@ public function processNode(Node $node, Scope $scope): array

foreach ($referencedClasses as $referencedClass) {
try {
$classReflection = $this->broker->getClass($referencedClass);
$classReflection = $this->reflectionProvider->getClass($referencedClass);
$methodReflection = $classReflection->getMethod($methodName, $scope);

if (!$methodReflection->isDeprecated()->yes()) {
Expand Down
12 changes: 6 additions & 6 deletions src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
Expand All @@ -18,15 +18,15 @@
class CallToDeprecatedStaticMethodRule implements \PHPStan\Rules\Rule
{

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

/** @var RuleLevelHelper */
private $ruleLevelHelper;

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

Expand Down Expand Up @@ -71,7 +71,7 @@ function (Type $type) use ($methodName): bool {

foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->broker->getClass($referencedClass);
$class = $this->reflectionProvider->getClass($referencedClass);
$methodReflection = $class->getMethod($methodName, $scope);
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
continue;
Expand Down
12 changes: 6 additions & 6 deletions src/Rules/Deprecations/DeprecatedClassHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace PHPStan\Rules\Deprecations;

use PHPStan\Broker\Broker;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;

class DeprecatedClassHelper
{

/** @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 getClassType(ClassReflection $class): string
Expand Down Expand Up @@ -44,7 +44,7 @@ public function filterDeprecatedClasses(array $referencedClasses): array
$deprecatedClasses = [];
foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->broker->getClass($referencedClass);
$class = $this->reflectionProvider->getClass($referencedClass);
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
Expand All @@ -18,15 +18,15 @@
class FetchingClassConstOfDeprecatedClassRule implements \PHPStan\Rules\Rule
{

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

/** @var RuleLevelHelper */
private $ruleLevelHelper;

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

Expand Down Expand Up @@ -71,7 +71,7 @@ function (Type $type) use ($constantName): bool {

foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->broker->getClass($referencedClass);
$class = $this->reflectionProvider->getClass($referencedClass);
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;

/**
* @implements \PHPStan\Rules\Rule<Class_>
*/
class ImplementationOfDeprecatedInterfaceRule implements \PHPStan\Rules\Rule
{

/** @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 @@ -39,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
: (string) $node->name;

try {
$class = $this->broker->getClass($className);
$class = $this->reflectionProvider->getClass($className);
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
return [];
}
Expand All @@ -52,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
$interfaceName = (string) $implement;

try {
$interface = $this->broker->getClass($interfaceName);
$interface = $this->reflectionProvider->getClass($interfaceName);

if ($interface->isDeprecated()) {
$description = $interface->getDeprecatedDescription();
Expand Down
14 changes: 7 additions & 7 deletions src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;

/**
* @implements \PHPStan\Rules\Rule<Class_>
*/
class InheritanceOfDeprecatedClassRule implements \PHPStan\Rules\Rule
{

/** @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 @@ -43,15 +43,15 @@ public function processNode(Node $node, Scope $scope): array
: (string) $node->name;

try {
$class = $this->broker->getClass($className);
$class = $this->reflectionProvider->getClass($className);
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
return [];
}

$parentClassName = (string) $node->extends;

try {
$parentClass = $this->broker->getClass($parentClassName);
$parentClass = $this->reflectionProvider->getClass($parentClassName);
$description = $parentClass->getDeprecatedDescription();
if ($parentClass->isDeprecated()) {
if (!$class->isAnonymous()) {
Expand Down
14 changes: 7 additions & 7 deletions src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Interface_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;

/**
* @implements \PHPStan\Rules\Rule<Interface_>
*/
class InheritanceOfDeprecatedInterfaceRule implements \PHPStan\Rules\Rule
{

/** @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 @@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
: (string) $node->name;

try {
$interface = $this->broker->getClass($interfaceName);
$interface = $this->reflectionProvider->getClass($interfaceName);
} catch (\PHPStan\Broker\ClassNotFoundException $e) {
return [];
}
Expand All @@ -52,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
$parentInterfaceName = (string) $parentInterfaceName;

try {
$parentInterface = $this->broker->getClass($parentInterfaceName);
$parentInterface = $this->reflectionProvider->getClass($parentInterfaceName);

if (!$parentInterface->isDeprecated()) {
continue;
Expand Down
Loading

0 comments on commit e5ccafb

Please sign in to comment.