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