Skip to content

Commit e23c2d7

Browse files
authored
Merge pull request #72 from MortalFlesh/feature/require-php-8
Require php 8
2 parents f635e7a + 3f86306 commit e23c2d7

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
}

0 commit comments

Comments
 (0)