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 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..47d04980 100644 --- a/src/Attribute/RouteParamValue/DynamicValues.php +++ b/src/Attribute/RouteParamValue/DynamicValues.php @@ -10,17 +10,17 @@ 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 $propertyPath = null, ) { } /** - * @return list + * @return non-empty-list */ - public function getValues(): array + protected function getValues(): array { - return [$this->alias, $this->arg]; + return [$this->alias, $this->propertyPath]; } public static function type(): string 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..b2e43385 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 { - /** @var string $alias */ - [$alias, $arg] = $values->getValues(); - return new DynamicValues( - alias: $alias, - arg: null !== $arg ? \sprintf('%s?.%s', $associationTarget, $arg) : $associationTarget, + alias: $values->alias, + propertyPath: null !== $values->propertyPath ? \sprintf('%s?.%s', $associationTarget, $values->propertyPath) : $associationTarget, ); } } diff --git a/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php b/src/Cache/PropertyResolver/InverseValuesBuilder/ExpressionInverseValuesBuilder.php index f9b09ecb..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->getValues(); - - $inverseExpression = $this->expressionTransformer->transform($expression, $associationClass, $associationTarget, 'null'); - - return new ExpressionValues($inverseExpression); + return new ExpressionValues( + expression: $this->expressionTransformer->transform($values->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..2449dba9 100644 --- a/tests/Attribute/RouteParamValue/ExpressionValuesTest.php +++ b/tests/Attribute/RouteParamValue/ExpressionValuesTest.php @@ -17,10 +17,6 @@ final class ExpressionValuesTest extends TestCase #[TestWith([new Expression('obj.getHeight() * obj.getWidth()')])] public function testValueNormalization(string|Expression $expression): void { - $values = (new ExpressionValues($expression))->getValues(); - - self::assertArrayHasKey(0, $values); - self::assertInstanceOf(Expression::class, $values[0]); - self::assertSame((string) $expression, (string) $values[0]); + self::assertSame((string) $expression, (string) (new ExpressionValues($expression))->expression); } } 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'), ), ], )]