Completed
Push — master ( fb9109...c0d92b )
by Mahmoud
03:27
created

GenerateApiDocJsDocsTask   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 18 2
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 Symfony\Component\Process\Exception\ProcessFailedException;
8
use Symfony\Component\Process\Process;
9
10
/**
11
 * Class GenerateApiDocJsDocsTask.
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class GenerateApiDocJsDocsTask extends Task
16
{
17
18
    /**
19
     * @param \App\Containers\Documentation\Contracts\ApiTypeInterface $type
20
     *
21
     * @return  mixed
22
     */
23
    public function run(ApiTypeInterface $type)
24
    {
25
        // the actual command that needs to be executed
26
        $command = "apidoc -c {$type->getJsonFilePath()} -f {$type->getType()}.php -i app -o {$type->getDocumentationPath()}";
27
28
        // execute the command
29
        ($process = new Process($command))->run();
30
31
        if (!$process->isSuccessful()) {
32
            throw new ProcessFailedException($process);
33
        }
34
35
        // echo the output
36
        echo $type->getType() . ': ' . $process->getOutput();
37
38
        // return the past to that generated documentation
39
        return $type->getUrl();
40
    }
41
42
}
43