Completed
Push — master ( a17b9a...3a4c95 )
by Andrii
01:54
created

Date::ensureValidValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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 DateTimeImmutable;
14
15
/**
16
 * Date addon.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class Date
21
{
22
    /**
23
     * @var DateTimeImmutable
24
     */
25
    protected $value;
26
27 1
    public function __construct($value)
28
    {
29 1
        $this->value = static::ensureValidValue($value);
30 1
    }
31
32 1
    public function getValue()
33
    {
34 1
        return $this->value;
35
    }
36
37 1
    public static function ensureValidValue($value)
38
    {
39 1
        if ($value instanceof DateTimeImmutable) {
40 1
            return $value;
41
        }
42
43
        throw new \Exception('invalid date given');
44
    }
45
}
46