Skip to content

Commit afa93f7

Browse files
committed
add "append" setting, to merge the output of the mapper into the previous step's output,
update phpstan
1 parent 6f7d5af commit afa93f7

File tree

8 files changed

+23
-9
lines changed

8 files changed

+23
-9
lines changed

.github/workflows/phpstan-5.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PHPStan level 5
22
on: push
33
jobs:
4-
phpstan:
4+
phpstan5:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3

.github/workflows/phpstan-6.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PHPStan level 6
22
on: push
33
jobs:
4-
phpstan:
4+
phpstan6:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3

.github/workflows/phpstan-7.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PHPStan level 7
22
on: push
33
jobs:
4-
phpstan:
4+
phpstan7:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3

.github/workflows/phpstan-8.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PHPStan level 8
22
on: push
33
jobs:
4-
phpstan:
4+
phpstan8:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3

src/Builder/Transformer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class: new Node\Name\FullyQualified(
9797
new Node\Arg(
9898
value: new Node\Expr\Variable('line')
9999
),
100+
new Node\Arg(
101+
value: new Node\Expr\Variable('line')
102+
),
100103
]
101104
),
102105
),

src/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function getConfigTreeBuilder(): TreeBuilder
3333
->end()
3434
->children()
3535
->scalarNode('class')->end()
36+
->booleanNode('append')->end()
3637
->scalarNode('expression')->end()
3738
->arrayNode('expression_language')
3839
->scalarPrototype()->end()
@@ -47,6 +48,9 @@ public function getConfigTreeBuilder(): TreeBuilder
4748
->ifTrue(fn ($value) => !\is_array($value))
4849
->thenInvalid('Your configuration should be an array.')
4950
->end()
51+
->validate()
52+
->always(mutuallyExclusiveFields('append', 'list', 'collection', 'object'))
53+
->end()
5054
->validate()
5155
->always(mutuallyExclusiveFields('copy', 'constant', 'map', 'object', 'list', 'collection'))
5256
->end()

src/Factory/ArrayMapper.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Kiboko\Plugin\FastMap\Factory;
66

7+
use Kiboko\Component\FastMapConfig\ArrayAppendBuilder;
78
use Kiboko\Component\FastMapConfig\ArrayBuilder;
89
use Kiboko\Contract\Configurator;
910
use Kiboko\Plugin\FastMap;
@@ -17,7 +18,7 @@
1718
private Processor $processor;
1819
private ConfigurationInterface $configuration;
1920

20-
public function __construct(private ?ExpressionLanguage $interpreter, private array $additionalExpressionVariables = [])
21+
public function __construct(private ?ExpressionLanguage $interpreter, private array $additionalExpressionVariables = [], private bool $append = false)
2122
{
2223
$this->processor = new Processor();
2324
$this->configuration = new FastMap\Configuration\MapMapper();
@@ -54,9 +55,15 @@ public function validate(array $config): bool
5455

5556
public function compile(array $config): Repository\TransformerMapper
5657
{
57-
$mapper = new ArrayBuilder(
58-
interpreter: $this->interpreter,
59-
);
58+
if ($this->append) {
59+
$mapper = new ArrayAppendBuilder(
60+
interpreter: $this->interpreter,
61+
);
62+
} else {
63+
$mapper = new ArrayBuilder(
64+
interpreter: $this->interpreter,
65+
);
66+
}
6067

6168
$builder = new FastMap\Builder\Transformer(
6269
new FastMap\Builder\ArrayMapper($mapper)

src/Service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function compile(array $config): Factory\Repository\TransformerMapper
9191
return $conditionalFactory->compile($config['conditional']);
9292
}
9393
if (\array_key_exists('map', $config)) {
94-
$arrayFactory = new Factory\ArrayMapper($interpreter, $this->additionalExpressionVariables);
94+
$arrayFactory = new Factory\ArrayMapper($interpreter, $this->additionalExpressionVariables, isset($config['append']) && $config['append']);
9595

9696
return $arrayFactory->compile($config['map']);
9797
}

0 commit comments

Comments
 (0)