|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace FRZB\Component\RequestMapper\Extractor; |
|
6
|
|
|
|
|
7
|
|
|
use Fp\Collections\ArrayList; |
|
8
|
|
|
use Fp\Collections\Entry; |
|
9
|
|
|
use Fp\Collections\HashMap; |
|
10
|
|
|
use FRZB\Component\DependencyInjection\Attribute\AsService; |
|
11
|
|
|
use FRZB\Component\PhpDocReader\Exception\ReaderException; |
|
12
|
|
|
use FRZB\Component\PhpDocReader\Reader\ReaderInterface as PhpDocReader; |
|
13
|
|
|
use FRZB\Component\RequestMapper\Helper\ClassHelper; |
|
14
|
|
|
use FRZB\Component\RequestMapper\Helper\ConstraintsHelper; |
|
15
|
|
|
use FRZB\Component\RequestMapper\Helper\PropertyHelper; |
|
16
|
|
|
use FRZB\Component\RequestMapper\Helper\SerializerHelper; |
|
17
|
|
|
|
|
18
|
|
|
#[AsService] |
|
19
|
|
|
class ParametersExtractor |
|
20
|
|
|
{ |
|
21
|
19 |
|
public function __construct( |
|
22
|
|
|
private readonly PhpDocReader $reader, |
|
23
|
|
|
) { |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
19 |
|
public function extract(string $class, array $parameters): array |
|
27
|
|
|
{ |
|
28
|
19 |
|
return [...$parameters, ...$this->mapProperties(PropertyHelper::getMapping($class, $parameters, $this->reader), $parameters)]; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
19 |
|
private function mapProperties(array $properties, array $parameters): array |
|
32
|
|
|
{ |
|
33
|
19 |
|
return HashMap::collect($properties) |
|
34
|
19 |
|
->map(fn (Entry $e) => match (true) { |
|
35
|
19 |
|
\is_array($e->value) => $this->mapPropertiesForArray($e->key, $e->value, $parameters), |
|
36
|
19 |
|
ClassHelper::isNotBuiltinAndExists($e->value) => $this->extract($e->value, $parameters[$e->key] ?? []), |
|
37
|
19 |
|
ClassHelper::isEnum($e->value) => $this->mapEnum($e->value, $parameters[$e->key] ?? null), |
|
38
|
19 |
|
!ClassHelper::isNotBuiltinAndExists($e->value) => $parameters[$e->key] ?? null, |
|
39
|
19 |
|
default => null, |
|
40
|
|
|
}) |
|
41
|
19 |
|
->toAssocArray() |
|
42
|
19 |
|
->getOrElse([]) |
|
43
|
|
|
; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function mapEnum(string $enumClassName, mixed $value = null): ?\BackedEnum |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
return match (true) { |
|
49
|
|
|
is_subclass_of($enumClassName, \IntBackedEnum::class) && \is_int($value) => $enumClassName::tryFrom($value), |
|
|
|
|
|
|
50
|
|
|
is_subclass_of($enumClassName, \StringBackedEnum::class) && \is_string($value) => $enumClassName::tryFrom($value), |
|
|
|
|
|
|
51
|
|
|
default => null, |
|
52
|
|
|
}; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function mapPropertiesForArray(string $key, array $value, array $parameters): array |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
return HashMap::collect($parameters[$key] ?? []) |
|
58
|
|
|
->map(static fn (Entry $e) => $e->value[$key]) |
|
59
|
|
|
->map(fn (Entry $e) => $this->extract($e->value, $parameters[$key][$e->key] ?? [])) |
|
60
|
|
|
->toAssocArray() |
|
61
|
|
|
->get() |
|
62
|
|
|
; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths