Skip to content

Commit 89263ca

Browse files
authored
Route param values cleanup (#130)
1 parent f8f01de commit 89263ca

File tree

18 files changed

+49
-63
lines changed

18 files changed

+49
-63
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `ExpressionValues` to enable resolution of route parameter values via expressions by @HypeMC
1313
in https://github.com/sofascore/purgatory-bundle/pull/112
1414

15+
### Changed
16+
17+
- Method `AbstractValues::toArray()` is now `final` by @Brajk19
18+
in https://github.com/sofascore/purgatory-bundle/pull/130
19+
- Method `AbstractValues::getValues()` is now `protected` by @Brajk19
20+
in https://github.com/sofascore/purgatory-bundle/pull/130
21+
- Rename second constructor argument in `DynamicValues` to `$propertyPath` by @Brajk19
22+
in https://github.com/sofascore/purgatory-bundle/pull/130
23+
1524
### Removed
1625

1726
- Symfony v5 support by @HypeMC in https://github.com/sofascore/purgatory-bundle/pull/128
1827
- `InverseValuesAwareInterface`, use dedicated builder services instead by @HypeMC
1928
in https://github.com/sofascore/purgatory-bundle/pull/123
29+
- `ValuesInterface::getValues()`, use public properties instead by @Brajk19
30+
in https://github.com/sofascore/purgatory-bundle/pull/130
2031

2132
## [1.3.0] - 2025-12-15
2233

src/Attribute/RouteParamValue/AbstractValues.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77
abstract class AbstractValues implements ValuesInterface
88
{
9+
/**
10+
* @return non-empty-list<?scalar>
11+
*/
12+
abstract protected function getValues(): array;
13+
914
/**
1015
* {@inheritDoc}
1116
*/
12-
public function toArray(): array
17+
final public function toArray(): array
1318
{
1419
return [
1520
'type' => static::type(),

src/Attribute/RouteParamValue/CompoundValues.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use Sofascore\PurgatoryBundle\Attribute\PurgeOn;
88
use Sofascore\PurgatoryBundle\Exception\InvalidArgumentException;
99

10-
final class CompoundValues extends AbstractValues
10+
final class CompoundValues implements ValuesInterface
1111
{
1212
/**
1313
* @var non-empty-list<ValuesInterface>
1414
*/
15-
private readonly array $values;
15+
public readonly array $values;
1616

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

41-
/**
42-
* @return list<ValuesInterface>
43-
*/
44-
public function getValues(): array
45-
{
46-
return $this->values;
47-
}
48-
4941
/**
5042
* {@inheritDoc}
5143
*/

src/Attribute/RouteParamValue/DynamicValues.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ final class DynamicValues extends AbstractValues
1010
* @param string $alias Alias defined in {@see AsRouteParamService} attribute
1111
*/
1212
public function __construct(
13-
private readonly string $alias,
14-
private readonly ?string $arg = null,
13+
public readonly string $alias,
14+
public readonly ?string $propertyPath = null,
1515
) {
1616
}
1717

1818
/**
19-
* @return list<?string>
19+
* @return non-empty-list<?string>
2020
*/
21-
public function getValues(): array
21+
protected function getValues(): array
2222
{
23-
return [$this->alias, $this->arg];
23+
return [$this->alias, $this->propertyPath];
2424
}
2525

2626
public static function type(): string

src/Attribute/RouteParamValue/EnumValues.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ final class EnumValues extends AbstractValues
1212
* @param class-string<\BackedEnum> $enum
1313
*/
1414
public function __construct(
15-
private readonly string $enum,
15+
public readonly string $enum,
1616
) {
1717
if (!is_a($this->enum, \BackedEnum::class, true)) {
1818
throw new InvalidArgumentException('The argument must be a backed enum.');
1919
}
2020
}
2121

2222
/**
23-
* @return list<class-string<\BackedEnum>>
23+
* @return non-empty-list<class-string<\BackedEnum>>
2424
*/
25-
public function getValues(): array
25+
protected function getValues(): array
2626
{
2727
return [$this->enum];
2828
}

src/Attribute/RouteParamValue/ExpressionValues.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
final class ExpressionValues extends AbstractValues
1111
{
12-
private readonly Expression $expression;
12+
public readonly Expression $expression;
1313

1414
public function __construct(
1515
string|Expression $expression,
@@ -18,19 +18,11 @@ public function __construct(
1818
}
1919

2020
/**
21-
* @return list<Expression>
21+
* @return non-empty-list<string>
2222
*/
23-
public function getValues(): array
23+
protected function getValues(): array
2424
{
25-
return [$this->expression];
26-
}
27-
28-
public function toArray(): array
29-
{
30-
return [
31-
'type' => self::type(),
32-
'values' => [(string) $this->expression],
33-
];
25+
return [(string) $this->expression];
3426
}
3527

3628
public static function type(): string

src/Attribute/RouteParamValue/PropertyValues.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
final class PropertyValues extends AbstractValues
88
{
99
/** @var non-empty-list<string> */
10-
private readonly array $properties;
10+
public readonly array $properties;
1111

1212
public function __construct(
1313
string $property,
@@ -19,7 +19,7 @@ public function __construct(
1919
/**
2020
* @return non-empty-list<string>
2121
*/
22-
public function getValues(): array
22+
protected function getValues(): array
2323
{
2424
return $this->properties;
2525
}

src/Attribute/RouteParamValue/RawValues.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
final class RawValues extends AbstractValues
88
{
99
/** @var non-empty-list<?scalar> */
10-
private readonly array $values;
10+
public readonly array $values;
1111

1212
public function __construct(
1313
int|float|string|bool|null $value,
@@ -19,7 +19,7 @@ public function __construct(
1919
/**
2020
* @return non-empty-list<?scalar>
2121
*/
22-
public function getValues(): array
22+
protected function getValues(): array
2323
{
2424
return $this->values;
2525
}

src/Attribute/RouteParamValue/ValuesInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
interface ValuesInterface
88
{
9-
/**
10-
* @return list<mixed>
11-
*/
12-
public function getValues(): array;
13-
149
/**
1510
* @return array{type: string, values: list<mixed>}
1611
*/

src/Cache/PropertyResolver/InverseValuesBuilder/CompoundInverseValuesBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function build(ValuesInterface $values, string $associationClass, string
3030
fn (ValuesInterface $values): ValuesInterface => $this->getInverseValuesBuilderFor($values)
3131
?->build($values, $associationClass, $associationTarget)
3232
?? $values,
33-
$values->getValues(),
33+
$values->values,
3434
),
3535
);
3636
}

0 commit comments

Comments
 (0)