Completed
Pull Request — master (#46)
by Jitendra
01:52
created

DocsCommand::getClassMetadata()   A

Complexity

Conditions 6
Paths 7

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 7
nop 1
dl 0
loc 29
rs 9.1111
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the PHINT package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace Ahc\Phint\Console;
13
14
use Ahc\Phint\Generator\TwigGenerator;
15
16
class DocsCommand extends BaseCommand
17
{
18
    /** @var string Command name */
19
    protected $_name = 'docs';
20
21
    /** @var string Command description */
22
    protected $_desc = 'Generate basic readme docs from docblocks';
23
24
    /**
25
     * Configure the command options/arguments.
26
     *
27
     * @return void
28
     */
29
    protected function onConstruct()
30
    {
31
        $this
32
            ->option('-o --output', 'Output file (default README.md). For old project you should use something else'
33
                . "\n(OR mark region with <!-- DOCS START --> and <!-- DOCS END --> to inject docs)",
34
                null, 'README.md'
35
            )
36
            ->option('-a --with-abstract', 'Create docs for abstract/interface class')
37
            ->option('-x --template', "User supplied template path\nIt has higher precedence than inbuilt templates")
38
            ->usage(
39
                '<bold>  phint docs</end>               Appends to readme.md<eol/>' .
40
                '<bold>  phint d</end> <comment>-o docs/api.md</end>   Writes to docs/api.md<eol/>'
41
            );
42
    }
43
44
    /**
45
     * Generate test stubs.
46
     *
47
     * @return void
48
     */
49
    public function execute()
50
    {
51
        $io = $this->app()->io();
52
53
        $io->comment('Preparing metadata ...', true);
54
        $docsMetadata = $this->getClassesMetadata();
55
56
        if (empty($docsMetadata)) {
57
            $io->bgGreen('Looks like nothing to do here', true);
58
59
            return;
60
        }
61
62
        $io->comment('Generating docs ...', true);
63
        $generated = $this->generate($docsMetadata, $this->values());
64
65
        if ($generated) {
66
            $io->cyan("$generated doc(s) generated", true);
67
        }
68
69
        $io->ok('Done', true);
70
    }
71
72
    protected function generate(array $docsMetadata, array $parameters): int
73
    {
74
        $generator = new TwigGenerator($this->getTemplatePaths($parameters), $this->getCachePath());
75
76
        $parameters['output'] = $this->_pathUtil->expand($parameters['output'], $this->_workDir);
77
78
        return $generator->generateDocs($docsMetadata, $parameters);
79
    }
80
}
81