mauretto78 /
simple-dic
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace SimpleDIC\Console; |
||||
| 4 | |||||
| 5 | use SimpleDIC\DIC; |
||||
| 6 | use Symfony\Component\Console\Command\Command; |
||||
| 7 | use Symfony\Component\Console\Helper\Table; |
||||
| 8 | use Symfony\Component\Console\Input\InputArgument; |
||||
| 9 | use Symfony\Component\Console\Input\InputInterface; |
||||
| 10 | use Symfony\Component\Console\Output\OutputInterface; |
||||
| 11 | |||||
| 12 | class DebugCommand extends Command |
||||
| 13 | { |
||||
| 14 | protected function configure() |
||||
| 15 | { |
||||
| 16 | $this |
||||
| 17 | ->setName('dic:debug') |
||||
| 18 | ->setDescription('Dumps the entry list in the DIC.') |
||||
| 19 | ->setHelp('This command shows you to complete entry list in the DIC from a valid config array.') |
||||
| 20 | ->addArgument('config_file', InputArgument::REQUIRED) |
||||
| 21 | ; |
||||
| 22 | } |
||||
| 23 | |||||
| 24 | protected function execute(InputInterface $input, OutputInterface $output) |
||||
| 25 | { |
||||
| 26 | $configFile = $input->getArgument('config_file'); |
||||
| 27 | |||||
| 28 | if (false === file_exists($configFile)) { |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 29 | throw new \InvalidArgumentException($configFile . ' is not a valid file'); |
||||
|
0 ignored issues
–
show
Are you sure
$configFile of type null|string|string[] can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 30 | } |
||||
| 31 | |||||
| 32 | DIC::initFromFile($configFile); |
||||
|
0 ignored issues
–
show
It seems like
$configFile can also be of type string[]; however, parameter $filename of SimpleDIC\DIC::initFromFile() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 33 | |||||
| 34 | $keys = DIC::keys(); |
||||
| 35 | asort($keys); |
||||
| 36 | |||||
| 37 | $table = new Table($output); |
||||
| 38 | $table->setHeaders(['#', 'Alias', 'Content']); |
||||
| 39 | |||||
| 40 | $i = 1; |
||||
| 41 | foreach ($keys as $key) { |
||||
| 42 | $table->setRow($i, [$i, $key, $this->getValue($key)]); |
||||
| 43 | $i++; |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | $table->render(); |
||||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * @param string $key |
||||
| 51 | * |
||||
| 52 | * @return mixed|string |
||||
| 53 | */ |
||||
| 54 | private function getValue($key) |
||||
| 55 | { |
||||
| 56 | $dicKey = DIC::get($key); |
||||
| 57 | |||||
| 58 | if (false === $dicKey) { |
||||
| 59 | return '<fg=red>Invalid Entry</>'; |
||||
| 60 | } |
||||
| 61 | |||||
| 62 | if (is_object($dicKey)) { |
||||
| 63 | return '<fg=cyan>' . get_class($dicKey) . '</>'; |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | if (is_array($dicKey)) { |
||||
| 67 | return '<fg=green>' . implode("|", $dicKey) . '</>'; |
||||
| 68 | } |
||||
| 69 | |||||
| 70 | return '<fg=yellow>' . $dicKey . '</>'; |
||||
| 71 | } |
||||
| 72 | } |
||||
| 73 |