Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
15 / 15 |
| ParamRefactor | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
15 / 15 |
| __construct(Refactored $ctx) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| enterNode(\PHPParser_Node $node) | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| enterParam(\PHPParser_Node_Param $node) | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
|||
| <?php | |
| /* | |
| * Mondrian | |
| */ | |
| namespace Trismegiste\Mondrian\Visitor; | |
| use Trismegiste\Mondrian\Refactor\Refactored; | |
| /** | |
| * ParamRefactor replaces the class of a param by its contract | |
| * | |
| * Changes could be made to the current PhpFile | |
| */ | |
| class ParamRefactor extends FqcnHelper | |
| { | |
| protected $context; | |
| public function __construct(Refactored $ctx) | |
| { | |
| $this->context = $ctx; | |
| } | |
| /** | |
| * {@inheritDoc} | |
| */ | |
| public function enterNode(\PHPParser_Node $node) | |
| { | |
| parent::enterNode($node); | |
| if ($node->getType() === 'Param') { | |
| $this->enterParam($node); | |
| } | |
| } | |
| /** | |
| * Visit a Param Node | |
| * | |
| * @param \PHPParser_Node_Param $node | |
| */ | |
| protected function enterParam(\PHPParser_Node_Param $node) | |
| { | |
| if ($node->type instanceof \PHPParser_Node_Name) { | |
| $typeHint = (string) $this->resolveClassName($node->type); | |
| if ($this->context->hasNewContract($typeHint)) { | |
| $node->type = new \PHPParser_Node_Name_FullyQualified($this->context->getNewContract($typeHint)); | |
| $this->currentPhpFile->modified(); | |
| } | |
| } | |
| } | |
| } |