Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
run: |
wget -q https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer
chmod a+x php-cs-fixer
PHP_CS_FIXER_IGNORE_ENV=true ./php-cs-fixer fix src --dry-run
./php-cs-fixer fix src --dry-run
phpstan:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"php-etl/phpspec-extension": "*"
},
"autoload": {
"files": ["src/Compiler/Builder/PropertyPathBuilder.php"],
"psr-4": {
"Kiboko\\Component\\FastMap\\": "src/"
}
Expand Down
886 changes: 437 additions & 449 deletions composer.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 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.1/phpunit.xsd"
backupGlobals="true"
colors="false"
processIsolation="false"
Expand All @@ -21,12 +21,13 @@
<directory>functional/</directory>
</testsuite>
</testsuites>
<coverage>
<coverage/>
<php>
<ini name="allow_url_include" value="1"/>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<ini name="allow_url_include" value="1" />
</php>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
public function __construct(
private PropertyPath $propertyPath,
private Node\Expr $pathNode
) {
}
) {}

public function getNode(): Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public function __construct(
private TypeMetadataInterface $metadata,
private PropertyPath $propertyPath,
private Node\Expr $pathNode
) {
}
) {}

public function getNode(): Node
{
Expand Down
4 changes: 1 addition & 3 deletions src/Compiler/Builder/ConstantValueBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

final readonly class ConstantValueBuilder implements Builder
{
public function __construct(private mixed $value)
{
}
public function __construct(private mixed $value) {}

public function getNode(): Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
/**
* @param string[] $variables
*/
public function __construct(private ExpressionLanguage $interpreter, private Expression $expression, private array $variables = [])
{
}
public function __construct(private ExpressionLanguage $interpreter, private Expression $expression, private array $variables = []) {}

public function getNode(): Node\Expr
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public function __construct(
private PropertyPath $propertyPath,
private Node\Expr $pathNode,
private ClassTypeMetadata $metadata
) {
}
) {}

public function getNode(): Node
{
Expand Down
56 changes: 5 additions & 51 deletions src/Compiler/Builder/PropertyPathBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,9 @@

namespace Kiboko\Component\FastMap\Compiler\Builder;

use PhpParser\Builder;
use PhpParser\Node;
use Symfony\Component\PropertyAccess\PropertyPathInterface;
trigger_deprecation('php-etl/fast-map', '0.5', 'The "%s" class is deprecated, use "%s" instead.', 'Kiboko\\Component\\FastMap\\Compiler\\Builder\\PropertyPathBuilder', \Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder::class);

final readonly class PropertyPathBuilder implements Builder
{
public function __construct(
private \IteratorAggregate&PropertyPathInterface $propertyPath,
private Node\Expr $pathNode,
private ?int $limit = null
) {
}

public function getNode(): Node\Expr
{
$pathNode = $this->pathNode;

$iterator = $this->propertyPath->getIterator();
if ($this->limit < 0) {
$iterator = new \LimitIterator($iterator, 0, iterator_count($iterator) + $this->limit);
} elseif (null !== $this->limit) {
$iterator = new \LimitIterator($iterator, 0, $this->limit);
}

try {
foreach ($iterator as $index => $child) {
if ($this->propertyPath->isIndex($index)) {
if (\is_int($child)) {
$pathNode = new Node\Expr\ArrayDimFetch(
$pathNode,
new Node\Scalar\LNumber($child)
);
} else {
$pathNode = new Node\Expr\ArrayDimFetch(
$pathNode,
new Node\Scalar\String_($child)
);
}
} elseif ($this->propertyPath->isProperty($index)) {
$pathNode = new Node\Expr\PropertyFetch(
$pathNode,
new Node\Name($child)
);
}
}
} catch (\OutOfBoundsException) {
// Case when the iterator is empty
}

return $pathNode;
}
}
/*
* @deprecated since FastMap 0.5, use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder instead.
*/
class_alias(\Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder::class, 'Kiboko\\Component\\FastMap\\Compiler\\Builder\\PropertyPathBuilder');
4 changes: 2 additions & 2 deletions src/Compiler/Builder/RequiredValuePreconditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kiboko\Component\FastMap\Compiler\Builder;

use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder;
use PhpParser\Builder;
use PhpParser\Node;
use Symfony\Component\PropertyAccess\PropertyPath;
Expand All @@ -13,8 +14,7 @@
public function __construct(
private PropertyPath $propertyPath,
private Node\Expr $pathNode
) {
}
) {}

public function getNode(): Node
{
Expand Down
4 changes: 1 addition & 3 deletions src/Compiler/Builder/ScopedCodeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
/**
* @param \PhpParser\Node\Stmt[] $stmts
*/
public function __construct(private Node\Expr $input, private Node\Expr $output, private array $stmts)
{
}
public function __construct(private Node\Expr $input, private Node\Expr $output, private array $stmts) {}

public function getNode(): Node\Expr
{
Expand Down
3 changes: 1 addition & 2 deletions src/Compiler/StandardCompilationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public function __construct(
private PropertyPathInterface $propertyPath,
private ?string $path = null,
private ?ClassMetadataInterface $class = null
) {
}
) {}

public static function build(PropertyPathInterface $propertyPath, string $cachePath, string $fqcn): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Strategy/Spaghetti.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Kiboko\Component\FastMap\Compiler\Strategy;

use Kiboko\Component\FastMap\Compiler\Builder\PropertyPathBuilder;
use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder;
use Kiboko\Contract\Mapping\CompilableMapperInterface;
use Kiboko\Contract\Mapping\CompiledMapperInterface;
use Kiboko\Contract\Mapping\Compiler\Strategy\StrategyInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Kiboko\Component\FastMap\Mapping;

use Kiboko\Component\FastMap\Compiler\Builder\PropertyPathBuilder;
use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder;
use Kiboko\Contract\Mapping;
use PhpParser\Node;
use Symfony\Component\PropertyAccess\PropertyAccess;
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Field/ConcatCopyValuesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Kiboko\Component\FastMap\Mapping\Field;

use Kiboko\Component\FastMap\Compiler\Builder\PropertyPathBuilder;
use Kiboko\Component\FastMap\Compiler\Builder\RequiredValuePreconditionBuilder;
use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder;
use Kiboko\Contract\Mapping;
use PhpParser\BuilderFactory;
use PhpParser\Node;
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Field/CopyValueMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Kiboko\Component\FastMap\Mapping\Field;

use Kiboko\Component\FastMap\Compiler\Builder\PropertyPathBuilder;
use Kiboko\Component\FastMap\Compiler\Builder\RequiredValuePreconditionBuilder;
use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder;
use Kiboko\Contract\Mapping;
use PhpParser\Node;
use Symfony\Component\PropertyAccess\PropertyAccess;
Expand Down
5 changes: 1 addition & 4 deletions src/Mapping/Field/ExpressionLanguageValueMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public function __invoke($input, $output, PropertyPathInterface $outputPath)
$this->accessor->setValue(
$output,
$outputPath,
$this->interpreter->evaluate($this->expression, array_merge($this->variables, [
'input' => $input,
'output' => $output,
]))
$this->interpreter->evaluate($this->expression, [...$this->variables, 'input' => $input, 'output' => $output])
);

return $output;
Expand Down
4 changes: 2 additions & 2 deletions src/Mapping/ListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Kiboko\Component\FastMap\Mapping;

use Kiboko\Component\FastMap\Compiler\Builder\ExpressionLanguageToPhpParserBuilder;
use Kiboko\Component\FastMap\Compiler\Builder\PropertyPathBuilder;
use Kiboko\Component\FastMap\Compiler\Builder\ScopedCodeBuilder;
use Kiboko\Component\FastMap\PropertyAccess\EmptyPropertyPath;
use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder;
use Kiboko\Contract\Mapping;
use PhpParser\Node;
use Symfony\Component\ExpressionLanguage\Expression;
Expand All @@ -24,7 +24,7 @@ public function __construct(
private PropertyPathInterface $outputPath,
private readonly ExpressionLanguage $interpreter,
private readonly Expression $inputExpression,
private readonly Mapping\CompilableMapperInterface&Mapping\ArrayMapperInterface $child
private readonly Mapping\ArrayMapperInterface&Mapping\CompilableMapperInterface $child
) {
$this->accessor = PropertyAccess::createPropertyAccessor();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/SingleRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Kiboko\Component\FastMap\Mapping;

use Kiboko\Component\FastMap\Compiler\Builder\PropertyPathBuilder;
use Kiboko\Component\FastMap\PropertyAccess\EmptyPropertyPath;
use Kiboko\Component\SatelliteToolbox\Builder\PropertyPathBuilder;
use Kiboko\Contract\Mapping;
use PhpParser\Node;
use Symfony\Component\ExpressionLanguage\Expression;
Expand Down
4 changes: 1 addition & 3 deletions src/MappingIteration/PathMappingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

final readonly class PathMappingIterator implements \Iterator
{
public function __construct(private PropertyPathIteratorInterface $inner, private TypeMetadataInterface $metadata)
{
}
public function __construct(private PropertyPathIteratorInterface $inner, private TypeMetadataInterface $metadata) {}

public function current(): mixed
{
Expand Down