1 | <?php |
||
2 | /** |
||
3 | * PHP Billing Library |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/php-billing |
||
6 | * @package php-billing |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hiqdev\php\billing\charge\modifiers; |
||
12 | |||
13 | use hiqdev\php\billing\action\ActionInterface; |
||
14 | use hiqdev\php\billing\charge\ChargeInterface; |
||
15 | use hiqdev\php\billing\formula\FormulaSemanticsError; |
||
16 | use hiqdev\php\billing\price\SinglePrice; |
||
17 | use hiqdev\php\billing\target\Target; |
||
18 | use hiqdev\php\billing\type\Type; |
||
19 | use hiqdev\php\units\Quantity; |
||
20 | use Money\Money; |
||
21 | |||
22 | /** |
||
23 | * Leasing. |
||
24 | * |
||
25 | * @author Andrii Vasyliev <[email protected]> |
||
26 | */ |
||
27 | class Leasing extends Modifier |
||
28 | { |
||
29 | public function buildPrice(Money $sum) |
||
30 | { |
||
31 | $type = $this->getType(); |
||
32 | $target = $this->getTarget(); |
||
33 | $prepaid = Quantity::create('items', 0); |
||
34 | |||
35 | return new SinglePrice(null, $type, $target, null, $prepaid, $sum); |
||
36 | } |
||
37 | |||
38 | public function getType() |
||
39 | { |
||
40 | return new Type(Type::ANY, 'discount,leasing'); |
||
41 | } |
||
42 | |||
43 | public function getTarget() |
||
44 | { |
||
45 | return new Target(Target::ANY, Target::ANY); |
||
46 | } |
||
47 | |||
48 | 1 | public function till($dummy) |
|
0 ignored issues
–
show
|
|||
49 | { |
||
50 | 1 | throw new FormulaSemanticsError('till can not be defined for leasing'); |
|
51 | } |
||
52 | |||
53 | 1 | public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): array |
|
54 | { |
||
55 | 1 | if ($charge === null) { |
|
56 | throw new \Exception('unexpected null charge in Leasing, to be implemented'); |
||
57 | } |
||
58 | |||
59 | 1 | $this->ensureIsValid(); |
|
60 | |||
61 | 1 | $month = $action->getTime()->modify('first day of this month midnight'); |
|
62 | 1 | if (!$this->checkPeriod($month)) { |
|
63 | return []; |
||
64 | } |
||
65 | |||
66 | 1 | $reason = $this->getReason(); |
|
67 | 1 | if ($reason) { |
|
0 ignored issues
–
show
|
|||
68 | $charge->setComment($reason->getValue()); |
||
69 | } |
||
70 | |||
71 | 1 | return [$charge]; |
|
72 | } |
||
73 | |||
74 | 1 | protected function ensureIsValid() |
|
75 | { |
||
76 | 1 | $since = $this->getSince(); |
|
77 | 1 | if ($since === null) { |
|
78 | throw new FormulaSemanticsError('no since given for leasing'); |
||
79 | } |
||
80 | |||
81 | 1 | $term = $this->getTerm(); |
|
82 | 1 | if ($term === null) { |
|
83 | throw new FormulaSemanticsError('no term given for leasing'); |
||
84 | } |
||
85 | 1 | } |
|
86 | } |
||
87 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.