1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Shapin\Datagen\Bridge\Symfony\Bundle\Command; |
6
|
|
|
|
7
|
|
|
use Shapin\Datagen\Loader; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
13
|
|
|
|
14
|
|
|
class DebugCommand extends Command |
15
|
|
|
{ |
16
|
|
|
private $loader; |
17
|
|
|
|
18
|
2 |
|
public function __construct(Loader $loader) |
19
|
|
|
{ |
20
|
2 |
|
$this->loader = $loader; |
21
|
|
|
|
22
|
2 |
|
parent::__construct(); |
23
|
2 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
2 |
|
protected function configure() |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
2 |
|
->setName('shapin:datagen:debug') |
32
|
2 |
|
->setDescription('Display information about fixtures.') |
33
|
2 |
|
->addOption('group', 'g', InputOption::VALUE_REQUIRED, 'List only fixtures from the given group.') |
34
|
2 |
|
->addOption('grouped', null, InputOption::VALUE_NONE, 'Display fixtures by groups.') |
35
|
|
|
; |
36
|
2 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
42
|
|
|
{ |
43
|
|
|
$io = new SymfonyStyle($input, $output); |
44
|
|
|
|
45
|
|
View Code Duplication |
if (null !== $group = $input->getOption('group')) { |
|
|
|
|
46
|
|
|
$fixtures = $this->loader->getFixtures([$group]); |
47
|
|
|
|
48
|
|
|
$io->title("Fixtures in group \"$group\"."); |
49
|
|
|
$io->listing($this->getListing($fixtures)); |
50
|
|
|
|
51
|
|
|
return 0; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
if (false !== $input->getOption('grouped')) { |
|
|
|
|
55
|
|
|
$io->title('Repartition of fixtures by groups.'); |
56
|
|
|
|
57
|
|
|
$fixturesByGroup = $this->loader->getFixturesByGroups(); |
58
|
|
|
|
59
|
|
|
foreach ($fixturesByGroup as $group => $fixtures) { |
60
|
|
|
$io->section($group); |
61
|
|
|
$io->listing($this->getListing($fixtures)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return 0; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$io->title('All fixtures'); |
68
|
|
|
|
69
|
|
|
$io->listing($this->getListing($this->loader->getFixtures())); |
70
|
|
|
|
71
|
|
|
return 0; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function getListing(array $fixtures): array |
75
|
|
|
{ |
76
|
|
|
$content = []; |
77
|
|
|
foreach ($fixtures as $fixture) { |
78
|
|
|
$order = str_pad((string) $fixture->getOrder(), 3, ' ', STR_PAD_LEFT); |
79
|
|
|
$content[] = "<comment>$order</comment> - <info>[{$fixture->getProcessor()}]</info> - {$fixture->getName()}"; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $content; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.