1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Application Service Class |
5
|
|
|
* @package Ticaje_BookingApi |
6
|
|
|
* @author Hector Luis Barrientos <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Ticaje\BookingApi\Application\Service\Provider\Package; |
10
|
|
|
|
11
|
|
|
use Ticaje\BookingApi\Application\Signatures\Provider\Package\PackageProviderSignature; |
12
|
|
|
use Ticaje\BookingApi\Application\Signatures\Repository\PackageRepositoryInterface; |
13
|
|
|
use Ticaje\Contract\Persistence\Entity\EntityInterface; |
14
|
|
|
use Ticaje\Contract\Persistence\Repository\RepositoryInterface as BaseRepositoryInterface; |
15
|
|
|
use Ticaje\Hexagonal\Application\Signatures\UseCase\UseCaseCommandInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class RootAggregate |
19
|
|
|
* @package Ticaje\BookingApi\Application\Service\Provider |
20
|
|
|
*/ |
21
|
|
|
class RootAggregate implements PackageProviderSignature |
22
|
|
|
{ |
23
|
|
|
/** @var PackageRepositoryInterface $packageRepository */ |
24
|
|
|
private $packageRepository; |
25
|
|
|
|
26
|
|
|
/** @var EntityInterface $package */ |
27
|
|
|
private $package; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Package constructor. |
31
|
|
|
* |
32
|
|
|
* @param BaseRepositoryInterface $packageRepository |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
BaseRepositoryInterface $packageRepository |
36
|
|
|
) { |
37
|
|
|
$this->packageRepository = $packageRepository; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritDoc |
42
|
|
|
*/ |
43
|
|
|
public function instance(UseCaseCommandInterface $command): PackageProviderSignature |
44
|
|
|
{ |
45
|
|
|
$productId = $command->getProductId(); |
|
|
|
|
46
|
|
|
$storeId = $command->getStoreId(); |
|
|
|
|
47
|
|
|
$this->package = $this->packageRepository->getByProductAndStore($productId, $storeId); |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritDoc |
54
|
|
|
*/ |
55
|
|
|
public function getAvailability(int $from, int $to): bool |
56
|
|
|
{ |
57
|
|
|
// @todo implementation |
58
|
|
|
} |
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritDoc |
62
|
|
|
*/ |
63
|
|
|
public function getDepartureDays(): array |
64
|
|
|
{ |
65
|
|
|
$result = unserialize($this->package->getDepartureDays()); |
|
|
|
|
66
|
|
|
|
67
|
|
|
return array_map(function ($value) { |
68
|
|
|
return $value - 1; |
69
|
|
|
}, $result); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritDoc |
74
|
|
|
*/ |
75
|
|
|
public function getNumberOfNights(): int |
76
|
|
|
{ |
77
|
|
|
return (int)$this->package->getNumberOfNights(); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @inheritDoc |
82
|
|
|
*/ |
83
|
|
|
public function getDateTo(): string |
84
|
|
|
{ |
85
|
|
|
return $this->package->getDateTo(); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.