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

src/Mvg/Factories/Departures.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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;
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"));
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
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
}