IsInstanceOf::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Bdf\Collection\Util\Functor\Predicate;
4
5
/**
6
 * Check if the element is an instance of the given class name
7
 *
8
 * <code>
9
 * $stream
10
 *     ->filter(new IsInstanceOf(User::class)
11
 *     ->forEach(function (User $user) { ... })
12
 * ;
13
 * </code>
14
 */
15
final class IsInstanceOf implements PredicateInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    private $className;
21
22
23
    /**
24
     * IsInstanceOf constructor.
25
     *
26
     * @param string $className The class name
27
     */
28 1
    public function __construct(string $className)
29
    {
30 1
        $this->className = $className;
31 1
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function __invoke($element, $key = null): bool
37
    {
38 1
        return $element instanceof $this->className;
39
    }
40
}
41