ScenarioState   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 61.53%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 40
ccs 8
cts 13
cp 0.6153
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureNotEmpty() 0 4 2
A __construct() 0 4 1
A createInitial() 0 3 1
A asString() 0 3 1
A equals() 0 3 1
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Domain\Options;
20
21
class ScenarioState
22
{
23
    const INITIAL_SCENARIO = 'Scenario.START';
24
25
    /** @var string * */
26
    private $state;
27
28 6
    public function __construct(string $state)
29
    {
30 6
        $this->ensureNotEmpty($state);
31 6
        $this->state = $state;
32 6
    }
33
34
    public static function createInitial()
35
    {
36
        return new self(self::INITIAL_SCENARIO);
37
    }
38
39
    /**
40
     * @return string
41
     */
42 6
    public function asString()
43
    {
44 6
        return $this->state;
45
    }
46
47
    /**
48
     * @param ScenarioState $other
49
     *
50
     * @return bool
51
     */
52
    public function equals($other)
53
    {
54
        return $other->asString() === $this->asString();
55
    }
56
57 6
    private function ensureNotEmpty($state)
58
    {
59 6
        if (empty($state)) {
60
            throw new \InvalidArgumentException('Scenario state can not be empty');
61
        }
62 6
    }
63
}
64