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 | /** |
||
| 3 | * User: ms |
||
| 4 | * Date: 29.08.15 |
||
| 5 | * Time: 09:36 |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace Mvg\Parser\Html; |
||
| 9 | |||
| 10 | |||
| 11 | use phpQuery; |
||
| 12 | use Mvg\Parser\AbstractParser; |
||
| 13 | /** |
||
| 14 | * Class Departures |
||
| 15 | * @package Mvg\Parser\Html |
||
| 16 | */ |
||
| 17 | class Departures extends AbstractParser { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $currentTime; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $station; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | protected $departureObjects = array(); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param $htmlResponse |
||
| 36 | */ |
||
| 37 | public function __construct($htmlResponse) { |
||
| 38 | |||
| 39 | parent::__construct($htmlResponse); |
||
| 40 | |||
| 41 | $html = $this->getHtmlResponse(); |
||
| 42 | phpQuery::newDocumentHTML($html); |
||
| 43 | $tableRows = pq('.rowEven,.rowOdd'); |
||
| 44 | foreach ($tableRows as $tableRow) { |
||
| 45 | $tableRow = pq($tableRow)->remove('.spacer'); |
||
| 46 | $departureObject = new \stdClass(); |
||
| 47 | $departureObject->lineNumber = trim(pq($tableRow)->find('.lineColumn')->html()); |
||
| 48 | $departureObject->destination = trim(preg_replace("(<([a-z]+).*?>.*?</\\1>)is", "", pq($tableRow)->find('.stationColumn')->html())); |
||
|
0 ignored issues
–
show
|
|||
| 49 | $departureObject->time = trim(pq($tableRow)->find('.inMinColumn')->html()); |
||
| 50 | $this->departureObjects[] = $departureObject; |
||
| 51 | |||
| 52 | } |
||
| 53 | |||
| 54 | //Time + Station name |
||
| 55 | $this->setStation(pq('.headerStationColumn')->html()); |
||
| 56 | $this->setCurrentTime(pq('.serverTimeColumn')->html()); |
||
| 57 | |||
| 58 | |||
| 59 | } |
||
| 60 | |||
| 61 | public function getDepartures() { |
||
| 62 | return $this->departureObjects; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | public function getCurrentTime() { |
||
| 69 | return $this->currentTime; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param string $currentTime |
||
| 74 | */ |
||
| 75 | protected function setCurrentTime($currentTime) { |
||
| 76 | $this->currentTime = $currentTime; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function getStation() { |
||
| 83 | return $this->station; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param string $station |
||
| 88 | */ |
||
| 89 | protected function setStation($station) { |
||
| 90 | $this->station = $station; |
||
| 91 | } |
||
| 92 | |||
| 93 | |||
| 94 | } |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.