Docs   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 14 1
A execute() 0 24 4
1
<?php
2
3
namespace Popstas\Transmission\Console\Command;
4
5
use Symfony\Component\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\BufferedOutput;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class Docs extends Command
11
{
12
    protected function configure()
13
    {
14
        parent::configure();
15
        $this
16
            ->setName('_docs')
17
            ->setDescription('Generate docs for README.md')
18
            ->setHelp(<<<EOT
19
Developer command for generate docs in markdown. Typically usage:
20
```
21
bin/transmission-cli _docs > docs/commands.md
22
```
23
EOT
24
            );
25
    }
26
27
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29
        $excludedCommands = ['_completion', '_docs', 'help', 'list'];
30
31
        /**
32
         * @var Command $command
33
         */
34
        $command = $this->getApplication()->find('list');
35
        $commandInput = new ArrayInput(['command' => 'list', '--raw' => true]);
36
        $commandOutput = new BufferedOutput();
37
        $command->run($commandInput, $commandOutput);
38
        $commandLines = explode("\n", $commandOutput->fetch());
39
40
        foreach ($commandLines as $commandLine) {
41
            $commandName = explode(' ', $commandLine)[0];
42
            if (empty($commandName) || in_array($commandName, $excludedCommands)) {
43
                continue;
44
            }
45
            $command = $this->getApplication()->find($commandName);
46
            $help = $command->getRawHelp();
47
48
            $output->writeln($help . "\n\n");
49
        }
50
    }
51
}
52