Skip to content

Commit

Permalink
Fixed conditional mapper : elseif conditions were not correctly use
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Jan 11, 2024
1 parent 9710cc8 commit 0a93b8e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Builder/ArrayMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getNode(): Node
name: null,
subNodes: [
'implements' => [
new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class),
new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'),
],
'stmts' => [
new Node\Stmt\ClassMethod(
Expand Down
10 changes: 4 additions & 6 deletions src/Builder/ConditionalMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ private function compileConditions(array $alternatives): Node

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

return new Node\Expr\New_(
new Node\Stmt\Class_(
name: null,
subNodes: [
'implements' => [
new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class),
new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'),
],
'stmts' => [
new Node\Stmt\Property(
Expand Down Expand Up @@ -108,7 +106,7 @@ function ($alternative) {
],
'stmts' => [
new Node\Stmt\If_(
cond: $expression->expr,
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.'),
subNodes: [
'stmts' => [
new Node\Stmt\Return_(
Expand All @@ -132,11 +130,11 @@ function ($alternative) {
),
],
'elseifs' => array_map(
function ($alternative, $index) use ($expression) {
function ($alternative, $index) use ($parser) {
[$condition, $repository] = $alternative;

return new Node\Stmt\ElseIf_(
cond: $expression->expr,
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.'),
stmts: [
new Node\Stmt\Return_(
new Node\Expr\FuncCall(
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/ObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getNode(): Node
name: null,
subNodes: [
'implements' => [
new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class),
new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'),
],
'stmts' => [
new Node\Stmt\ClassMethod(
Expand Down
8 changes: 4 additions & 4 deletions src/Builder/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class: new Node\Stmt\Class_(
name: null,
subNodes: [
'implements' => [
new Node\Name\FullyQualified(\Kiboko\Contract\Pipeline\TransformerInterface::class),
new Node\Name\FullyQualified('Kiboko\\Contract\\Pipeline\\TransformerInterface'),
],
'stmts' => [
new Node\Stmt\ClassMethod(
Expand Down Expand Up @@ -74,7 +74,7 @@ class: new Node\Stmt\Class_(
expr: new Node\Expr\Yield_(
new Node\Expr\New_(
class: new Node\Name\FullyQualified(
\Kiboko\Component\Bucket\AcceptanceResultBucket::class
'Kiboko\\Component\\Bucket\\AcceptanceResultBucket'
),
args: [
new Node\Arg(
Expand Down Expand Up @@ -110,7 +110,7 @@ class: new Node\Name\FullyQualified(
new Node\Expr\Yield_(
new Node\Expr\New_(
class: new Node\Name\FullyQualified(
\Kiboko\Component\Bucket\AcceptanceResultBucket::class,
'Kiboko\\Component\\Bucket\\AcceptanceResultBucket',
),
args: [
new Node\Arg(
Expand All @@ -121,7 +121,7 @@ class: new Node\Name\FullyQualified(
)
),
],
'returnType' => new Node\Name\FullyQualified(\Generator::class),
'returnType' => new Node\Name\FullyQualified('Generator'),
],
),
],
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ArrayMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function normalize(array $config): array
{
try {
return $this->processor->processConfiguration($this->configuration, $config);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {

Check warning on line 39 in src/Factory/ArrayMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Catch_": --- Original +++ New @@ @@ { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { + } catch (Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } }

Check warning on line 39 in src/Factory/ArrayMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Catch_": --- Original +++ New @@ @@ { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { + } catch (Symfony\InvalidConfigurationException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } }
throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception);
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public function compile(array $config): Repository\TransformerMapper

try {
return new Repository\TransformerMapper($builder);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Factory/ConditionalMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function normalize(array $config): array
{
try {
return $this->processor->processConfiguration($this->configuration, $config);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception);
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public function compile(array $config): Repository\TransformerMapper
$alternative['condition'],
$mapperBuilder
);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
}
} elseif (\array_key_exists('object', $alternative)) {
Expand All @@ -113,13 +113,13 @@ className: $alternative['object']['class'],
$alternative['condition'],
$mapperBuilder
);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
}
} else {
throw new InvalidConfigurationException('Could not determine if the factory should build an array or an object transformer.');
}
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new InvalidConfigurationException($exception->getMessage(), 0, $exception);
}
}
Expand All @@ -128,7 +128,7 @@ className: $alternative['object']['class'],
return new Repository\TransformerMapper(
new FastMap\Builder\Transformer($builder),
);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function normalize(array $config): array
{
try {
return $this->processor->processConfiguration($this->configuration, $config);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {

Check warning on line 38 in src/Factory/ObjectMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Catch_": --- Original +++ New @@ @@ { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { + } catch (Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } }

Check warning on line 38 in src/Factory/ObjectMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Catch_": --- Original +++ New @@ @@ { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { + } catch (Symfony\InvalidConfigurationException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } }
throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception);
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ className: $config['class'],

try {
return new Repository\TransformerMapper($builder);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Repository/RepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait RepositoryTrait
/** @var string[] */
private array $packages;

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

Expand Down
8 changes: 4 additions & 4 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#[Configurator\Pipeline(
name: 'fastmap',
dependencies: [
'php-etl/mapping-contracts:0.4.*'
'php-etl/mapping-contracts:0.4.*',
],
steps: [
new Configurator\Pipeline\StepTransformer(null),
Expand Down Expand Up @@ -50,7 +50,7 @@ public function normalize(array $config): array
{
try {
return $this->processor->processConfiguration($this->configuration, $config);
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new InvalidConfigurationException($exception->getMessage(), 0, $exception);
}
}
Expand All @@ -61,7 +61,7 @@ public function validate(array $config): bool
$this->processor->processConfiguration($this->configuration, $config);

return true;
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) {
return false;
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function compile(array $config): Factory\Repository\TransformerMapper
return $objectFactory->compile($config['object']);
}
throw new InvalidConfigurationException('Could not determine if the factory should build an array or an object transformer.');
} catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) {
} catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) {
throw new InvalidConfigurationException($exception->getMessage(), 0, $exception);
}
}
Expand Down

0 comments on commit 0a93b8e

Please sign in to comment.