BillState   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 47
ccs 0
cts 32
cp 0
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 9 3
A finished() 0 3 1
A isNew() 0 3 1
A isFinished() 0 3 1
A getName() 0 3 1
A __construct() 0 3 1
A new() 0 3 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-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\bill;
12
13
/**
14
 * Bill State.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class BillState
19
{
20
    const STATE_NEW      = 'new';
21
    const STATE_FINISHED = 'finished';
22
23
    /** @var string */
24
    protected $state;
25
26
    private function __construct(string $state = self::STATE_NEW)
27
    {
28
        $this->state = $state;
29
    }
30
31
    public function getName()
32
    {
33
        return $this->state;
34
    }
35
36
    public function isNew()
37
    {
38
        return $this->state === self::STATE_NEW;
39
    }
40
41
    public function isFinished()
42
    {
43
        return $this->state === self::STATE_FINISHED;
44
    }
45
46
    public static function new()
47
    {
48
        return new self(self::STATE_NEW);
49
    }
50
51
    public static function finished()
52
    {
53
        return new self(self::STATE_FINISHED);
54
    }
55
56
    public static function fromString(string $name)
57
    {
58
        foreach ([self::STATE_NEW, self::STATE_FINISHED] as $state) {
59
            if ($state === $name) {
60
                return new self($state);
61
            }
62
        }
63
64
        throw new \Exception("wrong bill state '$name'");
65
    }
66
}
67