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

GenerateAPIDocsAction::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace App\Containers\Documentation\Actions;
4
5
use App\Containers\Documentation\Exceptions\WrongDocTypeException;
6
use App\Containers\Documentation\Tasks\GenerateApiDocJsDocsTask;
7
use App\Port\Action\Abstracts\Action;
8
9
/**
10
 * Class GenerateAPIDocsAction.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class GenerateAPIDocsAction extends Action
15
{
16
17
    /**
18
     * string
19
     */
20
    const TYPES_CLASSES_NAMESPACE = 'App\Containers\Documentation\Objects\\';
21
22
    /**
23
     * string
24
     */
25
    const TYPES_CLASSES_POSTFIX = 'Api';
26
27
    /**
28
     * @var  \App\Containers\Documentation\Tasks\GenerateApiDocJsDocsTask
29
     */
30
    private $generateApiDocJsDocsTask;
31
32
    /**
33
     * GenerateAPIDocsAction constructor.
34
     *
35
     * @param \App\Containers\Documentation\Tasks\GenerateApiDocJsDocsTask $generateApiDocJsDocsTask
36
     */
37
    public function __construct(GenerateApiDocJsDocsTask $generateApiDocJsDocsTask)
38
    {
39
        $this->generateApiDocJsDocsTask = $generateApiDocJsDocsTask;
40
    }
41
42
    /**
43
     * @param $types
44
     *
45
     * @return  string
46
     */
47
    public function run($types)
48
    {
49
        // generate the full namespace of the types class based on this function param
50
        if (!class_exists($typeClass = self::TYPES_CLASSES_NAMESPACE . ucwords($types) . self::TYPES_CLASSES_POSTFIX)) {
51
            throw new WrongDocTypeException("The Documentation type ($typeClass) is not supported!");
52
        }
53
54
        // create an instance of the Documentation Type Class and pass it as argument to this task
55
        return $this->generateApiDocJsDocsTask->run(new $typeClass());
56
    }
57
}
58