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

Discount::grows()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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 Money\Money;
14
15
/**
16
 * General discount.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class Discount extends Modifier
21
{
22 1
    public function fixed($value)
23
    {
24 1
        return new FixedDiscount($value, $this->addons);
25
    }
26
27 1
    public function grows($step, $start = null)
28
    {
29 1
        return new GrowingDiscount($step, $start, $this->addons);
30
    }
31
32 3
    public static function ensureValidValue($value)
33
    {
34 3
        if (is_numeric($value) || $value instanceof Money) {
35 3
            return $value;
36
        }
37
38
        /// TODO: add convertion from string
39
40
        /// TODO: add special exception
41
        var_dump($value);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($value); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
42
        throw new \Exception('invalid discount value');
43
    }
44
}
45