Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
66.67% |
2 / 3 |
CRAP | |
94.12% |
16 / 17 |
FactoryGenerator | |
0.00% |
0 / 1 |
|
66.67% |
2 / 3 |
4.00 | |
94.12% |
16 / 17 |
configure() | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
initialize(InputInterface $input, OutputInterface $output) | |
0.00% |
0 / 1 |
2.01 | |
87.50% |
7 / 8 |
|||
execute(InputInterface $input, OutputInterface $output) | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
<?php | |
/* | |
* Mondrian | |
*/ | |
namespace Trismegiste\Mondrian\Command; | |
use Symfony\Component\Console\Command\Command; | |
use Trismegiste\Mondrian\Refactor\FactoryGenBuilder; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputOption; | |
use Trismegiste\Mondrian\Builder\Linking; | |
use Trismegiste\Mondrian\Builder\Statement\Builder; | |
use Trismegiste\Mondrian\Parser\PhpDumper; | |
use Trismegiste\Mondrian\Parser\NullDumper; | |
/** | |
* FactoryGenerator is a refactoring tools which scans all new statements | |
* and create a protected method for each. | |
* | |
* With this, it is possible to mockup the new instance for unit testing | |
*/ | |
class FactoryGenerator extends Command | |
{ | |
protected $dumper; | |
protected $source; | |
protected function configure() | |
{ | |
$this->setName('refactor:factory') | |
->addArgument('file', InputArgument::REQUIRED, 'The source file to refactor') | |
->setDescription('Scans a file and replace new instances in methods by protected factories') | |
->addOption('dry', null, InputOption::VALUE_NONE, 'Dry run (no write)'); | |
} | |
protected function initialize(InputInterface $input, OutputInterface $output) | |
{ | |
$this->source = new \ArrayIterator( | |
array(new \Symfony\Component\Finder\SplFileInfo( | |
$input->getArgument('file'), '', ''))); | |
if ($input->getOption('dry')) { | |
$this->dumper = new NullDumper(); | |
} else { | |
$this->dumper = new PhpDumper(); | |
} | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$compil = new Linking( | |
new Builder(), new FactoryGenBuilder($this->dumper)); | |
$compil->run($this->source); | |
} | |
} |