Passed
Push — main ( a74a35...66bb0f )
by Fractal
03:01
created

ConstraintsHelper::getArrayTypeAttribute()   A

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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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' === PropertyHelper::getTypeName($rProperty) && null !== AttributeHelper::getAttribute($rProperty, ArrayType::class);
40
    }
41
42 19
    public static function hasArrayDocBlock(\ReflectionProperty $rProperty, PhpDocReader $reader): bool
43
    {
44 19
        return 'array' === PropertyHelper::getTypeName($rProperty) && null !== $reader->getPropertyClass($rProperty);
45
    }
46
}
47