Passed
Push — master ( 005105...a5b1eb )
by Julius
01:50
created

GenerateDocumentationCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
dl 0
loc 36
rs 10
c 4
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 0 19 5
A configure() 0 12 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace JuliusHaertl\PHPDocToRst;
25
26
use JuliusHaertl\PHPDocToRst\Extension\AddFullElementNameExtension;
27
use JuliusHaertl\PHPDocToRst\Extension\PublicOnlyExtension;
28
use JuliusHaertl\PHPDocToRst\Extension\TocExtension;
29
use Symfony\Component\Console\Command\Command;
30
use Symfony\Component\Console\Input\InputInterface;
31
use Symfony\Component\Console\Input\InputOption;
32
use Symfony\Component\Console\Output\OutputInterface;
33
use Symfony\Component\Console\Input\InputArgument;
34
35
/**
36
 * Class GenerateDocumentationCommand
37
 * @package JuliusHaertl\PHPDocToRst
38
 * @internal Only for use of the phpdoc-to-rst cli tool
39
 */
40
class GenerateDocumentationCommand extends Command {
41
42
    protected function configure() {
43
        $this
44
            ->setName('generate')
45
            ->setDescription('Generate documentation')
46
            ->setHelp('This command allows you to generate sphinx/rst based documentation from PHPDoc annotations.')
47
            ->addArgument('target', InputArgument::REQUIRED, 'Destination for the generated rst files')
48
            ->addArgument(
49
                'src',
50
                InputArgument::IS_ARRAY,
51
                'Source directories to parse')
52
            ->addOption('public-only', 'p', InputOption::VALUE_NONE)
53
            ->addOption('element-toc', 't', InputOption::VALUE_NONE);
54
55
    }
56
57
    protected function execute(InputInterface $input, OutputInterface $output) {
58
        $src = $input->getArgument('src');
59
        $dst = $input->getArgument('target');
60
61
        $apiDocBuilder = new ApiDocBuilder($src, $dst);
62
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
63
            $apiDocBuilder->setVerboseOutput(true);
64
        }
65
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
66
            $apiDocBuilder->setVerboseOutput(true);
67
            $apiDocBuilder->setDebugOutput(true);
68
        }
69
        if($input->getOption('public-only')) {
70
            $apiDocBuilder->addExtension(PublicOnlyExtension::class);
71
        }
72
        if($input->getOption('element-toc')) {
73
            $apiDocBuilder->addExtension(TocExtension::class);
74
        }
75
        $apiDocBuilder->build();
76
    }
77
}