Completed
Push — master ( 2bd21a...de5d06 )
by Dmitry
03:00
created

Action::saleOccurred()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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\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 21
    public function isApplicable(PriceInterface $price): bool
28
    {
29 21
        return $this->saleOccurred() && $price->isApplicable($this);
30
    }
31
32
    /**
33
     * // TODO: think about moving to Sale::isOccurred()
34
     *
35
     * @return bool whether Sale that belongs to current Action has been already occurred
36
     * @throws \Exception
37
     */
38 21
    private function saleOccurred(): bool
39
    {
40 21
        if ($this->sale === null) {
41 17
            return true;
42
        }
43
44 4
        return $this->sale->getTime() <= new \DateTimeImmutable();
45
    }
46
}
47