Skip to content
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion src/Attribute/RouteParamValue/AbstractValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

abstract class AbstractValues implements ValuesInterface
{
/**
* @return non-empty-list<?scalar>
Comment thread
HypeMC marked this conversation as resolved.
*/
abstract protected function getValues(): array;

/**
* {@inheritDoc}
*/
public function toArray(): array
final public function toArray(): array
{
return [
'type' => static::type(),
Expand Down
12 changes: 2 additions & 10 deletions src/Attribute/RouteParamValue/CompoundValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValuesInterface>
*/
private readonly array $values;
public readonly array $values;

/**
* @param string|non-empty-list<string>|ValuesInterface $value
Expand All @@ -38,14 +38,6 @@ public function __construct(
$this->values = $normalized;
}

/**
* @return list<ValuesInterface>
*/
public function getValues(): array
{
return $this->values;
}

/**
* {@inheritDoc}
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Attribute/RouteParamValue/DynamicValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<?string>
* @return non-empty-list<?string>
*/
public function getValues(): array
protected function getValues(): array
{
return [$this->alias, $this->arg];
return [$this->alias, $this->propertyPath];
}

public static function type(): string
Expand Down
6 changes: 3 additions & 3 deletions src/Attribute/RouteParamValue/EnumValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ 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.');
}
}

/**
* @return list<class-string<\BackedEnum>>
* @return non-empty-list<class-string<\BackedEnum>>
*/
public function getValues(): array
protected function getValues(): array
{
return [$this->enum];
}
Expand Down
16 changes: 4 additions & 12 deletions src/Attribute/RouteParamValue/ExpressionValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class ExpressionValues extends AbstractValues
{
private readonly Expression $expression;
public readonly Expression $expression;

public function __construct(
string|Expression $expression,
Expand All @@ -18,19 +18,11 @@ public function __construct(
}

/**
* @return list<Expression>
* @return non-empty-list<string>
*/
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
Expand Down
4 changes: 2 additions & 2 deletions src/Attribute/RouteParamValue/PropertyValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
final class PropertyValues extends AbstractValues
{
/** @var non-empty-list<string> */
private readonly array $properties;
public readonly array $properties;

public function __construct(
string $property,
Expand All @@ -19,7 +19,7 @@ public function __construct(
/**
* @return non-empty-list<string>
*/
public function getValues(): array
protected function getValues(): array
{
return $this->properties;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Attribute/RouteParamValue/RawValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
final class RawValues extends AbstractValues
{
/** @var non-empty-list<?scalar> */
private readonly array $values;
public readonly array $values;

public function __construct(
int|float|string|bool|null $value,
Expand All @@ -19,7 +19,7 @@ public function __construct(
/**
* @return non-empty-list<?scalar>
*/
public function getValues(): array
protected function getValues(): array
{
return $this->values;
}
Expand Down
5 changes: 0 additions & 5 deletions src/Attribute/RouteParamValue/ValuesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

interface ValuesInterface
{
/**
* @return list<mixed>
*/
public function getValues(): array;

/**
* @return array{type: string, values: list<mixed>}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
}
2 changes: 1 addition & 1 deletion src/Cache/Subscription/PurgeSubscriptionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Attribute/RouteParamValue/CompoundValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions tests/Attribute/RouteParamValue/ExpressionValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions tests/Cache/PropertyResolver/InverseValuesBuildersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
),
],
)]
Expand Down