Completed
Push — master ( 6bcfe0...b7fa03 )
by Adam
04:08
created

Build::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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
	/** @var Config\Container */
17
	private $container;
18
19
	/** @var array */
20
	private $arguments;
21
22
23 15
	public function __construct(Config\Container $container, array $arguments = NULL)
24
	{
25 15
		$this->container = $container;
26 15
		$this->arguments = $arguments;
0 ignored issues
show
Documentation Bug introduced by
It seems like $arguments can be null. However, the property $arguments is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
27 15
	}
28
29
30
	/**
31
	 * @return Config\Container
32
	 */
33 3
	public function getContainer()
34
	{
35 3
		return $this->container;
36
	}
37
38
39
	/**
40
	 * @return array
41
	 */
42 4
	public function getArguments()
43
	{
44 4
		return $this->arguments;
45
	}
46
47
	/**
48
	 * Back compatibility.
49
	 * @TODO: remove in version 3.x
50
	 * @codeCoverageIgnoreStart
51
	 */
52
	public function &__get($name)
53
	{
54
		if(in_array($name, ['container', 'arguments'])){
55
			$method = 'get' . ucfirst($name);
56
			trigger_error(E_USER_WARNING, "Property '$name' is deprecated, use method $method() instead.");
57
			return $this->$method();
58
		}
59
		trigger_error(E_USER_WARNING, "Property '$name' is not defined.");
60
	}//@codeCoverageIgnoreEnd
61
62 9
	public function setup()
63
	{
64 9
	}
65
66
67 3
	public function runDefault()
68
	{
69 3
		$helpCommand = new Commands\Help;
70 3
		foreach ($this->detectAvailableTasks() as $section => $tasks) {
71 3
			if (!$helpCommand->hasSection($section)) {
72 3
				$helpCommand->addSection($section);
73 3
			}
74 3
			$helpCommand->setSectionTasks($section, $tasks);
75 3
		}
76 3
		$helpCommand->execute();
77 3
	}
78
79
80 3
	protected function detectAvailableTasks()
81
	{
82 3
		$tasks = [];
83 3
		$classReflection = new \ReflectionClass($this);
84 3
		foreach ($classReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
85 3
			if (preg_match('#^run(.*)#', $method->name, $match)) {
86 3
				$doc = $method->getDocComment();
87 3
				$section = NULL;
88 3
				if (preg_match('#@section ?([^\s]*)\s#s', $doc, $m)) {
89 3
					$section = trim($m[1]);
90 3
				}
91 3
				$description = NULL;
92 3
				if (preg_match('#([^@][a-zA-Z0-9]+)+#', $doc, $m)) {
93 3
					$description = trim($m[0]);
94 3
				}
95 3
				$tasks[$section][lcfirst($match[1])] = $description != '' ? $description : NULL;
96 3
			}
97 3
		}
98 3
		return $tasks;
99
	}
100
101
102 1
	protected function error($message)
103
	{
104 1
		throw new ErrorException($message);
105
	}
106
107
108 3
	protected function logSection($message)
109
	{
110 3
		echo Cli::getColoredString("=> " . $message, 'green') . PHP_EOL;
111 3
	}
112
113
114 7
	protected function log($message)
115
	{
116 7
		echo $message . PHP_EOL;
117 7
	}
118
119
}