ReaderFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Annotated;
6
7
use Doctrine\Common\Annotations\Reader as DoctrineReader;
8
use Spiral\Attributes\AnnotationReader;
9
use Spiral\Attributes\AttributeReader;
10
use Spiral\Attributes\Composite\SelectiveReader;
11
use Spiral\Attributes\ReaderInterface;
12
13
final class ReaderFactory
14
{
15 1062
    public static function create(DoctrineReader|ReaderInterface $reader = null): ReaderInterface
16
    {
17
        return match (true) {
18 1062
            $reader instanceof ReaderInterface => $reader,
19 20
            $reader instanceof DoctrineReader => new AnnotationReader($reader),
0 ignored issues
show
Bug introduced by
It seems like $reader can also be of type Spiral\Attributes\ReaderInterface; however, parameter $reader of Spiral\Attributes\AnnotationReader::__construct() does only seem to accept Doctrine\Common\Annotations\Reader|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
            $reader instanceof DoctrineReader => new AnnotationReader(/** @scrutinizer ignore-type */ $reader),
Loading history...
20 10
            $reader === null => new SelectiveReader([
21 10
                new AttributeReader(),
22 1062
                new AnnotationReader(),
23
            ]),
24
        };
25
    }
26
}
27