InstanceOfGuard   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validation() 0 8 2
A value() 0 5 1
A __construct() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace InputGuard\Guards;
5
6
use InputGuard\Guards\Bases\SingleInput;
7
8
class InstanceOfGuard implements Guard
9
{
10
    use ErrorMessagesBase;
11
    use SingleInput;
12
13
    /**
14
     * @var string
15
     */
16
    private $className;
17
18 5
    public function __construct($input, string $className, object $defaultValue = null)
19
    {
20 5
        $this->className = $className;
21 5
        $this->input     = $input;
22 5
        $this->value     = $defaultValue;
23 5
    }
24
25 4
    protected function validation($input, &$value): bool
26
    {
27 4
        if ($input instanceof $this->className) {
28 3
            $value = $input;
29 3
            return true;
30
        }
31
32 1
        return false;
33
    }
34
35 3
    public function value(): ?object
36
    {
37 3
        $this->success();
38
39 3
        return $this->value;
40
    }
41
}
42