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

Date::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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