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

Period::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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