Test Setup Failed
Push — main ( c2f1dd...c584c3 )
by Fractal
11:13
created

ConstraintsHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 21
rs 10
ccs 6
cts 6
cp 1
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getArrayTypeAttribute() 0 3 1
A fromProperty() 0 3 1
A createCollection() 0 3 1
A hasArrayTypeAttribute() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Helper;
6
7
use FRZB\Component\RequestMapper\Attribute\ArrayType;
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\Constraints\Collection;
10
11
/**
12
 * @internal
13
 */
14
final class ConstraintsHelper
15 15
{
16
    public static function createCollection(array $fields, bool $allowExtraFields = true, bool $allowMissingFields = true): Collection
17 15
    {
18
        return new Collection(fields: $fields, allowExtraFields: $allowExtraFields, allowMissingFields: $allowMissingFields);
19
    }
20
21 17
    /** @return array<Constraint> */
22
    public static function fromProperty(\ReflectionProperty $rProperty): array
23 17
    {
24 17
        return AttributeHelper::getAttributes($rProperty, Constraint::class);
25 17
    }
26
27
    public static function getArrayTypeAttribute(\ReflectionProperty $rProperty): ?ArrayType
28
    {
29
        return AttributeHelper::getAttribute($rProperty, ArrayType::class);
30
    }
31
32
    public static function hasArrayTypeAttribute(\ReflectionProperty $rProperty): bool
33
    {
34
        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

34
        return 'array' === $rProperty->getType()?->/** @scrutinizer ignore-call */ getName() && null !== AttributeHelper::getAttribute($rProperty, ArrayType::class);
Loading history...
35
    }
36
}
37