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

Discount   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 25
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fixed() 0 4 1
A grows() 0 4 1
A ensureValidValue() 0 12 3
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