Passed
Push — master ( 7315fc...1ee6e1 )
by Vlad
03:07
created

CollectionInfoExtractor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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