Skip to content

Commit

Permalink
[DX] Show warning on AbstractRector::__get() when pull deprecated pro…
Browse files Browse the repository at this point in the history
…perty from AbstractRector (#5069)
  • Loading branch information
samsonasik committed Sep 23, 2023
1 parent 9abbcb1 commit 9b319ef
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,23 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter
*/
private array $deprecatedDependencies = [];

/**
* @var array<class-string, array<string, bool>>
*/
private array $cachedDeprecatedDependenciesWarning = [];

/**
* Handle deprecated dependencies compatbility
*/
public function __get(string $name): mixed
{
if (! isset($this->cachedDeprecatedDependenciesWarning[static::class][$name])) {
echo sprintf('Get %s property from AbstractRector on %s is deprecated, inject via __construct() instead', $name, static::class);
echo PHP_EOL;

$this->cachedDeprecatedDependenciesWarning[static::class][$name] = true;
}

return $this->deprecatedDependencies[$name] ?? null;
}

Expand Down

0 comments on commit 9b319ef

Please sign in to comment.