Completed
Push — master ( efd5b5...1cc014 )
by Andrii
02:16
created

Modifier::addAddon()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 6
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\charge\ChargeModifier;
16
17
/**
18
 * Fixed discount.
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class Modifier implements ChargeModifier
23
{
24
    /**
25
     * @var AddonInterface[]
26
     */
27
    protected $addons;
28
29 4
    public function __construct(array $addons = [])
30
    {
31 4
        $this->addons = $addons;
32 4
    }
33
34
    public function modifyCharge(ChargeInterface $charge, ActionInterface $action): array
35
    {
36
        throw new \Exception('not finished modifier');
37
    }
38
39
    public function reason($text)
40
    {
41
        return $this->addAddon('reason', new Reason($text));
42
    }
43
44
    public function since($time)
45
    {
46
        return $this->addAddon('since', new Since($time));
47
    }
48
49
    public function till($time)
50
    {
51
        return $this->addAddon('till', new Till($time));
52
    }
53
54
    public function addAddon($name, $addon)
55
    {
56
        if (isset($this->addons[$name])) {
57
            throw new \Exception("'$name' is already set");
58
        }
59
        $this->addons[$name] = $addon;
60
61
        return $this;
62
    }
63
}
64