From b13ff8a7d9e35bd91fd245a6b68097fb6a664f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brajkovi=C4=87?= Date: Tue, 16 Dec 2025 22:29:49 +0100 Subject: [PATCH 1/5] cleanup --- src/Attribute/RouteParamValue/AbstractValues.php | 7 ++++++- src/Attribute/RouteParamValue/CompoundValues.php | 12 ++---------- src/Attribute/RouteParamValue/DynamicValues.php | 8 ++++---- src/Attribute/RouteParamValue/EnumValues.php | 6 +++--- .../RouteParamValue/ExpressionValues.php | 16 ++++------------ src/Attribute/RouteParamValue/PropertyValues.php | 4 ++-- src/Attribute/RouteParamValue/RawValues.php | 4 ++-- .../RouteParamValue/ValuesInterface.php | 5 ----- .../CompoundInverseValuesBuilder.php | 2 +- .../DynamicInverseValuesBuilder.php | 4 ++-- .../ExpressionInverseValuesBuilder.php | 2 +- .../PropertyInverseValuesBuilder.php | 2 +- .../Subscription/PurgeSubscriptionProvider.php | 2 +- .../RouteParamValue/CompoundValuesTest.php | 2 +- .../RouteParamValue/ExpressionValuesTest.php | 6 ++---- 15 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/Attribute/RouteParamValue/AbstractValues.php b/src/Attribute/RouteParamValue/AbstractValues.php index d4e6cbc9..91578a2e 100644 --- a/src/Attribute/RouteParamValue/AbstractValues.php +++ b/src/Attribute/RouteParamValue/AbstractValues.php @@ -6,10 +6,15 @@ abstract class AbstractValues implements ValuesInterface { + /** + * @return non-empty-list + */ + abstract protected function getValues(): array; + /** * {@inheritDoc} */ - public function toArray(): array + final public function toArray(): array { return [ 'type' => static::type(), diff --git a/src/Attribute/RouteParamValue/CompoundValues.php b/src/Attribute/RouteParamValue/CompoundValues.php index 4e8e6c3b..44a09f1c 100644 --- a/src/Attribute/RouteParamValue/CompoundValues.php +++ b/src/Attribute/RouteParamValue/CompoundValues.php @@ -7,12 +7,12 @@ use Sofascore\PurgatoryBundle\Attribute\PurgeOn; use Sofascore\PurgatoryBundle\Exception\InvalidArgumentException; -final class CompoundValues extends AbstractValues +final class CompoundValues implements ValuesInterface { /** * @var non-empty-list */ - private readonly array $values; + public readonly array $values; /** * @param string|non-empty-list|ValuesInterface $value @@ -38,14 +38,6 @@ public function __construct( $this->values = $normalized; } - /** - * @return list - */ - public function getValues(): array - { - return $this->values; - } - /** * {@inheritDoc} */ diff --git a/src/Attribute/RouteParamValue/DynamicValues.php b/src/Attribute/RouteParamValue/DynamicValues.php index 73f3668b..97b2e2a3 100644 --- a/src/Attribute/RouteParamValue/DynamicValues.php +++ b/src/Attribute/RouteParamValue/DynamicValues.php @@ -10,15 +10,15 @@ final class DynamicValues extends AbstractValues * @param string $alias Alias defined in {@see AsRouteParamService} attribute */ public function __construct( - private readonly string $alias, - private readonly ?string $arg = null, + public readonly string $alias, + public readonly ?string $arg = null, ) { } /** - * @return list + * @return non-empty-list */ - public function getValues(): array + protected function getValues(): array { return [$this->alias, $this->arg]; } diff --git a/src/Attribute/RouteParamValue/EnumValues.php b/src/Attribute/RouteParamValue/EnumValues.php index 009a8484..b1a6f3ec 100644 --- a/src/Attribute/RouteParamValue/EnumValues.php +++ b/src/Attribute/RouteParamValue/EnumValues.php @@ -12,7 +12,7 @@ final class EnumValues extends AbstractValues * @param class-string<\BackedEnum> $enum */ public function __construct( - private readonly string $enum, + public readonly string $enum, ) { if (!is_a($this->enum, \BackedEnum::class, true)) { throw new InvalidArgumentException('The argument must be a backed enum.'); @@ -20,9 +20,9 @@ public function __construct( } /** - * @return list> + * @return non-empty-list> */ - public function getValues(): array + protected function getValues(): array { return [$this->enum]; } diff --git a/src/Attribute/RouteParamValue/ExpressionValues.php b/src/Attribute/RouteParamValue/ExpressionValues.php index 15378cb3..d540522b 100644 --- a/src/Attribute/RouteParamValue/ExpressionValues.php +++ b/src/Attribute/RouteParamValue/ExpressionValues.php @@ -9,7 +9,7 @@ final class ExpressionValues extends AbstractValues { - private readonly Expression $expression; + public readonly Expression $expression; public function __construct( string|Expression $expression, @@ -18,19 +18,11 @@ public function __construct( } /** - * @return list + * @return non-empty-list */ - public function getValues(): array + protected function getValues(): array { - return [$this->expression]; - } - - public function toArray(): array - { - return [ - 'type' => self::type(), - 'values' => [(string) $this->expression], - ]; + return [(string) $this->expression]; } public static function type(): string diff --git a/src/Attribute/RouteParamValue/PropertyValues.php b/src/Attribute/RouteParamValue/PropertyValues.php index af419c17..96ceea8f 100644 --- a/src/Attribute/RouteParamValue/PropertyValues.php +++ b/src/Attribute/RouteParamValue/PropertyValues.php @@ -7,7 +7,7 @@ final class PropertyValues extends AbstractValues { /** @var non-empty-list */ - private readonly array $properties; + public readonly array $properties; public function __construct( string $property, @@ -19,7 +19,7 @@ public function __construct( /** * @return non-empty-list */ - public function getValues(): array + protected function getValues(): array { return $this->properties; } diff --git a/src/Attribute/RouteParamValue/RawValues.php b/src/Attribute/RouteParamValue/RawValues.php index 355de11e..41a1bb8c 100644 --- a/src/Attribute/RouteParamValue/RawValues.php +++ b/src/Attribute/RouteParamValue/RawValues.php @@ -7,7 +7,7 @@ final class RawValues extends AbstractValues { /** @var non-empty-list */ - private readonly array $values; + public readonly array $values; public function __construct( int|float|string|bool|null $value, @@ -19,7 +19,7 @@ public function __construct( /** * @return non-empty-list */ - public function getValues(): array + protected function getValues(): array { return $this->values; } diff --git a/src/Attribute/RouteParamValue/ValuesInterface.php b/src/Attribute/RouteParamValue/ValuesInterface.php index bd16ebcb..fc5cb49b 100644 --- a/src/Attribute/RouteParamValue/ValuesInterface.php +++ b/src/Attribute/RouteParamValue/ValuesInterface.php @@ -6,11 +6,6 @@ interface ValuesInterface { - /** - * @return list - */ - public function getValues(): array; - /** * @return array{type: string, values: list} */ diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/CompoundInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/CompoundInverseValuesBuilder.php index ab404641..4277188b 100644 --- a/src/Cache/PropertyResolver/InverseValuesBuilder/CompoundInverseValuesBuilder.php +++ b/src/Cache/PropertyResolver/InverseValuesBuilder/CompoundInverseValuesBuilder.php @@ -30,7 +30,7 @@ public function build(ValuesInterface $values, string $associationClass, string fn (ValuesInterface $values): ValuesInterface => $this->getInverseValuesBuilderFor($values) ?->build($values, $associationClass, $associationTarget) ?? $values, - $values->getValues(), + $values->values, ), ); } diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php index cb486bec..7a1d12ae 100644 --- a/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php +++ b/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php @@ -19,8 +19,8 @@ public static function for(): string public function build(ValuesInterface $values, string $associationClass, string $associationTarget): ValuesInterface { - /** @var string $alias */ - [$alias, $arg] = $values->getValues(); + $alias = $values->alias; + $arg = $values->arg; return new DynamicValues( alias: $alias, diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php index f9b09ecb..8d0b84da 100644 --- a/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php +++ b/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php @@ -25,7 +25,7 @@ public static function for(): string public function build(ValuesInterface $values, string $associationClass, string $associationTarget): ValuesInterface { - [$expression] = $values->getValues(); + $expression = $values->expression; $inverseExpression = $this->expressionTransformer->transform($expression, $associationClass, $associationTarget, 'null'); diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/PropertyInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/PropertyInverseValuesBuilder.php index c79f4fc3..2a8d728c 100644 --- a/src/Cache/PropertyResolver/InverseValuesBuilder/PropertyInverseValuesBuilder.php +++ b/src/Cache/PropertyResolver/InverseValuesBuilder/PropertyInverseValuesBuilder.php @@ -21,7 +21,7 @@ public function build(ValuesInterface $values, string $associationClass, string { return new PropertyValues(...array_map( static fn (string $property): string => \sprintf('%s?.%s', $associationTarget, $property), - $values->getValues(), + $values->properties, )); } } diff --git a/src/Cache/Subscription/PurgeSubscriptionProvider.php b/src/Cache/Subscription/PurgeSubscriptionProvider.php index 6fbb5a09..58c37f08 100644 --- a/src/Cache/Subscription/PurgeSubscriptionProvider.php +++ b/src/Cache/Subscription/PurgeSubscriptionProvider.php @@ -76,7 +76,7 @@ private function provideFromMetadata(RouteMetadataProviderInterface $routeMetada } else { foreach ($purgeOn->routeParams as $values) { if ($values instanceof ExpressionValues) { - $this->validateExpression($values->getValues()[0], $routeMetadata->routeName); + $this->validateExpression($values->expression, $routeMetadata->routeName); } } $this->validateRouteParams(array_keys($purgeOn->routeParams), $routeMetadata); diff --git a/tests/Attribute/RouteParamValue/CompoundValuesTest.php b/tests/Attribute/RouteParamValue/CompoundValuesTest.php index 3965dce2..94062b3e 100644 --- a/tests/Attribute/RouteParamValue/CompoundValuesTest.php +++ b/tests/Attribute/RouteParamValue/CompoundValuesTest.php @@ -23,7 +23,7 @@ public function testValueNormalization(mixed $values, mixed $expectedValues): vo { $compoundValues = new CompoundValues(...$values); - self::assertEquals($expectedValues, $compoundValues->getValues()); + self::assertEquals($expectedValues, $compoundValues->values); } public function testExceptionIsThrownOnSelf(): void diff --git a/tests/Attribute/RouteParamValue/ExpressionValuesTest.php b/tests/Attribute/RouteParamValue/ExpressionValuesTest.php index 2a547b0e..a22dc64b 100644 --- a/tests/Attribute/RouteParamValue/ExpressionValuesTest.php +++ b/tests/Attribute/RouteParamValue/ExpressionValuesTest.php @@ -17,10 +17,8 @@ final class ExpressionValuesTest extends TestCase #[TestWith([new Expression('obj.getHeight() * obj.getWidth()')])] public function testValueNormalization(string|Expression $expression): void { - $values = (new ExpressionValues($expression))->getValues(); + $value = (new ExpressionValues($expression))->expression; - self::assertArrayHasKey(0, $values); - self::assertInstanceOf(Expression::class, $values[0]); - self::assertSame((string) $expression, (string) $values[0]); + self::assertSame((string) $expression, (string) $value); } } From 301745e32590f1968872a48cd6cfb3bb9499b04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brajkovi=C4=87?= Date: Wed, 17 Dec 2025 08:27:27 +0100 Subject: [PATCH 2/5] inline --- tests/Attribute/RouteParamValue/ExpressionValuesTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Attribute/RouteParamValue/ExpressionValuesTest.php b/tests/Attribute/RouteParamValue/ExpressionValuesTest.php index a22dc64b..2449dba9 100644 --- a/tests/Attribute/RouteParamValue/ExpressionValuesTest.php +++ b/tests/Attribute/RouteParamValue/ExpressionValuesTest.php @@ -17,8 +17,6 @@ final class ExpressionValuesTest extends TestCase #[TestWith([new Expression('obj.getHeight() * obj.getWidth()')])] public function testValueNormalization(string|Expression $expression): void { - $value = (new ExpressionValues($expression))->expression; - - self::assertSame((string) $expression, (string) $value); + self::assertSame((string) $expression, (string) (new ExpressionValues($expression))->expression); } } From 7c014a6f6d83c8652c6730422b05df8212c962d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brajkovi=C4=87?= Date: Wed, 17 Dec 2025 08:34:08 +0100 Subject: [PATCH 3/5] inline in inverse values builders --- .../InverseValuesBuilder/DynamicInverseValuesBuilder.php | 7 ++----- .../ExpressionInverseValuesBuilder.php | 8 +++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php index 7a1d12ae..ee1d340e 100644 --- a/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php +++ b/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php @@ -19,12 +19,9 @@ public static function for(): string public function build(ValuesInterface $values, string $associationClass, string $associationTarget): ValuesInterface { - $alias = $values->alias; - $arg = $values->arg; - return new DynamicValues( - alias: $alias, - arg: null !== $arg ? \sprintf('%s?.%s', $associationTarget, $arg) : $associationTarget, + alias: $values->alias, + arg: null !== $values->arg ? \sprintf('%s?.%s', $associationTarget, $values->arg) : $associationTarget, ); } } diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php index 8d0b84da..f1873ca2 100644 --- a/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php +++ b/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php @@ -25,10 +25,8 @@ public static function for(): string public function build(ValuesInterface $values, string $associationClass, string $associationTarget): ValuesInterface { - $expression = $values->expression; - - $inverseExpression = $this->expressionTransformer->transform($expression, $associationClass, $associationTarget, 'null'); - - return new ExpressionValues($inverseExpression); + return new ExpressionValues( + expression: $this->expressionTransformer->transform($values->expression, $associationClass, $associationTarget, 'null'), + ); } } From 9b8d2e5f863fd55f9cab12e4416c470ea1c2c296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brajkovi=C4=87?= Date: Wed, 17 Dec 2025 13:16:00 +0100 Subject: [PATCH 4/5] rename DynamicValues::arg to propertyPath --- src/Attribute/RouteParamValue/DynamicValues.php | 4 ++-- .../InverseValuesBuilder/DynamicInverseValuesBuilder.php | 2 +- tests/Cache/PropertyResolver/InverseValuesBuildersTest.php | 6 +++--- .../TestApplication/Controller/AnimalController.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Attribute/RouteParamValue/DynamicValues.php b/src/Attribute/RouteParamValue/DynamicValues.php index 97b2e2a3..47d04980 100644 --- a/src/Attribute/RouteParamValue/DynamicValues.php +++ b/src/Attribute/RouteParamValue/DynamicValues.php @@ -11,7 +11,7 @@ final class DynamicValues extends AbstractValues */ public function __construct( public readonly string $alias, - public readonly ?string $arg = null, + public readonly ?string $propertyPath = null, ) { } @@ -20,7 +20,7 @@ public function __construct( */ protected function getValues(): array { - return [$this->alias, $this->arg]; + return [$this->alias, $this->propertyPath]; } public static function type(): string diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php index ee1d340e..b2e43385 100644 --- a/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php +++ b/src/Cache/PropertyResolver/InverseValuesBuilder/DynamicInverseValuesBuilder.php @@ -21,7 +21,7 @@ public function build(ValuesInterface $values, string $associationClass, string { return new DynamicValues( alias: $values->alias, - arg: null !== $values->arg ? \sprintf('%s?.%s', $associationTarget, $values->arg) : $associationTarget, + propertyPath: null !== $values->propertyPath ? \sprintf('%s?.%s', $associationTarget, $values->propertyPath) : $associationTarget, ); } } diff --git a/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php b/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php index 80960ca8..6e0ebc11 100644 --- a/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php +++ b/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php @@ -52,7 +52,7 @@ public function testBuild(): void $compoundValues = new CompoundValues( new DynamicValues('alias'), - new DynamicValues('alias', arg: 'obj'), + new DynamicValues('alias', propertyPath: 'obj'), new EnumValues(DummyIntEnum::class), new PropertyValues('obj'), new RawValues(1, null, 'str'), @@ -61,10 +61,10 @@ public function testBuild(): void self::assertEquals( expected: new CompoundValues( - new DynamicValues('alias', arg: 'association'), + new DynamicValues('alias', propertyPath: 'association'), new DynamicValues( alias: 'alias', - arg: 'association?.obj', + propertyPath: 'association?.obj', ), new EnumValues(DummyIntEnum::class), new PropertyValues('association?.obj'), diff --git a/tests/Functional/TestApplication/Controller/AnimalController.php b/tests/Functional/TestApplication/Controller/AnimalController.php index 29831313..044a79dc 100644 --- a/tests/Functional/TestApplication/Controller/AnimalController.php +++ b/tests/Functional/TestApplication/Controller/AnimalController.php @@ -115,7 +115,7 @@ public function tagAction(string $tag) 'rating' => new CompoundValues( new DynamicValues(alias: 'purgatory.animal_rating2'), new DynamicValues(alias: 'purgatory.animal_rating1'), - new DynamicValues(alias: 'purgatory.animal_rating3', arg: 'owner'), + new DynamicValues(alias: 'purgatory.animal_rating3', propertyPath: 'owner'), ), ], )] From d578ed23dee4fa29b7f4bc643bf5be2266c8eae2 Mon Sep 17 00:00:00 2001 From: HypeMC <2445045+HypeMC@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:41:34 +0100 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b55f1802..b4f7cc8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,11 +12,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `ExpressionValues` to enable resolution of route parameter values via expressions by @HypeMC in https://github.com/sofascore/purgatory-bundle/pull/112 +### Changed + +- Method `AbstractValues::toArray()` is now `final` by @Brajk19 + in https://github.com/sofascore/purgatory-bundle/pull/130 +- Method `AbstractValues::getValues()` is now `protected` by @Brajk19 + in https://github.com/sofascore/purgatory-bundle/pull/130 +- Rename second constructor argument in `DynamicValues` to `$propertyPath` by @Brajk19 + in https://github.com/sofascore/purgatory-bundle/pull/130 + ### Removed - Symfony v5 support by @HypeMC in https://github.com/sofascore/purgatory-bundle/pull/128 - `InverseValuesAwareInterface`, use dedicated builder services instead by @HypeMC in https://github.com/sofascore/purgatory-bundle/pull/123 +- `ValuesInterface::getValues()`, use public properties instead by @Brajk19 + in https://github.com/sofascore/purgatory-bundle/pull/130 ## [1.3.0] - 2025-12-15