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

Date   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 26
ccs 8
cts 9
cp 0.8889
rs 10

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 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