Passed
Push — master ( 8e43c9...4981d1 )
by Tarmo
116:46 queued 51:34
created

ControllerCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Rest/ControllerCollection.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Rest;
10
11
use App\Collection\CollectionTrait;
12
use App\Rest\Interfaces\ControllerInterface;
13
use Closure;
14
use Countable;
15
use IteratorAggregate;
16
use Psr\Log\LoggerInterface;
17
use function sprintf;
18
19
/**
20
 * Class ControllerCollection
21
 *
22
 * @package App\Rest
23
 * @author TLe, Tarmo Leppänen <[email protected]>
24
 *
25
 * @method ControllerInterface get(string $className)
26
 * @method IteratorAggregate<int, ControllerInterface> getAll()
27
 */
28
class ControllerCollection implements Countable
29
{
30
    use CollectionTrait;
31
32
    /**
33
     * Collection constructor.
34
     *
35 60
     * @param IteratorAggregate<int, ControllerInterface> $items
36
     */
37 60
    public function __construct(
38 60
        private IteratorAggregate $items,
39 60
        private LoggerInterface $logger,
40
    ) {
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ')', expecting T_VARIABLE on line 40 at column 4
Loading history...
41 1
    }
42
43 1
    public function getErrorMessage(string $className): string
44 1
    {
45 1
        return sprintf('REST controller \'%s\' does not exist', $className);
46
    }
47
48 1
    public function filter(string $className): Closure
49
    {
50
        return static fn (ControllerInterface $restController): bool => $restController instanceof $className;
51 57
    }
52
}
53