Skip to content

Fixed conditional mapper : elseif conditions were not correctly use #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/infection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:

- name: Infection
run: |
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar.asc
wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar
wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar.asc
chmod +x infection.phar
./infection.phar

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
"require-dev": {
"phpunit/phpunit": "^10.0",
"phpunit/php-invoker": "*",
"php-etl/phpunit-extension": "0.7.*",
"php-etl/phpunit-extension": "*",
"friendsofphp/php-cs-fixer": "^3.38",
"phpstan/phpstan": "^1.10",
"rector/rector": "^0.15",
"infection/infection": "^0.26"
"infection/infection": "^0.26",
"php-etl/bucket": "*"
},
"autoload": {
"psr-4": {
Expand Down
68 changes: 62 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
backupGlobals="true"
colors="false"
processIsolation="false"
Expand All @@ -16,17 +16,18 @@
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false">
<testsuites>
<testsuite name="Functional tests">
<directory>tests/functional/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<ini name="allow_url_include" value="1" />
</php>
<testsuites>
<testsuite name="Functional tests">
<directory>tests/functional/</directory>
</testsuite>
</testsuites>
<coverage/>
<php>
<ini name="allow_url_include" value="1"/>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
8 changes: 3 additions & 5 deletions src/Builder/ConditionalMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ 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_(
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/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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) {
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
Loading