Passed
Push — main ( 6c9276...76dcd0 )
by Anatoly
06:53 queued 02:07
created

BuiltinAnnotationReader::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2021, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/hydrator/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/hydrator
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Hydrator\AnnotationReader;
15
16
use Generator;
17
use LogicException;
18
use ReflectionAttribute;
19
use Sunrise\Hydrator\AnnotationReaderInterface;
20
21
use function sprintf;
22
23
use const PHP_MAJOR_VERSION;
24
25
/**
26
 * @link https://www.php.net/attributes
27
 *
28
 * @since 3.1.0
29
 */
30
final class BuiltinAnnotationReader implements AnnotationReaderInterface
31
{
32
33
    /**
34
     * Constructor of the class
35
     *
36
     * @throws LogicException If the PHP version less than 8.0.
37
     */
38
    public function __construct()
39
    {
40
        // @codeCoverageIgnoreStart
41
        if (PHP_MAJOR_VERSION < 8) {
42
            throw new LogicException(sprintf(
43
                'The annotation reader {%s} requires PHP version greater than or equal to 8.0.',
44
                __CLASS__,
45
            ));
46
        } // @codeCoverageIgnoreEnd
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52 541
    public function getAnnotations(string $name, $holder): Generator
53
    {
54
        // @codeCoverageIgnoreStart
55
        if (PHP_MAJOR_VERSION < 8) {
56
            return;
57
        } // @codeCoverageIgnoreEnd
58
59 541
        $attributes = $holder->getAttributes($name, ReflectionAttribute::IS_INSTANCEOF);
60 541
        foreach ($attributes as $attribute) {
61 50
            yield $attribute->newInstance();
62
        }
63
    }
64
}
65