Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move collectors to src/Collector namespace for easy discovery, add Mo…
…ckedClassCollector (#5055)
- Loading branch information
1 parent
0c0e5ee
commit 640a49b
Showing
7 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Collector; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use PhpParser\Node\Identifier; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Collectors\Collector; | ||
use PHPStan\Type\Constant\ConstantStringType; | ||
|
||
/** | ||
* @implements Collector<MethodCall, string[]|null> | ||
*/ | ||
final class MockedClassCollector implements Collector | ||
{ | ||
public function getNodeType(): string | ||
{ | ||
return MethodCall::class; | ||
} | ||
|
||
/** | ||
* @param MethodCall $node | ||
* @return string[]|null | ||
*/ | ||
public function processNode(Node $node, Scope $scope): ?array | ||
{ | ||
if (! $node->name instanceof Identifier) { | ||
return null; | ||
} | ||
|
||
$methodName = $node->name->toString(); | ||
if (! in_array($methodName, ['createMock', 'buildMock'], true)) { | ||
return null; | ||
} | ||
|
||
$firstArg = $node->getArgs()[0] ?? null; | ||
if (! $firstArg instanceof Arg) { | ||
return null; | ||
} | ||
|
||
$mockedClassType = $scope->getType($firstArg->value); | ||
|
||
if (! $mockedClassType instanceof ConstantStringType) { | ||
return null; | ||
} | ||
|
||
return [$mockedClassType->getValue()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters