Skip to content

Commit 3f86306

Browse files
committed
Require php 8
1 parent f635e7a commit 3f86306

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+222
-329
lines changed

.github/workflows/tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php-version: ['7.4']
15+
php-version: ['8.0']
1616
dependencies: ['']
1717
include:
18-
- { php-version: '7.4', dependencies: '--prefer-lowest --prefer-stable' }
18+
- { php-version: '8.0', dependencies: '--prefer-lowest --prefer-stable' }
1919

2020
name: Unit tests - PHP ${{ matrix.dependencies }}
2121

@@ -65,7 +65,7 @@ jobs:
6565
- name: Setup PHP
6666
uses: shivammathur/setup-php@v2
6767
with:
68-
php-version: '7.4'
68+
php-version: '8.0'
6969
extensions: mbstring, intl
7070

7171
- name: Install dependencies

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<!-- There should always be "Unreleased" section at the beginning. -->
55

66
## Unreleased
7+
- Require php 8.0
8+
- [**BC**] Use strong types (even union-types) (_it is considered BC, because some types annotated before were not correct in all places_)
9+
- Update dependencies
710

811
## 2.2.0 - 2021-04-09
912
- Require php 7.4 and update dependencies

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"description": "Parser/builder for filters from API query parameters.",
55
"license": "MIT",
66
"require": {
7-
"php": "^7.4",
7+
"php": "^8.0",
88
"ext-mbstring": "*",
99
"beberlei/assert": "^3.0",
10-
"mf/collections-php": "^5.0"
10+
"mf/collections-php": "^6.0"
1111
},
1212
"require-dev": {
1313
"doctrine/orm": "^2.7",

ecs.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
declare(strict_types=1);
44

55
use Lmc\CodingStandard\Sniffs\Naming\ClassNameSuffixByParentSniff;
6+
use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\OperatorSpacingSniff;
7+
use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
68
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
79
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
810
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@@ -13,7 +15,11 @@
1315

1416
$parameters->set(
1517
Option::SKIP,
16-
['SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff.ReferencedGeneralException' => ['tests/Exception/*.php']]
18+
[
19+
'SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff.ReferencedGeneralException' => ['tests/Exception/*.php'],
20+
OperatorSpacingSniff::class => null,
21+
BinaryOperatorSpacesFixer::class => null,
22+
]
1723
);
1824

1925
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');

src/ApiFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function registerFunction(string $functionName, array $parameters, callab
279279
* @throws ApiFilterExceptionInterface
280280
* @return mixed of type <U> - the output of the registered function
281281
*/
282-
public function executeFunction(string $functionName, array $queryParameters, $filterable)
282+
public function executeFunction(string $functionName, array $queryParameters, mixed $filterable): mixed
283283
{
284284
$filters = $this->parser->parse($queryParameters);
285285
$this->applicator->setFilters($filters);
@@ -311,7 +311,7 @@ public function executeFunction(string $functionName, array $queryParameters, $f
311311
* @throws ApiFilterExceptionInterface
312312
* @return ITuple (<U>, array) where <U> is the output of the registered function and array contains prepared values
313313
*/
314-
public function applyFunction(string $functionName, array $queryParameters, $filterable): ITuple
314+
public function applyFunction(string $functionName, array $queryParameters, mixed $filterable): ITuple
315315
{
316316
try {
317317
$filters = $this->parser->parse($queryParameters);

src/Assertion.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class Assertion extends BaseAssertion
1212

1313
/**
1414
* Assert that value is instance of ITuple or string value containing a Tuple.
15-
*
16-
* @param mixed $value
17-
* @param string|callable|null $message
1815
*/
19-
public static function isTuple($value, $message = null, ?string $propertyPath = null): bool
20-
{
16+
public static function isTuple(
17+
mixed $value,
18+
string|callable|null $message = null,
19+
?string $propertyPath = null
20+
): bool {
2121
if (self::isTupleValue($value)) {
2222
return true;
2323
}
@@ -30,8 +30,7 @@ public static function isTuple($value, $message = null, ?string $propertyPath =
3030
throw static::createException($value, $message, 0, $propertyPath);
3131
}
3232

33-
/** @param mixed $value */
34-
private static function isTupleValue($value): bool
33+
private static function isTupleValue(mixed $value): bool
3534
{
3635
return $value instanceof ITuple || (is_string($value) && mb_substr($value, 0, 1) === '(');
3736
}

src/Entity/Filterable.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@
66

77
class Filterable
88
{
9-
/** @var mixed */
10-
private $value;
11-
129
/** @param mixed $value This must be supported by any applicator */
13-
public function __construct($value)
10+
public function __construct(private mixed $value)
1411
{
1512
Assertion::notIsInstanceOf(
1613
$value,
1714
self::class,
1815
'Filterable must not contain another Filterable. Extract a value from Filterable or use it directly.'
1916
);
20-
$this->value = $value;
2117
}
2218

2319
/** @return mixed This must be supported by any applicator */
24-
public function getValue()
20+
public function getValue(): mixed
2521
{
2622
return $this->value;
2723
}

src/Entity/ParameterDefinition.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
class ParameterDefinition
1010
{
11-
private string $name;
12-
private string $filter;
13-
private string $column;
14-
private ?Value $defaultValue;
15-
1611
/**
1712
* Shortcut for creating parameter with just a name and a default value
1813
* Otherwise you would need to pass null as filter and column, or create default values for yourself
@@ -50,15 +45,13 @@ public static function fromArray(array $parameters): self
5045
}
5146

5247
public function __construct(
53-
string $name,
54-
?string $filter = Filter::EQUALS,
55-
?string $column = null,
56-
?Value $defaultValue = null
48+
private string $name,
49+
private ?string $filter = Filter::EQUALS,
50+
private ?string $column = null,
51+
private ?Value $defaultValue = null
5752
) {
58-
$this->name = $name;
5953
$this->filter = $filter ?? Filter::EQUALS;
6054
$this->column = $column ?? $name;
61-
$this->defaultValue = $defaultValue;
6255
}
6356

6457
public function getName(): string

src/Entity/Value.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,16 @@
66

77
class Value
88
{
9-
/** @var mixed */
10-
private $value;
11-
12-
/** @param mixed $value */
13-
public function __construct($value)
9+
public function __construct(private mixed $value)
1410
{
1511
Assertion::notIsInstanceOf(
1612
$value,
1713
self::class,
1814
'Value must not contain another Value. Extract a value from Value or use it directly.'
1915
);
20-
$this->value = $value;
2116
}
2217

23-
/** @return mixed */
24-
public function getValue()
18+
public function getValue(): mixed
2519
{
2620
return $this->value;
2721
}

src/Exception/InvalidArgumentException.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,23 @@
66

77
class InvalidArgumentException extends \InvalidArgumentException implements ApiFilterExceptionInterface, AssertionFailedException
88
{
9-
private ?string $propertyPath;
10-
/** @var mixed */
11-
private $value;
12-
private array $constraints;
13-
14-
/**
15-
* @param mixed $value
16-
*/
179
public function __construct(
1810
string $message,
1911
int $code = null,
20-
?string $propertyPath = null,
21-
$value = null,
22-
array $constraints = null,
12+
private ?string $propertyPath = null,
13+
private mixed $value = null,
14+
private array $constraints = [],
2315
\Throwable $previous = null
2416
) {
2517
parent::__construct($message, (int) $code, $previous);
26-
$this->propertyPath = $propertyPath;
27-
$this->value = $value;
28-
$this->constraints = $constraints ?? [];
2918
}
3019

3120
public function getPropertyPath(): ?string
3221
{
3322
return $this->propertyPath;
3423
}
3524

36-
/** @return mixed */
37-
public function getValue()
25+
public function getValue(): mixed
3826
{
3927
return $this->value;
4028
}

src/Filter/AbstractFilter.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@
77

88
abstract class AbstractFilter implements FilterInterface
99
{
10-
private string $title;
11-
private string $column;
12-
private Value $value;
1310
private ?string $fullTitle = null;
1411

15-
public function __construct(string $title, string $column, Value $value)
12+
public function __construct(private string $title, private string $column, private Value $value)
1613
{
1714
Assertion::regex($title, '/^[a-zA-Z_]+$/', 'Title must be only [a-zA-Z_] letters but "%s" given.');
18-
$this->title = $title;
19-
$this->column = $column;
20-
$this->value = $value;
2115
}
2216

2317
public function getTitle(): string

src/Filter/FilterWithOperator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
class FilterWithOperator extends AbstractFilter
88
{
9-
private string $operator;
10-
11-
public function __construct(string $column, Value $value, string $operator, string $title)
9+
public function __construct(string $column, Value $value, private string $operator, string $title)
1210
{
1311
parent::__construct($title, $column, $value);
14-
$this->operator = $operator;
1512
}
1613

1714
public function getOperator(): string

src/Service/FilterApplicator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ class FilterApplicator
1919
{
2020
/** @var PrioritizedCollection|ApplicatorInterface[] */
2121
private PrioritizedCollection $applicators;
22-
private Functions $functions;
2322
private ?FiltersInterface $filters = null;
2423

25-
public function __construct(Functions $functions)
24+
public function __construct(private Functions $functions)
2625
{
27-
$this->functions = $functions;
2826
$this->applicators = new PrioritizedCollection(ApplicatorInterface::class);
2927
}
3028

src/Service/FilterFactory.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ class FilterFactory
1515
{
1616
public function createFilter(string $column, string $filter, Value $value, string $title = null): FilterInterface
1717
{
18-
switch (mb_strtolower($filter)) {
19-
case Filter::EQUALS:
20-
return new FilterWithOperator($column, $value, '=', $title ?? Filter::EQUALS);
21-
case Filter::NOT_EQUALS:
22-
return new FilterWithOperator($column, $value, '!=', $title ?? Filter::NOT_EQUALS);
23-
case Filter::GREATER_THAN:
24-
return new FilterWithOperator($column, $value, '>', $title ?? Filter::GREATER_THAN);
25-
case Filter::LESS_THEN:
26-
return new FilterWithOperator($column, $value, '<', $title ?? Filter::LESS_THEN);
27-
case Filter::LESS_THEN_OR_EQUAL:
28-
return new FilterWithOperator($column, $value, '<=', $title ?? Filter::LESS_THEN_OR_EQUAL);
29-
case Filter::GREATER_THAN_OR_EQUAL:
30-
return new FilterWithOperator($column, $value, '>=', $title ?? Filter::GREATER_THAN_OR_EQUAL);
31-
case Filter::IN:
32-
return new FilterIn($column, $value, $title);
33-
case Filter::FUNCTION:
34-
return new FilterFunction($column, $value, $title);
35-
case Filter::FUNCTION_PARAMETER:
36-
return new FunctionParameter($column, $value, $title);
37-
}
38-
39-
throw UnknownFilterException::forFilterWithColumnAndValue($filter, $column, $value);
18+
return match (mb_strtolower($filter)) {
19+
Filter::EQUALS => new FilterWithOperator($column, $value, '=', $title ?? Filter::EQUALS),
20+
Filter::NOT_EQUALS => new FilterWithOperator($column, $value, '!=', $title ?? Filter::NOT_EQUALS),
21+
Filter::GREATER_THAN => new FilterWithOperator($column, $value, '>', $title ?? Filter::GREATER_THAN),
22+
Filter::LESS_THEN => new FilterWithOperator($column, $value, '<', $title ?? Filter::LESS_THEN),
23+
Filter::LESS_THEN_OR_EQUAL => new FilterWithOperator(
24+
$column,
25+
$value,
26+
'<=',
27+
$title ?? Filter::LESS_THEN_OR_EQUAL
28+
),
29+
Filter::GREATER_THAN_OR_EQUAL => new FilterWithOperator(
30+
$column,
31+
$value,
32+
'>=',
33+
$title ?? Filter::GREATER_THAN_OR_EQUAL
34+
),
35+
Filter::IN => new FilterIn($column, $value, $title),
36+
Filter::FUNCTION => new FilterFunction($column, $value, $title),
37+
Filter::FUNCTION_PARAMETER => new FunctionParameter($column, $value, $title),
38+
default => throw UnknownFilterException::forFilterWithColumnAndValue($filter, $column, $value),
39+
};
4040
}
4141
}

src/Service/FunctionCreator.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414

1515
class FunctionCreator
1616
{
17-
private FilterFactory $filterFactory;
18-
19-
public function __construct(FilterFactory $filterFactory)
17+
public function __construct(private FilterFactory $filterFactory)
2018
{
21-
$this->filterFactory = $filterFactory;
2219
}
2320

2421
/** @return ParameterDefinition[]|IMap IMap<string, Parameter> */
@@ -72,10 +69,7 @@ public function createByParameters(FilterApplicator $applicator, IMap $normalize
7269
};
7370
}
7471

75-
/**
76-
* @param mixed $parameter
77-
*/
78-
private function assertParameter($parameter): void
72+
private function assertParameter(mixed $parameter): void
7973
{
8074
Assertion::true(
8175
is_string($parameter) || $parameter instanceof ParameterDefinition || is_array($parameter),

src/Service/Parser/AbstractParser.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@
99

1010
abstract class AbstractParser implements ParserInterface
1111
{
12-
private FilterFactory $filterFactory;
13-
14-
public function __construct(FilterFactory $filterFactory)
12+
public function __construct(private FilterFactory $filterFactory)
1513
{
16-
$this->filterFactory = $filterFactory;
1714
}
1815

19-
/**
20-
* @param string|array $value
21-
*/
22-
protected function isTuple($value): bool
16+
protected function isTuple(string|array $value): bool
2317
{
2418
return is_string($value) && mb_substr($value, 0, 1) === '(';
2519
}
@@ -42,10 +36,7 @@ protected function isColumnWithFilter(string $column): bool
4236
return mb_strpos($column, '[') !== false || mb_strpos($column, ']') !== false;
4337
}
4438

45-
/**
46-
* @param mixed $value
47-
*/
48-
protected function createFilter(string $column, string $filter, $value): FilterInterface
39+
protected function createFilter(string $column, string $filter, mixed $value): FilterInterface
4940
{
5041
return $this->filterFactory->createFilter($column, $filter, new Value($value));
5142
}

0 commit comments

Comments
 (0)