Skip to content
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

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

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 @@ -11,7 +11,7 @@

final class ConditionalMapper implements Builder
{
private iterable $alternatives = [];

Check failure on line 14 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan8

Property Kiboko\Plugin\FastMap\Builder\ConditionalMapper::$alternatives type has no value type specified in iterable type iterable.

Check failure on line 14 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan6

Property Kiboko\Plugin\FastMap\Builder\ConditionalMapper::$alternatives type has no value type specified in iterable type iterable.

Check failure on line 14 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan7

Property Kiboko\Plugin\FastMap\Builder\ConditionalMapper::$alternatives type has no value type specified in iterable type iterable.

public function __construct(private readonly ExpressionLanguage $interpreter)
{
Expand All @@ -19,24 +19,22 @@

public function withAlternative(string $condition, Builder $builder): self
{
$this->alternatives[] = [$condition, $builder];

Check failure on line 22 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan8

Cannot access an offset on iterable.

Check failure on line 22 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan7

Cannot access an offset on iterable.

return $this;
}

public function getNode(): Node
{
return $this->compileConditions($this->alternatives);

Check failure on line 29 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter #1 $alternatives of method Kiboko\Plugin\FastMap\Builder\ConditionalMapper::compileConditions() expects array, iterable given.

Check failure on line 29 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter #1 $alternatives of method Kiboko\Plugin\FastMap\Builder\ConditionalMapper::compileConditions() expects array, iterable given.
}

private function compileConditions(array $alternatives): Node

Check failure on line 32 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan8

Method Kiboko\Plugin\FastMap\Builder\ConditionalMapper::compileConditions() has parameter $alternatives with no value type specified in iterable type array.

Check failure on line 32 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Plugin\FastMap\Builder\ConditionalMapper::compileConditions() has parameter $alternatives with no value type specified in iterable type array.

Check failure on line 32 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Plugin\FastMap\Builder\ConditionalMapper::compileConditions() has parameter $alternatives with no value type specified in iterable type array.
{
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, null);

/** @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 All @@ -45,19 +43,19 @@
'implements' => [
new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class),
],
'stmts' => [

Check warning on line 46 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, null); /** @var Builder $builder */ [$condition, $builder] = array_shift($alternatives); - return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\Property(flags: Node\Stmt\Class_::MODIFIER_PRIVATE, props: [new Node\Stmt\PropertyProperty(name: new Node\Name('mappers'))], type: new Node\Identifier('iterable')), new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { + return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { [$condition, $builder] = $alternative; return new Node\Expr\ArrayItem($builder->getNode()); }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) {
new Node\Stmt\Property(
flags: Node\Stmt\Class_::MODIFIER_PRIVATE,
props: [
new Node\Stmt\PropertyProperty(
name: new Node\Name('mappers'),

Check failure on line 51 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter $name of class PhpParser\Node\Stmt\PropertyProperty constructor expects PhpParser\Node\VarLikeIdentifier|string, PhpParser\Node\Name given.

Check failure on line 51 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan5

Parameter $name of class PhpParser\Node\Stmt\PropertyProperty constructor expects PhpParser\Node\VarLikeIdentifier|string, PhpParser\Node\Name given.

Check failure on line 51 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan6

Parameter $name of class PhpParser\Node\Stmt\PropertyProperty constructor expects PhpParser\Node\VarLikeIdentifier|string, PhpParser\Node\Name given.

Check failure on line 51 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter $name of class PhpParser\Node\Stmt\PropertyProperty constructor expects PhpParser\Node\VarLikeIdentifier|string, PhpParser\Node\Name given.
),
],
type: new Node\Identifier('iterable')
),
new Node\Stmt\ClassMethod(
name: '__construct',
subNodes: [

Check warning on line 58 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, null); /** @var Builder $builder */ [$condition, $builder] = array_shift($alternatives); - return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\Property(flags: Node\Stmt\Class_::MODIFIER_PRIVATE, props: [new Node\Stmt\PropertyProperty(name: new Node\Name('mappers'))], type: new Node\Identifier('iterable')), new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { + return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\Property(flags: Node\Stmt\Class_::MODIFIER_PRIVATE, props: [new Node\Stmt\PropertyProperty(name: new Node\Name('mappers'))], type: new Node\Identifier('iterable')), new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { [$condition, $builder] = $alternative; return new Node\Expr\ArrayItem($builder->getNode()); }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) {
'flags' => Node\Stmt\Class_::MODIFIER_PUBLIC,
'stmts' => [
new Node\Stmt\Expression(
Expand All @@ -69,20 +67,20 @@
new Node\Expr\Array_(
items: [
new Node\Expr\ArrayItem(
$builder->getNode()

Check failure on line 70 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter #1 $value of class PhpParser\Node\Expr\ArrayItem constructor expects PhpParser\Node\Expr, PhpParser\Node given.

Check failure on line 70 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan5

Parameter #1 $value of class PhpParser\Node\Expr\ArrayItem constructor expects PhpParser\Node\Expr, PhpParser\Node given.

Check failure on line 70 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan6

Parameter #1 $value of class PhpParser\Node\Expr\ArrayItem constructor expects PhpParser\Node\Expr, PhpParser\Node given.

Check failure on line 70 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter #1 $value of class PhpParser\Node\Expr\ArrayItem constructor expects PhpParser\Node\Expr, PhpParser\Node given.
),
...array_map(
function ($alternative) {
[$condition, $builder] = $alternative;

return new Node\Expr\ArrayItem(

Check warning on line 76 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "NewObject": --- Original +++ New @@ @@ [$condition, $builder] = array_shift($alternatives); return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\Property(flags: Node\Stmt\Class_::MODIFIER_PRIVATE, props: [new Node\Stmt\PropertyProperty(name: new Node\Name('mappers'))], type: new Node\Identifier('iterable')), new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { [$condition, $builder] = $alternative; - return new Node\Expr\ArrayItem($builder->getNode()); + new Node\Expr\ArrayItem($builder->getNode()); + return null; }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { [$condition, $repository] = $alternative; return new Node\Stmt\ElseIf_(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(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber($index + 1)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))]);
$builder->getNode()
);
},
$alternatives
),
],
attributes: [

Check warning on line 83 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\Property(flags: Node\Stmt\Class_::MODIFIER_PRIVATE, props: [new Node\Stmt\PropertyProperty(name: new Node\Name('mappers'))], type: new Node\Identifier('iterable')), new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { [$condition, $builder] = $alternative; return new Node\Expr\ArrayItem($builder->getNode()); - }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { + }, $alternatives)], attributes: [])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { [$condition, $repository] = $alternative; return new Node\Stmt\ElseIf_(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(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber($index + 1)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))]); }, $alternatives, array_keys($alternatives)), 'else' => new Node\Stmt\Else_(stmts: [new Node\Stmt\Return_(new Node\Expr\Variable('input'))])])]])]])); } }
'kind' => Node\Expr\Array_::KIND_SHORT,
],
),
Expand All @@ -93,7 +91,7 @@
),
new Node\Stmt\ClassMethod(
name: '__invoke',
subNodes: [

Check warning on line 94 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\Property(flags: Node\Stmt\Class_::MODIFIER_PRIVATE, props: [new Node\Stmt\PropertyProperty(name: new Node\Name('mappers'))], type: new Node\Identifier('iterable')), new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { [$condition, $builder] = $alternative; return new Node\Expr\ArrayItem($builder->getNode()); - }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { + }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { [$condition, $repository] = $alternative; return new Node\Stmt\ElseIf_(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(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber($index + 1)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))]); }, $alternatives, array_keys($alternatives)), 'else' => new Node\Stmt\Else_(stmts: [new Node\Stmt\Return_(new Node\Expr\Variable('input'))])])]])]])); } }
'flags' => Node\Stmt\Class_::MODIFIER_PUBLIC,
'params' => [
new Node\Param(
Expand All @@ -108,7 +106,7 @@
],
'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 @@ -131,13 +129,13 @@
),
),
],
'elseifs' => array_map(

Check warning on line 132 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItem": --- Original +++ New @@ @@ return new Node\Expr\New_(new Node\Stmt\Class_(name: null, subNodes: ['implements' => [new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class)], 'stmts' => [new Node\Stmt\Property(flags: Node\Stmt\Class_::MODIFIER_PRIVATE, props: [new Node\Stmt\PropertyProperty(name: new Node\Name('mappers'))], type: new Node\Identifier('iterable')), new Node\Stmt\ClassMethod(name: '__construct', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), new Node\Identifier('mappers')), new Node\Expr\Array_(items: [new Node\Expr\ArrayItem($builder->getNode()), ...array_map(function ($alternative) { [$condition, $builder] = $alternative; return new Node\Expr\ArrayItem($builder->getNode()); - }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { + }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' > array_map(function ($alternative, $index) use($parser) { [$condition, $repository] = $alternative; return new Node\Stmt\ElseIf_(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(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber($index + 1)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))]); }, $alternatives, array_keys($alternatives)), 'else' => new Node\Stmt\Else_(stmts: [new Node\Stmt\Return_(new Node\Expr\Variable('input'))])])]])]])); } }
function ($alternative, $index) use ($expression) {
function ($alternative, $index) use ($parser) {
[$condition, $repository] = $alternative;

return new Node\Stmt\ElseIf_(

Check warning on line 136 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "NewObject": --- Original +++ New @@ @@ return new Node\Expr\ArrayItem($builder->getNode()); }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { [$condition, $repository] = $alternative; - return new Node\Stmt\ElseIf_(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(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber($index + 1)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))]); + new Node\Stmt\ElseIf_(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(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber($index + 1)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))]); + return null; }, $alternatives, array_keys($alternatives)), 'else' => new Node\Stmt\Else_(stmts: [new Node\Stmt\Return_(new Node\Expr\Variable('input'))])])]])]])); } }
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: [

Check warning on line 138 in src/Builder/ConditionalMapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ return new Node\Expr\ArrayItem($builder->getNode()); }, $alternatives)], attributes: ['kind' => Node\Expr\Array_::KIND_SHORT])))]]), new Node\Stmt\ClassMethod(name: '__invoke', subNodes: ['flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [new Node\Param(var: new Node\Expr\Variable('input')), new Node\Param(var: new Node\Expr\Variable('output'), default: new Node\Expr\ConstFetch(new Node\Name('null')))], 'stmts' => [new Node\Stmt\If_(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_(new Node\Expr\FuncCall(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber(0)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))], 'elseifs' => array_map(function ($alternative, $index) use($parser) { [$condition, $repository] = $alternative; - return new Node\Stmt\ElseIf_(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(new Node\Expr\ArrayDimFetch(var: new Node\Expr\PropertyFetch(var: new Node\Expr\Variable('this'), name: new Node\Identifier('mappers')), dim: new Node\Scalar\LNumber($index + 1)), args: [new Node\Arg(new Node\Expr\Variable('input')), new Node\Arg(new Node\Expr\Variable('output'))]))]); + return new Node\Stmt\ElseIf_(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: []); }, $alternatives, array_keys($alternatives)), 'else' => new Node\Stmt\Else_(stmts: [new Node\Stmt\Return_(new Node\Expr\Variable('input'))])])]])]])); } }
new Node\Stmt\Return_(
new Node\Expr\FuncCall(
new Node\Expr\ArrayDimFetch(
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 @@
)
),
],
'returnType' => new Node\Name\FullyQualified(\Generator::class),
'returnType' => new Node\Name\FullyQualified('Generator'),
],
),
],
Expand All @@ -129,7 +129,7 @@
),
args: [
new Node\Arg(
$this->mapper instanceof Builder ? $this->mapper->getNode() : $this->mapper,

Check failure on line 132 in src/Builder/Transformer.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter #1 $value of class PhpParser\Node\Arg constructor expects PhpParser\Node\Expr, PhpParser\Node given.

Check failure on line 132 in src/Builder/Transformer.php

View workflow job for this annotation

GitHub Actions / phpstan5

Parameter #1 $value of class PhpParser\Node\Arg constructor expects PhpParser\Node\Expr, PhpParser\Node given.

Check failure on line 132 in src/Builder/Transformer.php

View workflow job for this annotation

GitHub Actions / phpstan6

Parameter #1 $value of class PhpParser\Node\Arg constructor expects PhpParser\Node\Expr, PhpParser\Node given.

Check failure on line 132 in src/Builder/Transformer.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter #1 $value of class PhpParser\Node\Arg constructor expects PhpParser\Node\Expr, PhpParser\Node given.
),
],
);
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
Loading