mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
96112cb1f0
2da49992cc
[Downgrade] [PHP 7.2] Make DowngradeParameterTypeWideningRector always downgrade to phpdoc type (#390)
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\PhpSpecToPHPUnit\Rector\Variable;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Expr\PropertyFetch;
|
|
use PhpParser\Node\Expr\Variable;
|
|
use Rector\PhpSpecToPHPUnit\PhpSpecMockCollector;
|
|
use Rector\PhpSpecToPHPUnit\Rector\AbstractPhpSpecToPHPUnitRector;
|
|
/**
|
|
* $mock->call()
|
|
* ↓
|
|
* $this->mock->call()
|
|
*
|
|
* @see \Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\PhpSpecToPHPUnitRectorTest
|
|
*/
|
|
final class MockVariableToPropertyFetchRector extends \Rector\PhpSpecToPHPUnit\Rector\AbstractPhpSpecToPHPUnitRector
|
|
{
|
|
/**
|
|
* @var \Rector\PhpSpecToPHPUnit\PhpSpecMockCollector
|
|
*/
|
|
private $phpSpecMockCollector;
|
|
public function __construct(\Rector\PhpSpecToPHPUnit\PhpSpecMockCollector $phpSpecMockCollector)
|
|
{
|
|
$this->phpSpecMockCollector = $phpSpecMockCollector;
|
|
}
|
|
/**
|
|
* @return array<class-string<Node>>
|
|
*/
|
|
public function getNodeTypes() : array
|
|
{
|
|
return [\PhpParser\Node\Expr\Variable::class];
|
|
}
|
|
/**
|
|
* @param Variable $node
|
|
*/
|
|
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
|
{
|
|
if (!$this->isInPhpSpecBehavior($node)) {
|
|
return null;
|
|
}
|
|
if (!$this->phpSpecMockCollector->isVariableMockInProperty($node)) {
|
|
return null;
|
|
}
|
|
/** @var string $variableName */
|
|
$variableName = $this->getName($node);
|
|
return new \PhpParser\Node\Expr\PropertyFetch(new \PhpParser\Node\Expr\Variable('this'), $variableName);
|
|
}
|
|
}
|