ControllerCollection::getErrorMessage()   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 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 0
b 0
f 0
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 Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
18
use function sprintf;
19
20
/**
21
 * Class ControllerCollection
22
 *
23
 * @package App\Rest
24
 * @author TLe, Tarmo Leppänen <[email protected]>
25
 *
26
 * @method ControllerInterface get(string $className)
27
 * @method IteratorAggregate<int, ControllerInterface> getAll()
28
 *
29
 * @template T<ControllerInterface>
30
 */
31
class ControllerCollection implements Countable
32
{
33
    use CollectionTrait;
34
35
    /**
36
     * Collection constructor.
37
     *
38
     * @phpstan-param IteratorAggregate<int, ControllerInterface> $items
39
     */
40 93
    public function __construct(
41
        #[TaggedIterator('app.rest.controller')]
42
        protected readonly IteratorAggregate $items,
43
        protected readonly LoggerInterface $logger,
44
    ) {
45 93
    }
46
47 1
    public function getErrorMessage(string $className): string
48
    {
49 1
        return sprintf('REST controller \'%s\' does not exist', $className);
50
    }
51
52 90
    public function filter(string $className): Closure
53
    {
54 90
        return static fn (ControllerInterface $restController): bool => $restController instanceof $className;
55
    }
56
}
57