Skip to content

Commit 715b813

Browse files
authored
Merge pull request #29 from php-etl/fix/conditional-mapper
Fixed conditional mapper : elseif conditions were not correctly use
2 parents 9710cc8 + 51822e7 commit 715b813

17 files changed

+437
-44
lines changed

.github/workflows/infection.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323

2424
- name: Infection
2525
run: |
26-
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar
27-
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar.asc
26+
wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar
27+
wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar.asc
2828
chmod +x infection.phar
2929
./infection.phar
3030

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
"require-dev": {
2525
"phpunit/phpunit": "^10.0",
2626
"phpunit/php-invoker": "*",
27-
"php-etl/phpunit-extension": "0.7.*",
27+
"php-etl/phpunit-extension": "*",
2828
"friendsofphp/php-cs-fixer": "^3.38",
2929
"phpstan/phpstan": "^1.10",
3030
"rector/rector": "^0.15",
31-
"infection/infection": "^0.26"
31+
"infection/infection": "^0.26",
32+
"php-etl/bucket": "*"
3233
},
3334
"autoload": {
3435
"psr-4": {

composer.lock

+62-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
55
backupGlobals="true"
66
colors="false"
77
processIsolation="false"
@@ -16,17 +16,18 @@
1616
cacheDirectory=".phpunit.cache"
1717
backupStaticProperties="false"
1818
requireCoverageMetadata="false">
19-
<testsuites>
20-
<testsuite name="Functional tests">
21-
<directory>tests/functional/</directory>
22-
</testsuite>
23-
</testsuites>
24-
<coverage>
25-
<include>
26-
<directory suffix=".php">src</directory>
27-
</include>
28-
</coverage>
29-
<php>
30-
<ini name="allow_url_include" value="1" />
31-
</php>
19+
<testsuites>
20+
<testsuite name="Functional tests">
21+
<directory>tests/functional/</directory>
22+
</testsuite>
23+
</testsuites>
24+
<coverage/>
25+
<php>
26+
<ini name="allow_url_include" value="1"/>
27+
</php>
28+
<source>
29+
<include>
30+
<directory suffix=".php">src</directory>
31+
</include>
32+
</source>
3233
</phpunit>

src/Builder/ConditionalMapper.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ private function compileConditions(array $alternatives): Node
3535

3636
/** @var Builder $builder */
3737
[$condition, $builder] = array_shift($alternatives);
38-
/** @var Node\Stmt\Expression $expression */
39-
$expression = $parser->parse('<?php '.$this->interpreter->compile($condition, ['input', 'output']).';')[0];
4038

4139
return new Node\Expr\New_(
4240
new Node\Stmt\Class_(
@@ -108,7 +106,7 @@ function ($alternative) {
108106
],
109107
'stmts' => [
110108
new Node\Stmt\If_(
111-
cond: $expression->expr,
109+
cond: $parser->parse('<?php '.$this->interpreter->compile($condition, ['input', 'output']).';')[0]->expr ?? throw new \UnexpectedValueException('Expected parsing result to be an instance of Node\Expr.'),
112110
subNodes: [
113111
'stmts' => [
114112
new Node\Stmt\Return_(
@@ -132,11 +130,11 @@ function ($alternative) {
132130
),
133131
],
134132
'elseifs' => array_map(
135-
function ($alternative, $index) use ($expression) {
133+
function ($alternative, $index) use ($parser) {
136134
[$condition, $repository] = $alternative;
137135

138136
return new Node\Stmt\ElseIf_(
139-
cond: $expression->expr,
137+
cond: $parser->parse('<?php '.$this->interpreter->compile($condition, ['input', 'output']).';')[0]->expr ?? throw new \UnexpectedValueException('Expected parsing result to be an instance of Node\Expr.'),
140138
stmts: [
141139
new Node\Stmt\Return_(
142140
new Node\Expr\FuncCall(

src/Builder/Transformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class: new Node\Name\FullyQualified(
121121
)
122122
),
123123
],
124-
'returnType' => new Node\Name\FullyQualified(\Generator::class),
124+
'returnType' => new Node\Name\FullyQualified('Generator'),
125125
],
126126
),
127127
],

src/Factory/ArrayMapper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function normalize(array $config): array
3636
{
3737
try {
3838
return $this->processor->processConfiguration($this->configuration, $config);
39-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
39+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
4040
throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception);
4141
}
4242
}
@@ -73,7 +73,7 @@ public function compile(array $config): Repository\TransformerMapper
7373

7474
try {
7575
return new Repository\TransformerMapper($builder);
76-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
76+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
7777
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
7878
}
7979
}

src/Factory/ConditionalMapper.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function normalize(array $config): array
3939
{
4040
try {
4141
return $this->processor->processConfiguration($this->configuration, $config);
42-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
42+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
4343
throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception);
4444
}
4545
}
@@ -86,7 +86,7 @@ public function compile(array $config): Repository\TransformerMapper
8686
$alternative['condition'],
8787
$mapperBuilder
8888
);
89-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
89+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
9090
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
9191
}
9292
} elseif (\array_key_exists('object', $alternative)) {
@@ -113,13 +113,13 @@ className: $alternative['object']['class'],
113113
$alternative['condition'],
114114
$mapperBuilder
115115
);
116-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
116+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
117117
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
118118
}
119119
} else {
120120
throw new InvalidConfigurationException('Could not determine if the factory should build an array or an object transformer.');
121121
}
122-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
122+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
123123
throw new InvalidConfigurationException($exception->getMessage(), 0, $exception);
124124
}
125125
}
@@ -128,7 +128,7 @@ className: $alternative['object']['class'],
128128
return new Repository\TransformerMapper(
129129
new FastMap\Builder\Transformer($builder),
130130
);
131-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
131+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
132132
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
133133
}
134134
}

src/Factory/ObjectMapper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function normalize(array $config): array
3535
{
3636
try {
3737
return $this->processor->processConfiguration($this->configuration, $config);
38-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
38+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
3939
throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception);
4040
}
4141
}
@@ -67,7 +67,7 @@ className: $config['class'],
6767

6868
try {
6969
return new Repository\TransformerMapper($builder);
70-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
70+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
7171
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
7272
}
7373
}

src/Factory/Repository/RepositoryTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait RepositoryTrait
1515
/** @var string[] */
1616
private array $packages;
1717

18-
public function addFiles(FileInterface|DirectoryInterface ...$files): Configurator\RepositoryInterface
18+
public function addFiles(DirectoryInterface|FileInterface ...$files): Configurator\RepositoryInterface
1919
{
2020
array_push($this->files, ...$files);
2121

src/Service.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#[Configurator\Pipeline(
1515
name: 'fastmap',
1616
dependencies: [
17-
'php-etl/mapping-contracts:0.4.*'
17+
'php-etl/mapping-contracts:0.4.*',
1818
],
1919
steps: [
2020
new Configurator\Pipeline\StepTransformer(null),
@@ -50,7 +50,7 @@ public function normalize(array $config): array
5050
{
5151
try {
5252
return $this->processor->processConfiguration($this->configuration, $config);
53-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
53+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
5454
throw new InvalidConfigurationException($exception->getMessage(), 0, $exception);
5555
}
5656
}
@@ -61,7 +61,7 @@ public function validate(array $config): bool
6161
$this->processor->processConfiguration($this->configuration, $config);
6262

6363
return true;
64-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) {
64+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) {
6565
return false;
6666
}
6767
}
@@ -99,7 +99,7 @@ public function compile(array $config): Factory\Repository\TransformerMapper
9999
return $objectFactory->compile($config['object']);
100100
}
101101
throw new InvalidConfigurationException('Could not determine if the factory should build an array or an object transformer.');
102-
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
102+
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
103103
throw new InvalidConfigurationException($exception->getMessage(), 0, $exception);
104104
}
105105
}

0 commit comments

Comments
 (0)