DocsCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 8
Bugs 1 Features 1
Metric Value
eloc 29
c 8
b 1
f 1
dl 0
loc 66
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 7 1
A execute() 0 21 3
A onConstruct() 0 15 1
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(
33
                '-o --output',
34
                'Output file (default README.md). For old project you should use something else'
35
                . "\n(OR mark region with <!-- DOCS START --> and <!-- DOCS END --> to inject docs)",
36
                null,
37
                'README.md'
38
            )
39
            ->option('-a --with-abstract', 'Create docs for abstract/interface class')
40
            ->option('-x --template', "User supplied template path\nIt has higher precedence than inbuilt templates")
41
            ->usage(
42
                '<bold>  phint docs</end>               Appends to readme.md<eol/>' .
43
                '<bold>  phint d</end> <comment>-o docs/api.md</end>   Writes to docs/api.md<eol/>'
44
            );
45
    }
46
47
    /**
48
     * Generate test stubs.
49
     *
50
     * @return void
51
     */
52
    public function execute()
53
    {
54
        $io = $this->app()->io();
55
56
        $io->comment('Preparing metadata ...', true);
57
        $docsMetadata = $this->getClassesMetadata();
58
59
        if (empty($docsMetadata)) {
60
            $io->bgGreen('Looks like nothing to do here', true);
61
62
            return;
63
        }
64
65
        $io->comment('Generating docs ...', true);
66
        $generated = $this->generate($docsMetadata, $this->values());
67
68
        if ($generated) {
69
            $io->cyan("$generated doc(s) generated", true);
70
        }
71
72
        $io->ok('Done', true);
73
    }
74
75
    protected function generate(array $docsMetadata, array $parameters): int
76
    {
77
        $generator = new TwigGenerator($this->getTemplatePaths($parameters), $this->getCachePath());
78
79
        $parameters['output'] = $this->_pathUtil->expand($parameters['output'], $this->_workDir);
80
81
        return $generator->generateDocs($docsMetadata, $parameters);
82
    }
83
}
84