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 $connection; |
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; |
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; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$io->title('All fixtures'); |
68
|
|
|
|
69
|
|
|
$io->listing($this->getListing($this->loader->getFixtures())); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function getListing(array $fixtures): array |
73
|
|
|
{ |
74
|
|
|
$content = []; |
75
|
|
|
foreach ($fixtures as $fixture) { |
76
|
|
|
$order = str_pad((string) $fixture->getOrder(), 3, ' ', STR_PAD_LEFT); |
77
|
|
|
$content[] = "<comment>$order</comment> - <info>[{$fixture->getProcessor()}]</info> - {$fixture->getName()}"; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $content; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: