Skip to content

Commit 1365f64

Browse files
committed
Fix array configs
1 parent a11e9c0 commit 1365f64

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

resources/config.schema.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
"description": "A mapper configuration schema",
77
"additionalProperties": false,
88
"properties": {
9-
"type_error_message": {
10-
"type": "string",
11-
"minLength": 1,
12-
"description": "Custom error message on property type error"
13-
},
14-
"undefined_error_message": {
15-
"type": "string",
16-
"minLength": 1,
17-
"description": "Custom error message on property value missing error"
18-
},
199
"normalize_as_array": {
2010
"type": "boolean",
2111
"description": "Responsible for enabling or disabling the conversion to an associative array"
@@ -71,6 +61,16 @@
7161
"description": "Specific property type",
7262
"minLength": 1
7363
},
64+
"type_error_message": {
65+
"type": "string",
66+
"minLength": 1,
67+
"description": "Custom error message on property type error"
68+
},
69+
"undefined_error_message": {
70+
"type": "string",
71+
"minLength": 1,
72+
"description": "Custom error message on property value missing error"
73+
},
7474
"skip": {
7575
"description": "Rules according to which a property should be excluded during normalization",
7676
"anyOf": [

src/Mapping/Driver/ArrayConfigDriver.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@
1919
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
2020
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
2121

22+
/**
23+
* @phpstan-type PropertyConfigType array{
24+
* name?: non-empty-string,
25+
* type?: non-empty-string,
26+
* skip?: 'null'|'empty'|non-empty-string|list<'null'|'empty'|non-empty-string>,
27+
* type_error_message?: non-empty-string,
28+
* undefined_error_message?: non-empty-string,
29+
* ...
30+
* }
31+
*
32+
* @phpstan-type ClassDiscriminatorConfigType array{
33+
* field: non-empty-string,
34+
* map: array<non-empty-string, non-empty-string>,
35+
* otherwise?: non-empty-string,
36+
* }
37+
*
38+
* @phpstan-type ClassConfigType array{
39+
* normalize_as_array?: bool,
40+
* discriminator?: ClassDiscriminatorConfigType,
41+
* properties?: array<non-empty-string, non-empty-string|PropertyConfigType>
42+
* }
43+
*/
2244
abstract class ArrayConfigDriver extends LoadableDriver
2345
{
2446
private static ?bool $supportsSchemaValidation = null;
@@ -42,22 +64,7 @@ abstract protected function getConfiguration(\ReflectionClass $class): ?array;
4264
/**
4365
* @param \ReflectionClass<object> $class
4466
*
45-
* @return array{
46-
* normalize_as_array?: bool,
47-
* type_error_message?: non-empty-string,
48-
* undefined_error_message?: non-empty-string,
49-
* discriminator?: array{
50-
* field: non-empty-string,
51-
* map: array<non-empty-string, non-empty-string>,
52-
* otherwise?: non-empty-string,
53-
* },
54-
* properties?: array<non-empty-string, non-empty-string|array{
55-
* name?: non-empty-string,
56-
* type?: non-empty-string,
57-
* skip?: 'null'|'empty'|non-empty-string|list<'null'|'empty'|non-empty-string>,
58-
* ...
59-
* }>
60-
* }|null
67+
* @return ClassConfigType|null
6168
* @throws \InvalidArgumentException
6269
*/
6370
private function getConfigurationAndValidate(\ReflectionClass $class): ?array

0 commit comments

Comments
 (0)