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

Modifier::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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