Completed
Push — master ( f978d6...93ae9a )
by Michael
11:24
created

Departures   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 13
c 4
b 1
f 0
lcom 1
cbo 1
dl 0
loc 109
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFilter() 0 4 1
A setFilter() 0 4 1
A getDeparturesFactory() 0 4 1
A setDeparturesFactory() 0 4 1
A getOutput() 0 20 3
B getColorForLineNumber() 0 29 5
1
<?php
2
namespace Mvg\LedMatrixOutput;
3
4
class Departures
5
{
6
7
	/**
8
	 * @var \Mvg\Factories\Departures
9
	 */
10
	protected $departuresFactory = null;
11
12
	/**
13
	 * @var mixed
14
	 */
15
	protected $filter = null;
16
17
	/**
18
	 * @param \Mvg\Factories\Departures $departuresFactory
19
	 * @param mixed $filter
20
	 */
21
	public function __construct($departuresFactory, $filter = null)
22
	{
23
		$this->setDeparturesFactory($departuresFactory);
24
		$this->setFilter($filter);
25
	}
26
27
	/**
28
	 * @return mixed
29
	 */
30
	protected function getFilter()
31
	{
32
		return $this->filter;
33
	}
34
35
	/**
36
	 * @param mixed $filter
37
	 */
38
	protected function setFilter($filter)
39
	{
40
		$this->filter = $filter;
41
	}
42
43
44
	/**
45
	 * @return \Mvg\Factories\Departures
46
	 */
47
	protected function getDeparturesFactory()
48
	{
49
		return $this->departuresFactory;
50
	}
51
52
53
	/**
54
	 * @param \Mvg\Factories\Departures $departuresFactory
55
	 */
56
	protected function setDeparturesFactory($departuresFactory)
57
	{
58
		$this->departuresFactory = $departuresFactory;
59
	}
60
61
	public function getOutput()
62
	{
63
64
65
		$returnValue = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
66
		$returnValue['departures'] = array();
67
		$departuresItems = $this->getDeparturesFactory()->getItems($this->getFilter());
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
68
		if (count($departuresItems) == 0) {
69
			return null;
70
		}
71
		foreach ($departuresItems as $departureObject) {
72
			$returnValue['departures'][] = intval($departureObject->time);
73
74
		}
75
		$returnValue['name'] = $departureObject->lineNumber;
0 ignored issues
show
Bug introduced by
The variable $departureObject seems to be defined by a foreach iteration on line 71. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
76
		$returnValue['color'] = self::getColorForLineNumber($departureObject->lineNumber);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
77
		$returnValue['departureCount'] = count($departuresItems);
78
79
		return $returnValue;
80
	}
81
82
83
	public static function getColorForLineNumber($lineNumber)
84
	{
85
		if ($lineNumber === 'U3') {
86
			return array(
87
				'red' => 255,
88
				'green' => 127,
89
				'blue' => 0);
90
		} elseif ($lineNumber === '28') {
91
			return array(
92
				'red' => 100,
93
				'green' => 0,
94
				'blue' => 0);
95
		} elseif ($lineNumber === 'U2') {
96
			return array(
97
				'red' => 100,
98
				'green' => 0,
99
				'blue' => 20);
100
		} elseif ($lineNumber === 'U8') {
101
			return array(
102
				'red' => 100,
103
				'green' => 0,
104
				'blue' => 10);
105
		} else {
106
			return array(
107
				'red' => 0,
108
				'green' => 0,
109
				'blue' => 255);
110
		}
111
	}
112
}