Completed
Push — master ( c0d92b...c0ae4b )
by Mahmoud
03:11
created

GenerateApiDocJsDocsTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Containers\Documentation\Tasks;
4
5
use App\Containers\Documentation\Contracts\ApiTypeInterface;
6
use App\Port\Task\Abstracts\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 GenerateApiDocJsDocsTask.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class GenerateApiDocJsDocsTask extends Task
17
{
18
19
    /**
20
     * @var  \Illuminate\Config\Repository
21
     */
22
    private $config;
23
24
    /**
25
     * GenerateApiDocJsDocsTask constructor.
26
     *
27
     * @param \Illuminate\Config\Repository $config
28
     */
29
    public function __construct(Config $config)
30
    {
31
        $this->config = $config;
32
    }
33
34
    /**
35
     * @param \App\Containers\Documentation\Contracts\ApiTypeInterface $type
36
     *
37
     * @return  mixed
38
     */
39
    public function run(ApiTypeInterface $type)
40
    {
41
        // the actual command that needs to be executed
42
        $command = "{$this->config->get('apidoc.executable')} -c {$type->getJsonFilePath()} -f {$type->getType()}.php -i app -o {$type->getDocumentationPath()}";
43
44
        // execute the command
45
        ($process = new Process($command))->run();
46
47
        if (!$process->isSuccessful()) {
48
            throw new ProcessFailedException($process);
49
        }
50
51
        // echo the output
52
        echo $type->getType() . ': ' . $process->getOutput();
53
54
        // return the past to that generated documentation
55
        return $type->getUrl();
56
    }
57
58
}
59