Completed
Push — master ( 43e33c...14ebff )
by Adam
03:20
created

Build   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 14
c 6
b 0
f 2
lcom 0
cbo 2
dl 0
loc 73
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setup() 0 3 1
A runDefault() 0 11 3
B detectAvailableTasks() 0 20 6
A error() 0 4 1
A logSection() 0 4 1
A log() 0 4 1
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
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
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
}