Passed
Push — main ( 76039c...af3e21 )
by Fractal
03:22
created

ConstraintsHelper::hasArrayDocBlock()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Helper;
6
7
use FRZB\Component\PhpDocReader\Reader\ReaderInterface as PhpDocReader;
8
use FRZB\Component\RequestMapper\Attribute\ArrayType;
9
use Symfony\Component\Validator\Constraint;
10
use Symfony\Component\Validator\Constraints\Collection;
11
12
/**
13
 * @internal
14
 */
15
final class ConstraintsHelper
16
{
17 15
    public static function createCollection(array $fields, bool $allowExtraFields = true, bool $allowMissingFields = true): Collection
18
    {
19 15
        return new Collection(fields: $fields, allowExtraFields: $allowExtraFields, allowMissingFields: $allowMissingFields);
20
    }
21
22
    /** @return array<Constraint> */
23 2
    public static function fromProperty(\ReflectionProperty $rProperty): array
24
    {
25 2
        return AttributeHelper::getAttributes($rProperty, Constraint::class);
26
    }
27
28 15
    public static function getArrayTypeAttribute(\ReflectionProperty $rProperty): ?ArrayType
29
    {
30 15
        return AttributeHelper::getAttribute($rProperty, ArrayType::class);
31
    }
32
33 23
    public static function hasArrayTypeAttribute(\ReflectionProperty $rProperty): bool
34
    {
35 23
        return 'array' === $rProperty->getType()?->getName() && null !== AttributeHelper::getAttribute($rProperty, ArrayType::class);
0 ignored issues
show
Bug introduced by
The method getName() does not exist on ReflectionType. It seems like you code against a sub-type of ReflectionType such as ReflectionNamedType. ( Ignorable by Annotation )

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

35
        return 'array' === $rProperty->getType()?->/** @scrutinizer ignore-call */ getName() && null !== AttributeHelper::getAttribute($rProperty, ArrayType::class);
Loading history...
36
    }
37
38 19
    public static function hasArrayDocBlock(\ReflectionProperty $rProperty, PhpDocReader $reader): bool
39
    {
40 19
        return 'array' === $rProperty->getType()?->getName() && null !== $reader->getPropertyClass($rProperty);
41
    }
42
}
43