schmiddim /
mvg-live-php
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
|
|||
| 66 | $returnValue['departures'] = array(); |
||
| 67 | $departuresItems = $this->getDeparturesFactory()->getItems($this->getFilter()); |
||
|
0 ignored issues
–
show
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
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...
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
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 | } |
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
will produce issues in the first and second line, while this second example
will produce no issues.