These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | |||
4 | namespace Genesis; |
||
5 | |||
6 | |||
7 | use Genesis\Commands; |
||
8 | use Genesis\Config; |
||
9 | |||
10 | /** |
||
11 | * @author Adam Bisek <[email protected]> |
||
12 | */ |
||
13 | class Build implements IBuild |
||
14 | { |
||
15 | |||
16 | protected $container; |
||
17 | |||
18 | protected $arguments; |
||
19 | |||
20 | |||
21 | public function __construct(Config\Container $container, array $arguments = NULL) |
||
22 | { |
||
23 | $this->container = $container; |
||
24 | $this->arguments = $arguments; |
||
25 | } |
||
26 | |||
27 | |||
28 | public function setup() |
||
29 | { |
||
30 | } |
||
31 | |||
32 | |||
33 | public function runDefault() |
||
34 | { |
||
35 | $helpCommand = new Commands\Help; |
||
36 | foreach ($this->detectAvailableTasks() as $section => $tasks) { |
||
37 | if(!$helpCommand->hasSection($section)){ |
||
38 | $helpCommand->addSection($section); |
||
39 | } |
||
40 | $helpCommand->setSectionTasks($section, $tasks); |
||
41 | } |
||
42 | $helpCommand->execute(); |
||
43 | } |
||
44 | |||
45 | |||
46 | protected function detectAvailableTasks() |
||
47 | { |
||
48 | $tasks = []; |
||
49 | $classReflection = new \ReflectionClass($this); |
||
50 | foreach ($classReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
||
51 | if (preg_match('#^run(.*)#', $method->getName(), $match)) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
52 | $doc = $method->getDocComment(); |
||
53 | $section = NULL; |
||
54 | if(preg_match('#@section ?([^\s]*)\s#s', $doc, $m)){ |
||
55 | $section = trim($m[1]); |
||
56 | } |
||
57 | $description = NULL; |
||
58 | if(preg_match('#([^@][a-zA-Z0-9]+)+#', $doc, $m)){ |
||
59 | $description = trim($m[0]); |
||
60 | } |
||
61 | $tasks[$section][lcfirst($match[1])] = $description != '' ? $description : NULL; |
||
62 | } |
||
63 | } |
||
64 | return $tasks; |
||
65 | } |
||
66 | |||
67 | |||
68 | protected function error($message) |
||
69 | { |
||
70 | throw new \ErrorException($message); |
||
71 | } |
||
72 | |||
73 | |||
74 | protected function logSection($message) |
||
75 | { |
||
76 | echo Cli::getColoredString("=> " . $message, 'green') . PHP_EOL; |
||
77 | } |
||
78 | |||
79 | |||
80 | protected function log($message) |
||
81 | { |
||
82 | echo $message . PHP_EOL; |
||
83 | } |
||
84 | |||
85 | } |