|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Ticaje\BookingApi\Application\Service\Provider\AgencyCar; |
|
5
|
|
|
|
|
6
|
|
|
use Ticaje\BookingApi\Application\Service\Provider\BasePriceProvider; |
|
7
|
|
|
use Ticaje\BookingApi\Application\Signatures\Provider\PriceProviderSignature; |
|
8
|
|
|
use Ticaje\Hexagonal\Application\Signatures\UseCase\UseCaseCommandInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class Price |
|
12
|
|
|
* @package Ticaje\BookingApi\Application\Service\Provider\AgencyCar |
|
13
|
|
|
* Low level details kingdom. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Price extends BasePriceProvider implements PriceProviderSignature |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @inheritDoc |
|
19
|
|
|
*/ |
|
20
|
|
|
public function getPrice(UseCaseCommandInterface $command): float |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var string $indexed */ |
|
23
|
|
|
$indexed = (string)$this->instance->getSeasonBasedPrices(); |
|
|
|
|
|
|
24
|
|
|
$days = $this->calculateDays($command); |
|
25
|
|
|
$key = "{$indexed}"; |
|
26
|
|
|
$price = $this->extractLogicFromSerializedPrices($command->getProduct()->getData($key), $days->days); |
|
|
|
|
|
|
27
|
|
|
$price *= (int)$days->days; |
|
28
|
|
|
|
|
29
|
|
|
return (float)$price; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param $unserialized |
|
34
|
|
|
* @param $days |
|
35
|
|
|
* |
|
36
|
|
|
* @return |null |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
private function extractLogicFromSerializedPrices($unserialized, $days) |
|
39
|
|
|
{ |
|
40
|
|
|
$rules = $this->normalizePrice($unserialized); |
|
41
|
|
|
foreach ($rules as $range => $price) { |
|
42
|
|
|
$range = explode('..', $range); |
|
43
|
|
|
$storeDays = range($range[0], $range[1]); |
|
44
|
|
|
if (in_array($days, $storeDays)) { |
|
45
|
|
|
return $price; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param $value |
|
54
|
|
|
* |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
private function normalizePrice($value): array |
|
58
|
|
|
{ |
|
59
|
|
|
$normalizedArray = []; |
|
60
|
|
|
if (!$value) {// Guard clause |
|
61
|
|
|
return []; |
|
62
|
|
|
} |
|
63
|
|
|
$values = explode(';', $value); |
|
64
|
|
|
if (empty($values)) {// Guard clause |
|
65
|
|
|
return []; |
|
66
|
|
|
} |
|
67
|
|
|
foreach ($values as $val) { |
|
68
|
|
|
$indexValue = explode('=', $val); |
|
69
|
|
|
if (isset($indexValue[0]) && $indexValue[0]) { |
|
70
|
|
|
$normalizedArray[$indexValue[0]] = $indexValue[1]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $normalizedArray; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.