1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium; |
4
|
|
|
|
5
|
|
|
use Formularium\Exception\ClassNotFoundException; |
6
|
|
|
use Formularium\Extradata; |
|
|
|
|
7
|
|
|
use Formularium\ExtradataParameter; |
|
|
|
|
8
|
|
|
use Formularium\Field; |
9
|
|
|
use Formularium\Factory\ValidatorFactory; |
10
|
|
|
use Formularium\Metadata; |
11
|
|
|
use GraphQL\Language\AST\DirectiveNode; |
12
|
|
|
use GraphQL\Language\AST\NodeList; |
13
|
|
|
use Modelarium\Exception\Exception; |
14
|
10 |
|
|
15
|
|
|
class FormulariumUtils |
16
|
|
|
{ |
17
|
|
|
public static function getFieldFromDirectives( |
18
|
|
|
string $fieldName, |
19
|
10 |
|
string $datatypeName, |
20
|
10 |
|
NodeList $directives |
21
|
10 |
|
): Field { |
22
|
8 |
|
$validators = []; |
23
|
|
|
$renderable = []; |
24
|
8 |
|
$extradata = []; |
25
|
|
|
foreach ($directives as $directive) { |
26
|
|
|
$name = $directive->name->value; |
27
|
|
|
|
28
|
|
|
if ($name === 'renderable') { |
29
|
|
|
foreach ($directive->arguments as $arg) { |
30
|
|
|
/** |
31
|
|
|
* @var \GraphQL\Language\AST\ArgumentNode $arg |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
$argName = $arg->name->value; |
35
|
|
|
$argValue = $arg->value->value; /** @phpstan-ignore-line */ |
|
|
|
|
36
|
|
|
$renderable[$argName] = $argValue; |
37
|
8 |
|
} |
38
|
|
|
continue; |
39
|
8 |
|
} |
40
|
8 |
|
|
41
|
8 |
|
$extradata[] = FormulariumUtils::directiveToExtradata($directive); |
42
|
|
|
|
43
|
|
|
$validator = null; |
|
|
|
|
44
|
|
|
try { |
45
|
|
|
$validator = ValidatorFactory::class($name); |
46
|
|
|
} catch (ClassNotFoundException $e) { |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var Metadata $metadata |
52
|
|
|
*/ |
53
|
|
|
$metadata = $validator::getMetadata(); |
54
|
|
|
$arguments = []; |
55
|
|
|
|
56
|
|
|
foreach ($directive->arguments as $arg) { |
57
|
|
|
/** |
58
|
|
|
* @var \GraphQL\Language\AST\ArgumentNode $arg |
59
|
|
|
*/ |
60
|
|
|
|
61
|
|
|
$argName = $arg->name->value; |
62
|
|
|
$argValue = $arg->value->value; /** @phpstan-ignore-line */ |
63
|
|
|
|
64
|
|
|
$argValidator = $metadata->parameter($argName); |
65
|
|
|
if (!$argValidator) { |
66
|
|
|
throw new Exception("Directive $validator does not have argument $argName"); |
67
|
|
|
} |
68
|
|
|
if ($argValidator->type === 'Int') { |
69
|
|
|
$argValue = (int)$argValue; |
70
|
|
|
} |
71
|
10 |
|
$arguments[$argName] = $argValue; |
72
|
10 |
|
} |
73
|
10 |
|
|
74
|
10 |
|
$validators[$name] = $arguments; |
75
|
10 |
|
} |
76
|
|
|
|
77
|
|
|
return new Field( |
78
|
|
|
$fieldName, |
79
|
|
|
$datatypeName, |
80
|
|
|
$renderable, |
81
|
|
|
$validators, |
82
|
|
|
$extradata |
|
|
|
|
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public static function directiveToExtradata(DirectiveNode $directive): Extradata |
87
|
|
|
{ |
88
|
|
|
$metadataArgs = []; |
89
|
|
|
foreach ($directive->arguments as $arg) { |
90
|
|
|
$metadataArgs[] = new ExtradataParameter( |
91
|
|
|
$arg->name->value, |
92
|
|
|
// @phpstan-ignore-next-line |
93
|
|
|
$arg->value->value |
|
|
|
|
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
return new Extradata( |
97
|
|
|
$directive->name->value, |
98
|
|
|
$metadataArgs |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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