Departures::cmpObjects()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 7
rs 9.4285
1
<?php
2
/**
3
 * User: ms
4
 * Date: 29.08.15
5
 * Time: 21:15
6
 */
7
namespace Mvg\Factories;
8
9
10
use  Mvg\Parser\Html\Departures as ParserDepartures;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
11
12
class Departures implements FactoryInterface {
13
	/**
14
	 * @var ParserDepartures null
15
	 */
16
	protected $parserDepartures = null;
17
18
	/**
19
	 * @var array
20
	 */
21
	protected $departures = array();
22
23
	public function __construct(ParserDepartures $parserDepartures) {
24
		$this->setParserDepartures($parserDepartures);
25
		$this->departures = $parserDepartures->getDepartures();
26
		usort($this->departures, array("Mvg\Factories\Departures", "cmpObjects"));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Mvg\Factories\Departures does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal cmpObjects does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
27
28
	}
29
30
	protected static function cmpObjects($a, $b) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
31
32
		if ($a->time === $b->time) {
33
			return 0;
34
		}
35
		return ($a->time > $b->time) ? +1 : -1;
36
	}
37
38
	/**
39
	 * Filter By Destination
40
	 * @param mixed $filter
41
	 * @return array
42
	 */
43
	public function getItems($filter = '') {
44
		if ('' === $filter) {
45
			return $this->departures;
46
		}
47
		if (null === $filter) {
48
			return $this->departures;
49
		}
50
51
		if( true === empty($filter)) {
52
			return $this->departures;
53
		}
54
55
		if (false === is_array($filter)) {
56
			$filter = [$filter];
57
		}
58
59
		$departures = array();
60
61
		foreach ($this->departures as $departure) {
62
			if (true === in_array($departure->destination, $filter)) {
63
				$departures[] = $departure;
64
			}
65
		}
66
		return $departures;
67
	}
68
69
	/**
70
	 * @return string
71
	 */
72
	public function getCurrentTime() {
73
		return $this->parserDepartures->getCurrentTime();
74
	}
75
76
	/**
77
	 * @return string
78
	 */
79
	public function getStation() {
80
		return $this->parserDepartures->getStation();
81
	}
82
83
	/**
84
	 * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be ParserDepartures?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
85
	 */
86
	protected function getParserDepartures() {
87
		return $this->parserDepartures;
88
	}
89
90
	/**
91
	 * @param ParserDepartures $parserDepartures
92
	 */
93
	protected function setParserDepartures(ParserDepartures $parserDepartures) {
94
		$this->parserDepartures = $parserDepartures;
95
	}
96
97
98
}