CollectionInfoExtractor   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 55
ccs 24
cts 26
cp 0.9231
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B getValueType() 0 45 8
1
<?php
2
/**
3
 * Schema Validator
4
 *
5
 * @author Vlad Shashkov <[email protected]>
6
 * @copyright Copyright (c) 2021, The Myaza Software
7
 */
8
9
declare(strict_types=1);
10
11
namespace SchemaValidator\CollectionInfoExtractor;
12
13
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
14
15
final class CollectionInfoExtractor implements CollectionInfoExtractorInterface
16
{
17 8
    public function __construct(
18
        private PropertyInfoExtractorInterface $propertyInfoExtractor
19
    ) {
20 8
    }
21
22
    /**
23
     * @psalm-suppress DeprecatedMethod
24
     */
25 8
    public function getValueType(string $class, string $propertyName): ValueType
26
    {
27 8
        $typesProperty = $this->propertyInfoExtractor->getTypes($class, $propertyName);
28
29 8
        if (null === $typesProperty) {
30 1
            return new ValueType(null, true);
31
        }
32
33 7
        foreach ($typesProperty as $type) {
34 5
            if (!$type->isCollection()) {
35 5
                continue;
36
            }
37
38 5
            if (method_exists($type, 'getCollectionValueTypes')) {
39 2
                $valueTypes = $type->getCollectionValueTypes();
40
41 2
                if ([] === $valueTypes) {
42
                    return new ValueType(null, true);
43
                }
44
45 2
                $valueType = $valueTypes[0];
46
47 2
                return new ValueType(
48 2
                    $valueType->getClassName() ?? $valueType->getBuiltinType(),
49 2
                    null === $valueType->getClassName()
50
                );
51
            }
52
53 3
            if (!method_exists($type, 'getCollectionValueType')) {
54
                continue;
55
            }
56
57 3
            $valueType = $type->getCollectionValueType();
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Proper...etCollectionValueType() has been deprecated: since Symfony 5.3, use "getCollectionValueTypes()" instead ( Ignorable by Annotation )

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

57
            $valueType = /** @scrutinizer ignore-deprecated */ $type->getCollectionValueType();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
59 3
            if (null === $valueType) {
60 1
                return new ValueType(null, true);
61
            }
62
63 2
            return new ValueType(
64 2
                $valueType->getClassName() ?? $valueType->getBuiltinType(),
65 2
                null === $valueType->getClassName()
66
            );
67
        }
68
69 2
        return new ValueType(null, true);
70
    }
71
}
72