ScalarEnsurance   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isString() 0 6 1
A isNumeric() 0 6 1
A isBool() 0 6 1
1
<?php
2
3
namespace Dgame\Ensurance;
4
5
/**
6
 * Class ScalarEnsurance
7
 * @package Dgame\Ensurance
8
 */
9
final class ScalarEnsurance implements EnsuranceInterface
10
{
11
    use EnsuranceTrait;
12
13
    /**
14
     * ScalarEnsurance constructor.
15
     *
16
     * @param EnsuranceInterface $ensurance
17
     */
18
    public function __construct(EnsuranceInterface $ensurance)
19
    {
20
        $this->transferEnsurance($ensurance);
21
    }
22
23
    /**
24
     * @return StringEnsurance
25
     */
26
    public function isString(): StringEnsurance
27 26
    {
28
        $this->ensure(is_string($this->value))->orThrow('"%s" is not a string', $this->value);
29 26
30
        return new StringEnsurance($this);
31
    }
32
33 26
    /**
34 26
     * @return NumericEnsurance
35
     */
36
    public function isNumeric(): NumericEnsurance
37
    {
38
        $this->ensure(is_numeric($this->value))->orThrow('"%s" is not numeric', $this->value);
39 12
40
        return new NumericEnsurance($this);
41 12
    }
42
43 12
    /**
44
     * @return BooleanEnsurance
45
     */
46
    public function isBool(): BooleanEnsurance
47
    {
48
        $this->ensure(is_bool($this->value))->orThrow('"%s" is not a bool', $this->value);
49 12
50
        return new BooleanEnsurance($this);
51
    }
52
}