Skip to content

Commit 90ba0b9

Browse files
committed
Changed the parameters config + updated tests
1 parent c1b62dd commit 90ba0b9

File tree

7 files changed

+102
-56
lines changed

7 files changed

+102
-56
lines changed

src/Configuration/Parameters.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,23 @@ public function getConfigTreeBuilder(): TreeBuilder
2222
})
2323
->thenUnset()
2424
->end()
25-
->useAttributeAsKey('key')
2625
->arrayPrototype()
2726
->children()
27+
->variableNode('key')
28+
->isRequired()
29+
->validate()
30+
->ifTrue(isExpression())
31+
->then(asExpression())
32+
->end()
33+
->validate()
34+
->ifTrue(function ($value) {
35+
return !is_string($value) && !is_int($value);
36+
})
37+
->thenInvalid('The parameter\'s key must be of a string or an integer.')
38+
->end()
39+
->end()
2840
->scalarNode('value')
41+
->isRequired()
2942
->validate()
3043
->ifTrue(isExpression())
3144
->then(asExpression())

src/Factory/Extractor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ public function compile(array $config): SQL\Factory\Repository\Extractor
5454
);
5555

5656
if (array_key_exists('parameters', $config)) {
57-
foreach ($config["parameters"] as $key => $parameter) {
57+
foreach ($config["parameters"] as $parameter) {
5858
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
5959
'integer' => $extractor->addIntegerParam(
60-
$key,
60+
$parameter["key"],
6161
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6262
),
6363
'boolean' => $extractor->addBooleanParam(
64-
$key,
64+
$parameter["key"],
6565
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6666
),
6767
default => $extractor->addStringParam(
68-
$key,
68+
$parameter["key"],
6969
compileValueWhenExpression($this->interpreter, $parameter["value"]),
7070
),
7171
};

src/Factory/Loader.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ public function compile(array $config): SQL\Factory\Repository\Loader
5656
);
5757

5858
if (array_key_exists('parameters', $config)) {
59-
foreach ($config["parameters"] as $key => $parameter) {
59+
foreach ($config["parameters"] as $parameter) {
6060
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
6161
'integer' => $loader->addIntegerParam(
62-
$key,
62+
$parameter["key"],
6363
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6464
),
6565
'boolean' => $loader->addBooleanParam(
66-
$key,
66+
$parameter["key"],
6767
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6868
),
6969
default => $loader->addStringParam(
70-
$key,
70+
$parameter["key"],
7171
compileValueWhenExpression($this->interpreter, $parameter["value"]),
7272
),
7373
};
@@ -82,18 +82,18 @@ public function compile(array $config): SQL\Factory\Repository\Loader
8282
);
8383

8484
if (array_key_exists('parameters', $alternative)) {
85-
foreach ($alternative["parameters"] as $key => $parameter) {
85+
foreach ($alternative["parameters"] as $parameter) {
8686
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
8787
'integer' => $alternativeLoaderBuilder->addIntegerParam(
88-
$key,
88+
$parameter["key"],
8989
compileValueWhenExpression($this->interpreter, $parameter["value"]),
9090
),
9191
'boolean' => $alternativeLoaderBuilder->addBooleanParam(
92-
$key,
92+
$parameter["key"],
9393
compileValueWhenExpression($this->interpreter, $parameter["value"]),
9494
),
9595
default => $alternativeLoaderBuilder->addStringParam(
96-
$key,
96+
$parameter["key"],
9797
compileValueWhenExpression($this->interpreter, $parameter["value"]),
9898
),
9999
};

src/Factory/Lookup.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ public function compile(array $config): SQL\Factory\Repository\Lookup
8080
$lookup = new SQL\Builder\Lookup($alternativeBuilder);
8181

8282
if (array_key_exists('parameters', $config)) {
83-
foreach ($config["parameters"] as $key => $parameter) {
83+
foreach ($config["parameters"] as $parameter) {
8484
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
8585
'integer' => $alternativeBuilder->addIntegerParam(
86-
$key,
86+
$parameter["key"],
8787
compileValueWhenExpression($this->interpreter, $parameter["value"]),
8888
),
8989
'boolean' => $alternativeBuilder->addBooleanParam(
90-
$key,
90+
$parameter["key"],
9191
compileValueWhenExpression($this->interpreter, $parameter["value"]),
9292
),
9393
default => $alternativeBuilder->addStringParam(
94-
$key,
94+
$parameter["key"],
9595
compileValueWhenExpression($this->interpreter, $parameter["value"]),
9696
),
9797
};
@@ -108,18 +108,18 @@ public function compile(array $config): SQL\Factory\Repository\Lookup
108108
);
109109

110110
if (array_key_exists('parameters', $alternative)) {
111-
foreach ($config["parameters"] as $key => $parameter) {
111+
foreach ($config["parameters"] as $parameter) {
112112
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
113113
'integer' => $alternativeBuilder->addIntegerParam(
114-
$key,
114+
$parameter["key"],
115115
compileValueWhenExpression($this->interpreter, $parameter["value"]),
116116
),
117117
'boolean' => $alternativeBuilder->addBooleanParam(
118-
$key,
118+
$parameter["key"],
119119
compileValueWhenExpression($this->interpreter, $parameter["value"]),
120120
),
121121
default => $alternativeBuilder->addStringParam(
122-
$key,
122+
$parameter["key"],
123123
compileValueWhenExpression($this->interpreter, $parameter["value"]),
124124
),
125125
};

tests/functional/Builder/ExtractorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public function testNormalizingConfiguration(): void
4141
[
4242
'query' => 'SELECT * FROM foo WHERE value IS NOT NULL AND id <= :identifier',
4343
'parameters' => [
44-
'identifier' => [
44+
[
45+
'key' => 'identifier',
4546
'value' => new Expression('3'),
4647
]
4748
],
@@ -50,7 +51,8 @@ public function testNormalizingConfiguration(): void
5051
[
5152
'query' => 'SELECT * FROM foo WHERE value IS NOT NULL AND id <= :identifier',
5253
'parameters' => [
53-
'identifier' => [
54+
[
55+
'key' => 'identifier',
5456
'value' => '@=3',
5557
]
5658
],

tests/functional/Builder/LoaderTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public function testNormalizingConfiguration(): void
4141
[
4242
'query' => 'INSERT INTO foo WHERE value IS NOT NULL AND id <= :identifier',
4343
'parameters' => [
44-
'identifier' => [
44+
[
45+
'key' => 'identifier',
4546
'value' => new Expression('3'),
4647
],
4748
],
@@ -50,9 +51,10 @@ public function testNormalizingConfiguration(): void
5051
[
5152
'query' => 'INSERT INTO foo WHERE value IS NOT NULL AND id <= :identifier',
5253
'parameters' => [
53-
'identifier' => [
54+
[
55+
'key' => 'identifier',
5456
'value' => '@=3',
55-
],
57+
]
5658
],
5759
],
5860
]),

0 commit comments

Comments
 (0)