diff --git a/src/Response/Struct/Office.php b/src/Response/Struct/Office.php index ae5a767..106c9b3 100644 --- a/src/Response/Struct/Office.php +++ b/src/Response/Struct/Office.php @@ -15,6 +15,7 @@ class Office public string $nameEn; public int $siteId; public OfficeAddress $address; + public OpeningSchedule $openingSchedule; public WorkingTimeSchedule $workingTimeSchedule; public ShipmentParcelSize $maxParcelDimension; public float $maxParcelWeight; @@ -56,6 +57,7 @@ public static function fromArray(array $officeData): self $office->nameEn = $officeData['nameEn']; $office->siteId = $officeData['siteId']; $office->address = OfficeAddress::fromArray($officeData['address']); + $office->openingSchedule = OpeningSchedule::fromArray($officeData); $office->workingTimeSchedule = WorkingTimeSchedule::fromArray($officeData); $office->maxParcelDimension = ShipmentParcelSize::fromArray($officeData['maxParcelDimensions']); $office->maxParcelWeight = $officeData['maxParcelWeight']; diff --git a/src/Response/Struct/OpeningSchedule.php b/src/Response/Struct/OpeningSchedule.php new file mode 100644 index 0000000..a116fd1 --- /dev/null +++ b/src/Response/Struct/OpeningSchedule.php @@ -0,0 +1,37 @@ +weekday = $weekday; + $this->saturday = $saturday; + $this->sunday = $sunday; + } + + public static function fromArray(array $officeData): self + { + Assert::stringNotEmpty($officeData['workingTimeFrom']); + Assert::stringNotEmpty($officeData['workingTimeTo']); + Assert::stringNotEmpty($officeData['workingTimeHalfFrom']); + Assert::stringNotEmpty($officeData['workingTimeHalfTo']); + Assert::stringNotEmpty($officeData['workingTimeDayOffFrom']); + Assert::stringNotEmpty($officeData['workingTimeDayOffTo']); + + return new self( + new OpeningTime($officeData['workingTimeFrom'], $officeData['workingTimeTo']), + new OpeningTime($officeData['workingTimeHalfFrom'], $officeData['workingTimeHalfTo']), + new OpeningTime($officeData['workingTimeDayOffFrom'], $officeData['workingTimeDayOffTo']) + ); + } +} diff --git a/src/Response/Struct/OpeningTime.php b/src/Response/Struct/OpeningTime.php new file mode 100644 index 0000000..305e05d --- /dev/null +++ b/src/Response/Struct/OpeningTime.php @@ -0,0 +1,22 @@ +from = $from; + $this->to = $to; + } + + public function isClosed(): bool + { + return '00:00' === $this->from && '00:00' === $this->to; + } +} diff --git a/tests/Integration/Command/FindOfficeTest.php b/tests/Integration/Command/FindOfficeTest.php index c8b4da9..3ad70d3 100644 --- a/tests/Integration/Command/FindOfficeTest.php +++ b/tests/Integration/Command/FindOfficeTest.php @@ -76,6 +76,16 @@ private function assertOffice(FindOfficeResponse $response): void $this->assertSame($office->address->latitude, 42.987654); $this->assertSame($office->address->longitude, 24.123456); $this->assertCount(9, $office->workingTimeSchedule); + + $this->assertSame('08:30', $office->openingSchedule->weekday->from); + $this->assertSame('19:30', $office->openingSchedule->weekday->to); + $this->assertFalse($office->openingSchedule->weekday->isClosed()); + $this->assertSame('08:30', $office->openingSchedule->saturday->from); + $this->assertSame('14:30', $office->openingSchedule->saturday->to); + $this->assertFalse($office->openingSchedule->saturday->isClosed()); + $this->assertSame('00:00', $office->openingSchedule->sunday->from); + $this->assertSame('00:00', $office->openingSchedule->sunday->to); + $this->assertTrue($office->openingSchedule->sunday->isClosed()); } private function getCommand(): FindOffice