IsInstanceOf   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isApplicable() 0 3 2
A __invoke() 0 5 2
1
<?php
2
/**
3
 * File was created 29.05.2015 21:06
4
 *
5
 * @author Karsten J. Gerber <[email protected]>
6
 */
7
8
namespace PeekAndPoke\Component\Psi\Psi;
9
10
use PeekAndPoke\Component\Psi\Functions\ParameterizedUnaryFunction;
11
12
/**
13
 * IsInstanceOf checks if the input is of a certain type.
14
 *
15
 * @see    ParameterizedUnaryFunction
16
 * @see    IsInstanceOfIsNotInstanceOfTest
17
 *
18
 * @author Karsten J. Gerber <[email protected]>
19
 */
20
class IsInstanceOf extends ParameterizedUnaryFunction
21
{
22
    /**
23
     * @param mixed $input
24
     *
25
     * @return bool
26
     */
27 48
    public function __invoke($input)
28
    {
29 48
        $val = $this->getValue();
30
31 48
        return $this->isApplicable($val) && ($input instanceof $val);
32
    }
33
34
    /**
35
     * @param $val
36
     *
37
     * @return bool
38
     */
39 48
    private function isApplicable($val)
40
    {
41 48
        return is_string($val) || is_object($val);
42
    }
43
}
44