Skip to content

Commit

Permalink
Separate reflection provided deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
cs278 authored and ondrejmirtes committed Jan 12, 2020
1 parent 4d18903 commit a122cf1
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Rules/Deprecations/FetchingDeprecatedConstRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\GlobalConstantReflection;
use PHPStan\Reflection\ReflectionProvider;

/**
Expand Down Expand Up @@ -44,21 +43,23 @@ public function processNode(Node $node, Scope $scope): array
}

$constantReflection = $this->reflectionProvider->getConstant($node->name, $scope);
$defaultMessage = 'Use of constant %s is deprecated.';

if ($this->isDeprecated($constantReflection)) {
if ($constantReflection->isDeprecated()->yes()) {
return [sprintf(
$this->deprecatedConstants[$constantReflection->getName()] ?? 'Use of constant %s is deprecated.',
$constantReflection->getDeprecatedDescription() ?? $defaultMessage,
$constantReflection->getName()
)];
}

return [];
}
if (isset($this->deprecatedConstants[$constantReflection->getName()])) {
return [sprintf(
$this->deprecatedConstants[$constantReflection->getName()] ?? $defaultMessage,
$constantReflection->getName()
)];
}

private function isDeprecated(GlobalConstantReflection $constantReflection): bool
{
return $constantReflection->isDeprecated()->yes()
|| isset($this->deprecatedConstants[$constantReflection->getName()]);
return [];
}

}

0 comments on commit a122cf1

Please sign in to comment.