Skip to content

Commit

Permalink
Merge pull request #3 from answear/opening-time
Browse files Browse the repository at this point in the history
Add OpeningSchedule and OpeningTime for Office
  • Loading branch information
malarzm authored Apr 27, 2021
2 parents cd2c527 + cbd41f8 commit da1e413
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Response/Struct/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
Expand Down
37 changes: 37 additions & 0 deletions src/Response/Struct/OpeningSchedule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Answear\SpeedyBundle\Response\Struct;

use Webmozart\Assert\Assert;

class OpeningSchedule
{
public OpeningTime $weekday;
public OpeningTime $saturday;
public OpeningTime $sunday;

public function __construct(OpeningTime $weekday, OpeningTime $saturday, OpeningTime $sunday)
{
$this->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'])
);
}
}
22 changes: 22 additions & 0 deletions src/Response/Struct/OpeningTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Answear\SpeedyBundle\Response\Struct;

class OpeningTime
{
public string $from;
public string $to;

public function __construct(string $from, string $to)
{
$this->from = $from;
$this->to = $to;
}

public function isClosed(): bool
{
return '00:00' === $this->from && '00:00' === $this->to;
}
}
10 changes: 10 additions & 0 deletions tests/Integration/Command/FindOfficeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit da1e413

Please sign in to comment.