Completed
Push — master ( 7d972a...3baf5c )
by Andrii
02:11
created

Period   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 26
ccs 6
cts 9
cp 0.6667
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValue() 0 4 1
A ensureValidValue() 0 8 2
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\addons;
12
13
use hiqdev\php\billing\charge\modifiers\AddonInterface;
14
15
/**
16
 * Period addon.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
abstract class Period implements AddonInterface
21
{
22
    /**
23
     * @var int
24
     */
25
    protected $value;
26
27 4
    public function __construct($value)
28
    {
29 4
        $this->value = static::ensureValidValue($value);
30 4
    }
31
32
    public function getValue()
33
    {
34
        return $this->value;
35
    }
36
37 4
    public static function ensureValidValue($value)
38
    {
39 4
        if (filter_var($value, FILTER_VALIDATE_INT) === false) {
40
            throw new \Exception('periodicity must be integer number');
41
        }
42
43 4
        return (int) $value;
44
    }
45
}
46