Completed
Push — master ( ce9eda...f41b2c )
by Mahmoud
03:36
created

GenerateAPIDocsTask::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 2
1
<?php
2
3
namespace App\Containers\Documentation\Tasks;
4
5
use App\Containers\Documentation\Traits\DocsGeneratorTrait;
6
use App\Ship\Parents\Tasks\Task;
7
use Illuminate\Config\Repository as Config;
8
use Symfony\Component\Process\Exception\ProcessFailedException;
9
use Symfony\Component\Process\Process;
10
11
/**
12
 * Class GenerateAPIDocsTask.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class GenerateAPIDocsTask extends Task
17
{
18
19
    use DocsGeneratorTrait;
20
21
    /**
22
     * @var  \Illuminate\Config\Repository
23
     */
24
    private $config;
25
26
    /**
27
     * GenerateApiDocJsDocsTask constructor.
28
     *
29
     * @param \Illuminate\Config\Repository $config
30
     */
31
    public function __construct(Config $config)
32
    {
33
        $this->config = $config;
34
    }
35
36
    /**
37
     * @param $type
38
     *
39
     * @return  mixed
40
     */
41
    public function run($type, $console)
42
    {
43
        $path = $this->getDocumentationPath($type);
44
45
        $exe = $this->getExecutable();
46
47
        // the actual command that needs to be executed:
48
        $command = $exe . ' ' . "-c {$this->getJsonFilePath($type)} {$this->getEndpointFiles($type)}-i app -o {$path}";
49
50
        // execute the command
51
        ($process = new Process($command))->run();
52
53
        if (!$process->isSuccessful()) {
54
            throw new ProcessFailedException($process);
55
        }
56
57
        // echo the output
58
        $console->info('[' . $type . '] ' . $command);
59
        $console->info('Result: ' . $process->getOutput());
60
61
        // return the past to that generated documentation
62
        return $this->getFullApiUrl($type);
63
    }
64
65
}
66