Passed
Push — main ( a74a35...8a07cd )
by Fractal
03:04
created

ConstraintsHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
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 JetBrains\PhpStorm\Immutable;
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\Constraints\Collection;
12
13
/** @internal */
14
#[Immutable]
15
final class ConstraintsHelper
16
{
17
    private function __construct()
18
    {
19
    }
20
21 15
    public static function createCollection(array $fields, bool $allowExtraFields = true, bool $allowMissingFields = true): Collection
22
    {
23 15
        return new Collection(fields: $fields, allowExtraFields: $allowExtraFields, allowMissingFields: $allowMissingFields);
24
    }
25
26
    /** @return array<Constraint> */
27 2
    public static function fromProperty(\ReflectionProperty $rProperty): array
28
    {
29 2
        return AttributeHelper::getAttributes($rProperty, Constraint::class);
30
    }
31
32 15
    public static function getArrayTypeAttribute(\ReflectionProperty $rProperty): ?ArrayType
33
    {
34 15
        return AttributeHelper::getAttribute($rProperty, ArrayType::class);
35
    }
36
37 20
    public static function hasArrayTypeAttribute(\ReflectionProperty $rProperty): bool
38
    {
39 20
        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

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