InstanceOfGuard::validation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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