Action   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 23
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saleOccurred() 0 7 2
A isApplicable() 0 3 2
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-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\action;
12
13
use hiqdev\php\billing\price\PriceInterface;
14
15
/**
16
 * Simple Action.
17
 * It is applicable when price is applicable.
18
 * But it can be different see Coupon.
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class Action extends AbstractAction
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 25
    public function isApplicable(PriceInterface $price): bool
28
    {
29 25
        return $this->saleOccurred() && $price->isApplicable($this);
30
    }
31
32
    /**
33
     * // TODO: think about moving to Sale::isOccurred()
34
     *
35
     * @throws \Exception
36
     * @return bool whether Sale that belongs to current Action occurs in current month or earlier
37
     */
38 25
    private function saleOccurred(): bool
39
    {
40 25
        if ($this->sale === null) {
41 17
            return true;
42
        }
43
44 8
        return $this->sale->getTime() < $this->getTime()->modify('first day of next month 00:00');
45
    }
46
}
47