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

Discount::ensureValidValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

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