Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| ObjectWithRelation | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isExpired | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOrderId | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getDateToRecalculate | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\IntegrationTests\Apie\TypeDemo\Resources; |
| 3 | |
| 4 | use Apie\Core\ApieLib; |
| 5 | use Apie\Core\Entities\EntityInterface; |
| 6 | use Apie\Core\Entities\RequiresRecalculatingInterface; |
| 7 | use Apie\IntegrationTests\Apie\TypeDemo\Enums\ExpireStatus; |
| 8 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\ObjectWithRelationIdentifier; |
| 9 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\OrderIdentifier; |
| 10 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\UserIdentifier; |
| 11 | use DateTimeInterface; |
| 12 | |
| 13 | class ObjectWithRelation implements EntityInterface, RequiresRecalculatingInterface |
| 14 | { |
| 15 | private ObjectWithRelationIdentifier $id; |
| 16 | |
| 17 | public function __construct( |
| 18 | public UserIdentifier $userId, |
| 19 | public DateTimeInterface $expireDate, |
| 20 | private ?OrderIdentifier $orderId = null, |
| 21 | ) { |
| 22 | $this->id = ObjectWithRelationIdentifier::createRandom(); |
| 23 | } |
| 24 | |
| 25 | public function getId(): ObjectWithRelationIdentifier |
| 26 | { |
| 27 | return $this->id; |
| 28 | } |
| 29 | |
| 30 | public function getStatus(): ExpireStatus |
| 31 | { |
| 32 | return $this->isExpired() ? ExpireStatus::EXPIRED : ExpireStatus::ACTIVE; |
| 33 | } |
| 34 | |
| 35 | public function isExpired(): bool |
| 36 | { |
| 37 | return $this->expireDate < ApieLib::getPsrClock()->now(); |
| 38 | } |
| 39 | |
| 40 | public function getOrderId(): ?OrderIdentifier |
| 41 | { |
| 42 | if ($this->isExpired()) { |
| 43 | return null; |
| 44 | } |
| 45 | return $this->orderId; |
| 46 | } |
| 47 | |
| 48 | public function getDateToRecalculate(): ?DateTimeInterface |
| 49 | { |
| 50 | if ($this->isExpired()) { |
| 51 | return null; |
| 52 | } |
| 53 | return $this->expireDate; |
| 54 | } |
| 55 | } |