private function calculateRoute() { $referenceStart = array_search($this->route->getStart()->gate, Gate::listGates($this->route->getWay())); $referenceEnd = array_search($this->route->getEnd()->gate, Gate::listGates($this->route->getWay())); $dataCalculated = ['time' => 0, 'timeReference' => 0, 'kms' => 0]; if ($referenceStart >= $referenceEnd) { while ($referenceStart < count(Gate::listGates($this->route->getWay()))) { $section = $this->sectionCollection->getItems($this->route->getWay(), $referenceStart); $this->route->setSection($section); $dataCalculated = $this->incrementValues($dataCalculated, $section->getData()); $referenceStart++; } //and restart $cursor = 0; while ($cursor < $referenceEnd) { $section = $this->sectionCollection->getItems($this->route->getWay(), $cursor); $this->route->setSection($section); foreach ($section->getData() as $field => $number) { $dataCalculated[$field] += (int) $number; } $cursor++; } } else { while ($referenceStart < $referenceEnd) { $section = $this->sectionCollection->getItems($this->route->getWay(), $referenceStart); $this->route->setSection($section); $dataCalculated = $this->incrementValues($dataCalculated, $section->getData()); $referenceStart++; } } foreach ($dataCalculated as $field => $value) { $this->route->{'set' . ucwords($field)}($value); } }
public function testCreateRoute() { $startGate = new Gate('chapelle', 'start'); $endGate = new Gate('orleans', 'end'); $data = ['time' => '8 min', 'timeReference' => '5 min', 'kms' => 5]; $route = new Route($startGate, $endGate, 'interior'); $this->assertSame('chapelle', $route->getStart()->getName()); $this->assertSame('orleans', $route->getEnd()->getName()); $this->assertSame('interior', $route->getWay()); $route->setKms(5); $this->assertSame(5, $route->getKms()); $section = new Section($startGate, $endGate, $data); $route->setSection($section); $route->setSection($section); $this->assertCount(2, $route->getSections()); $route->setTime('8 min'); $this->assertSame('8 min', $route->getTime()); $route->setTimeReference('5 min'); $this->assertSame('5 min', $route->getTimeReference()); }