Skip to content

Commit 0c2db67

Browse files
committed
Ran php-cs-fixer + fixed some phpstan errors
1 parent c7d8936 commit 0c2db67

21 files changed

+140
-144
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

src/Builder/ArrayMapper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap\Builder;
46

7+
58
use Kiboko\Component\FastMapConfig\ArrayBuilderInterface;
69
use PhpParser\Builder;
710
use PhpParser\Node;

src/Builder/ConditionalMapper.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap\Builder;
46

5-
use Kiboko\Contract\Configurator\RepositoryInterface;
67
use PhpParser\Builder;
78
use PhpParser\Node;
89
use PhpParser\ParserFactory;
@@ -70,15 +71,15 @@ private function compileConditions(array $alternatives): Node
7071
$builder->getNode()
7172
),
7273
...array_map(
73-
function ($alternative) use ($parser) {
74+
function ($alternative) {
7475
[$condition, $builder] = $alternative;
7576

7677
return new Node\Expr\ArrayItem(
7778
$builder->getNode()
7879
);
7980
},
8081
$alternatives
81-
)
82+
),
8283
],
8384
attributes: [
8485
'kind' => Node\Expr\Array_::KIND_SHORT,
@@ -106,7 +107,7 @@ function ($alternative) use ($parser) {
106107
],
107108
'stmts' => [
108109
new Node\Stmt\If_(
109-
cond: $parser->parse('<?php ' . $this->interpreter->compile($condition, ['input', 'output']) . ';')[0]->expr,
110+
cond: $parser->parse('<?php '.$this->interpreter->compile($condition, ['input', 'output']).';')[0]->expr,
110111
subNodes: [
111112
'stmts' => [
112113
new Node\Stmt\Return_(
@@ -134,7 +135,7 @@ function ($alternative, $index) use ($parser) {
134135
[$condition, $repository] = $alternative;
135136

136137
return new Node\Stmt\ElseIf_(
137-
cond: $parser->parse('<?php ' . $this->interpreter->compile($condition, ['input', 'output']) . ';')[0]->expr,
138+
cond: $parser->parse('<?php '.$this->interpreter->compile($condition, ['input', 'output']).';')[0]->expr,
138139
stmts: [
139140
new Node\Stmt\Return_(
140141
new Node\Expr\FuncCall(
@@ -165,9 +166,9 @@ function ($alternative, $index) use ($parser) {
165166
stmts: [
166167
new Node\Stmt\Return_(
167168
new Node\Expr\Variable('input'),
168-
)
169+
),
169170
]
170-
)
171+
),
171172
],
172173
),
173174
],

src/Builder/ObjectMapper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap\Builder;
46

7+
use Kiboko\Component\FastMap\Mapping\Composite\ObjectAppendMapper;
58
use Kiboko\Component\FastMapConfig\ObjectBuilderInterface;
69
use PhpParser\Builder;
710
use PhpParser\Node;

src/Builder/Transformer.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap\Builder;
46

@@ -9,35 +11,21 @@
911

1012
final class Transformer implements StepBuilderInterface
1113
{
12-
private ?Node\Expr $logger;
13-
private ?Node\Expr $rejection;
14-
private ?Node\Expr $state;
15-
1614
public function __construct(private Builder|Node $mapper)
17-
{
18-
$this->logger = null;
19-
$this->rejection = null;
20-
$this->state = null;
21-
}
15+
{}
2216

2317
public function withLogger(Node\Expr $logger): self
2418
{
25-
$this->logger = $logger;
26-
2719
return $this;
2820
}
2921

3022
public function withRejection(Node\Expr $rejection): self
3123
{
32-
$this->rejection = $rejection;
33-
3424
return $this;
3525
}
3626

3727
public function withState(Node\Expr $state): self
3828
{
39-
$this->state = $state;
40-
4129
return $this;
4230
}
4331

@@ -107,7 +95,7 @@ class: new Node\Name\FullyQualified(
10795
args: [
10896
new Node\Arg(
10997
value: new Node\Expr\Variable('line')
110-
)
98+
),
11199
]
112100
),
113101
),

src/Configuration.php

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap;
46

7+
use function Kiboko\Component\SatelliteToolbox\Configuration\mutuallyDependentFields;
8+
use function Kiboko\Component\SatelliteToolbox\Configuration\mutuallyExclusiveFields;
59
use Kiboko\Contract\Configurator\PluginConfigurationInterface;
610
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
711
use Symfony\Component\Config\Definition\NodeInterface;
812
use Symfony\Component\ExpressionLanguage\Expression;
9-
use function Kiboko\Component\SatelliteToolbox\Configuration\mutuallyExclusiveFields;
10-
use function Kiboko\Component\SatelliteToolbox\Configuration\mutuallyDependentFields;
1113

1214
final class Configuration implements PluginConfigurationInterface
1315
{
1416
public function __construct(
1517
private string $name = 'fastmap'
1618
) {}
1719

18-
public function getConfigTreeBuilder()
20+
public function getConfigTreeBuilder(): TreeBuilder
1921
{
2022
$builder = new TreeBuilder($this->name);
2123

24+
/* @phpstan-ignore-next-line */
2225
$builder->getRootNode()
2326
->validate()
2427
->always($this->cleanupFields('conditional', 'expression_language', 'map', 'list', 'object', 'collection'))
@@ -39,9 +42,7 @@ public function getConfigTreeBuilder()
3942
->append($this->getCollectionTreeBuilder()->getRootNode())
4043
->end()
4144
->validate()
42-
->ifTrue(function ($value) {
43-
return !is_array($value);
44-
})
45+
->ifTrue(fn ($value) => !\is_array($value))
4546
->thenInvalid('Your configuration should be an array.')
4647
->end()
4748
->validate()
@@ -81,8 +82,7 @@ public function getConfigTreeBuilder()
8182

8283
private function evaluateMap($children)
8384
{
84-
$node = $this->getMapNode();
85-
return $node->finalize($children);
85+
return $this->getMapNode()->finalize($children);
8686
}
8787

8888
private function evaluateList($children)
@@ -124,11 +124,11 @@ private function cleanupFields(string ...$fieldNames): \Closure
124124
{
125125
return function (array $value) use ($fieldNames) {
126126
foreach ($fieldNames as $fieldName) {
127-
if (!array_key_exists($fieldName, $value)) {
127+
if (!\array_key_exists($fieldName, $value)) {
128128
continue;
129129
}
130130

131-
if (!is_array($value[$fieldName]) || count($value[$fieldName]) <= 0) {
131+
if (!\is_array($value[$fieldName]) || \count($value[$fieldName]) <= 0) {
132132
unset($value[$fieldName]);
133133
}
134134
}
@@ -141,6 +141,7 @@ private function getChildTreeBuilder(string $name): TreeBuilder
141141
{
142142
$builder = new TreeBuilder($name);
143143

144+
/* @phpstan-ignore-next-line */
144145
$builder->getRootNode()
145146
->arrayPrototype()
146147
->validate()
@@ -202,59 +203,43 @@ private function getChildTreeBuilder(string $name): TreeBuilder
202203
->scalarNode('constant')->end()
203204
->variableNode('map')
204205
->validate()
205-
->ifTrue(function ($element) {
206-
return !is_array($element);
207-
})
206+
->ifTrue(fn ($element) => !\is_array($element))
208207
->thenInvalid('The children element must be an array.')
209208
->end()
210209
->validate()
211210
->ifArray()
212-
->then(function (array $children) {
213-
return $this->evaluateMap($children);
214-
})
211+
->then(fn (array $children) => $this->evaluateMap($children))
215212
->end()
216213
->end()
217214
->variableNode('list')
218215
->validate()
219-
->ifTrue(function ($element) {
220-
return !is_array($element);
221-
})
216+
->ifTrue(fn ($element) => !\is_array($element))
222217
->thenInvalid('The children element must be an array.')
223218
->end()
224219
->validate()
225220
->ifArray()
226-
->then(function (array $children) {
227-
return $this->evaluateList($children);
228-
})
221+
->then(fn (array $children) => $this->evaluateList($children))
229222
->end()
230223
->end()
231224
->scalarNode('class')->end()
232225
->variableNode('object')
233226
->validate()
234-
->ifTrue(function ($element) {
235-
return !is_array($element);
236-
})
227+
->ifTrue(fn ($element) => !\is_array($element))
237228
->thenInvalid('The children element must be an array.')
238229
->end()
239230
->validate()
240231
->ifArray()
241-
->then(function (array $children) {
242-
return $this->evaluateObject($children);
243-
})
232+
->then(fn (array $children) => $this->evaluateObject($children))
244233
->end()
245234
->end()
246235
->variableNode('collection')
247236
->validate()
248-
->ifTrue(function ($element) {
249-
return !is_array($element);
250-
})
237+
->ifTrue(fn ($element) => !\is_array($element))
251238
->thenInvalid('The children element must be an array.')
252239
->end()
253240
->validate()
254241
->ifArray()
255-
->then(function (array $children) {
256-
return $this->evaluateCollection($children);
257-
})
242+
->then(fn (array $children) => $this->evaluateCollection($children))
258243
->end()
259244
->end()
260245
->end()
@@ -268,6 +253,7 @@ public function getConditionalTreeBuilder(): TreeBuilder
268253
{
269254
$builder = new TreeBuilder('conditional');
270255

256+
/* @phpstan-ignore-next-line */
271257
$builder->getRootNode()
272258
->arrayPrototype()
273259
->validate()
@@ -284,7 +270,8 @@ public function getConditionalTreeBuilder(): TreeBuilder
284270
->append($this->getObjectTreeBuilder()->getRootNode())
285271
->append($this->getCollectionTreeBuilder()->getRootNode())
286272
->end()
287-
->end();
273+
->end()
274+
;
288275

289276
return $builder;
290277
}

src/Configuration/CollectionMapper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap\Configuration;
46

57
use Kiboko\Plugin\FastMap\Configuration;
8+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
69
use Symfony\Component\Config\Definition\ConfigurationInterface;
710

811
final class CollectionMapper implements ConfigurationInterface
912
{
10-
public function getConfigTreeBuilder()
13+
public function getConfigTreeBuilder(): TreeBuilder
1114
{
1215
return (new Configuration())->getCollectionTreeBuilder();
1316
}

src/Configuration/ConditionalMapper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap\Configuration;
46

57
use Kiboko\Plugin\FastMap\Configuration;
8+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
69
use Symfony\Component\Config\Definition\ConfigurationInterface;
710

811
final class ConditionalMapper implements ConfigurationInterface
912
{
10-
public function getConfigTreeBuilder()
13+
public function getConfigTreeBuilder(): TreeBuilder
1114
{
1215
return (new Configuration())->getConditionalTreeBuilder();
1316
}

src/Configuration/ConfigurationApplier.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Kiboko\Plugin\FastMap\Configuration;
46

@@ -14,42 +16,38 @@ public function __construct(private array $additionalExpressionVariables = [])
1416
public function __invoke(CompositeBuilderInterface $mapper, iterable $fields): void
1517
{
1618
foreach ($fields as $field) {
17-
if (array_key_exists('object', $field)) {
19+
if (\array_key_exists('object', $field)) {
1820
$this(
1921
$mapper->object($field['field'], $field['class'], $field['expression'])->children(),
2022
$field['object'],
2123
);
22-
} elseif (array_key_exists('collection', $field)) {
24+
} elseif (\array_key_exists('collection', $field)) {
2325
$this(
2426
$mapper->collection($field['field'], $field['class'], $field['expression'])->children(),
2527
$field['collection'],
2628
);
27-
} elseif (array_key_exists('map', $field)) {
29+
} elseif (\array_key_exists('map', $field)) {
2830
$this(
2931
$mapper->map($field['field'], $field['expression'])->children(),
3032
$field['map'],
3133
);
32-
} elseif (array_key_exists('list', $field)) {
34+
} elseif (\array_key_exists('list', $field)) {
3335
$this(
3436
$mapper->list($field['field'], $field['expression'])->children(),
3537
$field['list'],
3638
);
37-
} elseif (array_key_exists('copy', $field)) {
39+
} elseif (\array_key_exists('copy', $field)) {
3840
$mapper->copy($field['field'], $field['copy']);
39-
} elseif (array_key_exists('expression', $field)) { // Should be at the end in order to let the complex fields use the "expression" property
41+
} elseif (\array_key_exists('expression', $field)) { // Should be at the end in order to let the complex fields use the "expression" property
4042
$mapper->expression(
4143
$field['field'],
4244
$field['expression'],
4345
array_merge([], $field['variables'] ?? [], $this->additionalExpressionVariables),
4446
);
45-
} elseif (array_key_exists('constant', $field)) {
47+
} elseif (\array_key_exists('constant', $field)) {
4648
$mapper->constant($field['field'], $field['constant']);
4749
} else {
48-
throw new InvalidConfigurationException(sprintf(
49-
'No field type is suitable for the field %s, configuration was %s.',
50-
$field['field'],
51-
\json_encode($field),
52-
));
50+
throw new InvalidConfigurationException(sprintf('No field type is suitable for the field %s, configuration was %s.', $field['field'], json_encode($field)));
5351
}
5452
}
5553
}

0 commit comments

Comments
 (0)