IsInstanceOf   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 24
ccs 5
cts 5
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 3 1
A __construct() 0 3 1
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