Skip to content

Commit 0391fb2

Browse files
Modernize.
1 parent 24a7e0e commit 0391fb2

24 files changed

+310
-332
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,13 @@ name: CI
33
on: [push]
44

55
jobs:
6-
old:
7-
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
8-
runs-on: ${{ matrix.operating-system }}
9-
strategy:
10-
matrix:
11-
operating-system: ['ubuntu-latest']
12-
php-versions: ['7.0']
13-
phpunit-versions: ['6.5.14']
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v4
17-
18-
- name: Setup PHP
19-
uses: shivammathur/setup-php@v2
20-
with:
21-
php-version: ${{ matrix.php-versions }}
22-
extensions: mbstring, intl
23-
ini-values: post_max_size=256M, max_execution_time=180
24-
tools: psalm, phpunit:${{ matrix.phpunit-versions }}
25-
26-
- name: Install dependencies
27-
run: composer self-update; composer install
28-
29-
- name: PHPUnit tests
30-
run: vendor/bin/phpunit
31-
32-
moderate:
33-
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
34-
runs-on: ${{ matrix.operating-system }}
35-
strategy:
36-
matrix:
37-
operating-system: ['ubuntu-latest']
38-
php-versions: ['7.1', '7.2', '7.3']
39-
phpunit-versions: ['latest']
40-
steps:
41-
- name: Checkout
42-
uses: actions/checkout@v4
43-
44-
- name: Setup PHP
45-
uses: shivammathur/setup-php@v2
46-
with:
47-
php-version: ${{ matrix.php-versions }}
48-
extensions: mbstring, intl, sodium
49-
ini-values: post_max_size=256M, max_execution_time=180
50-
tools: psalm, phpunit:${{ matrix.phpunit-versions }}
51-
52-
- name: Install dependencies
53-
run: composer install
54-
55-
- name: Modernize dependencies
56-
run: composer require --dev "phpunit/phpunit:>=4"
57-
58-
- name: PHPUnit tests
59-
run: vendor/bin/phpunit
60-
616
modern:
627
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
638
runs-on: ${{ matrix.operating-system }}
649
strategy:
6510
matrix:
6611
operating-system: ['ubuntu-latest']
67-
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
12+
php-versions: ['8.1', '8.2', '8.3', '8.4', '8.5']
6813
phpunit-versions: ['latest']
6914
steps:
7015
- name: Checkout

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
[![Downloads](https://img.shields.io/packagist/dt/paragonie/ionizer.svg)](https://packagist.org/packages/paragonie/ionizer)
99

1010
Ionizer provides strict typing and input validation for dynamic inputs (i.e. HTTP request parameters).
11-
**Requires PHP 7 or higher.**
11+
**Requires PHP 8.1 or higher.**
12+
13+
For PHP 7.0 support, please refer to the [v1.x](https://github.com/paragonie/ionizer/tree/v1.x) branch.
1214

1315
## What is Ionizer?
1416

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"license": "ISC",
2727
"require": {
2828
"ext-json": "*",
29-
"php": "^7|^8",
29+
"php": "^8.1",
3030
"paragonie/constant_time_encoding": "^2.1|^3"
3131
},
3232
"require-dev": {
33-
"phpunit/phpunit": "^6.5|^7|^8|^9|^10|^11"
33+
"phpunit/phpunit": "^10|^11"
3434
},
3535
"scripts": {
3636
"test": ["phpunit", "psalm"]

src/Filter/AllowList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AllowList extends InputFilter
1414
/**
1515
* @var array<int, mixed>
1616
*/
17-
protected $allowedValues = [];
17+
protected array $allowedValues = [];
1818

1919
/**
2020
* AllowList constructor.
@@ -29,7 +29,7 @@ public function __construct(...$values)
2929
* @param array<int, scalar> $values
3030
* @return self
3131
*/
32-
protected function addToWhiteList(...$values)
32+
protected function addToWhiteList(mixed ...$values): static
3333
{
3434
switch ($this->type) {
3535
case 'bool':
@@ -88,7 +88,7 @@ protected function addToWhiteList(...$values)
8888
* @throws \TypeError
8989
* @throws InvalidDataException
9090
*/
91-
public function process($data = null)
91+
public function process(mixed $data = null): mixed
9292
{
9393
if (!empty($this->allowedValues)) {
9494
if (!\in_array($data, $this->allowedValues, true)) {

src/Filter/ArrayFilter.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,31 @@
55
use ParagonIE\Ionizer\Contract\IndexPolicyInterface;
66
use ParagonIE\Ionizer\InputFilter;
77
use ParagonIE\Ionizer\InvalidDataException;
8+
use ReturnTypeWillChange;
9+
use TypeError;
10+
use function is_array;
11+
use function is_null;
12+
use function sprintf;
813

914
/**
1015
* Class ArrayFilter
1116
* @package ParagonIE\Ionizer\Filter
1217
*/
1318
class ArrayFilter extends InputFilter
1419
{
15-
/**
16-
* @var mixed
17-
*/
18-
protected $default = [];
20+
protected mixed $default = [];
1921

20-
/**
21-
* @var string
22-
*/
23-
protected $type = 'array';
22+
protected string $type = 'array';
2423

25-
/**
26-
* @var ?IndexPolicyInterface $indexPolicy
27-
*/
28-
protected $indexPolicy = null;
24+
protected ?IndexPolicyInterface $indexPolicy = null;
2925

3026
/**
3127
* Add restrictions to the keys allowed in this array
3228
*
3329
* @param IndexPolicyInterface $indexPolicy
34-
* @return $this
30+
* @return static
3531
*/
36-
public function setIndexPolicy(IndexPolicyInterface $indexPolicy): self
32+
public function setIndexPolicy(IndexPolicyInterface $indexPolicy): static
3733
{
3834
$this->indexPolicy = $indexPolicy;
3935
return $this;
@@ -44,26 +40,27 @@ public function setIndexPolicy(IndexPolicyInterface $indexPolicy): self
4440
*
4541
* @param mixed $data
4642
* @return array
47-
* @throws \TypeError
43+
* @throws TypeError
4844
* @throws InvalidDataException
4945
*/
50-
public function process($data = null)
46+
#[ReturnTypeWillChange]
47+
public function process(mixed $data = null): array
5148
{
52-
if (\is_array($data)) {
49+
if (is_array($data)) {
5350
$data = (array) $data;
54-
} elseif (\is_null($data)) {
51+
} elseif (is_null($data)) {
5552
$data = [];
5653
} else {
57-
throw new \TypeError(
58-
\sprintf('Expected an array (%s).', $this->index)
54+
throw new TypeError(
55+
sprintf('Expected an array (%s).', $this->index)
5956
);
6057
}
6158
if (!is_null($this->indexPolicy)) {
6259
$keys = array_keys($data);
6360
foreach ($keys as $arrayKey) {
6461
if (!$this->indexPolicy->indexIsValid($arrayKey)) {
65-
throw new \TypeError(
66-
\sprintf("Invalid key (%s) in violation of key policy", $arrayKey)
62+
throw new TypeError(
63+
sprintf("Invalid key (%s) in violation of key policy", $arrayKey)
6764
);
6865
}
6966
}

src/Filter/BoolArrayFilter.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
use ParagonIE\Ionizer\InvalidDataException;
66
use ParagonIE\Ionizer\Util;
7+
use ReturnTypeWillChange;
8+
use TypeError;
9+
use function is_array;
10+
use function is_null;
11+
use function sprintf;
712

813
/**
914
* Class BoolArrayFilter
@@ -14,35 +19,33 @@ class BoolArrayFilter extends ArrayFilter
1419
/**
1520
* @var string
1621
*/
17-
protected $type = 'bool[]';
22+
protected string $type = 'bool[]';
1823

1924
/**
2025
* Apply all of the callbacks for this filter.
2126
*
2227
* @param mixed $data
2328
* @param int $offset
2429
* @return mixed
25-
* @throws \TypeError
30+
* @throws TypeError
2631
* @throws InvalidDataException
2732
*/
28-
public function applyCallbacks($data = null, int $offset = 0)
33+
#[ReturnTypeWillChange]
34+
public function applyCallbacks($data = null, int $offset = 0): array
2935
{
3036
if ($offset === 0) {
31-
if (\is_null($data)) {
37+
if (is_null($data)) {
3238
return parent::applyCallbacks($data, 0);
33-
} elseif (!\is_array($data)) {
34-
throw new \TypeError(
35-
\sprintf('Expected an array of booleans (%s).', $this->index)
39+
} elseif (!is_array($data)) {
40+
throw new TypeError(
41+
sprintf('Expected an array of booleans (%s).', $this->index)
3642
);
3743
}
38-
/**
39-
* @var array<mixed, array<mixed, mixed>>
40-
*/
4144
$data = (array) $data;
4245

4346
if (!Util::is1DArray($data)) {
44-
throw new \TypeError(
45-
\sprintf('Expected a 1-dimensional array (%s).', $this->index)
47+
throw new TypeError(
48+
sprintf('Expected a 1-dimensional array (%s).', $this->index)
4649
);
4750
}
4851
/**
@@ -51,9 +54,9 @@ public function applyCallbacks($data = null, int $offset = 0)
5154
* @var string|int|float|bool|array|null $val
5255
*/
5356
foreach ($data as $key => $val) {
54-
if (\is_array($val)) {
55-
throw new \TypeError(
56-
\sprintf('Expected a 1-dimensional array (%s).', $this->index)
57+
if (is_array($val)) {
58+
throw new TypeError(
59+
sprintf('Expected a 1-dimensional array (%s).', $this->index)
5760
);
5861
}
5962
$data[$key] = !empty($val);

src/Filter/BoolFilter.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use ParagonIE\Ionizer\Contract\FilterInterface;
66
use ParagonIE\Ionizer\InputFilter;
77
use ParagonIE\Ionizer\InvalidDataException;
8+
use ReturnTypeWillChange;
9+
use TypeError;
10+
use function is_array;
11+
use function sprintf;
812

913
/**
1014
* Class BoolFilter
@@ -15,26 +19,27 @@ class BoolFilter extends InputFilter
1519
/**
1620
* @var mixed
1721
*/
18-
protected $default = false;
22+
protected mixed $default = false;
1923

2024
/**
2125
* @var string
2226
*/
23-
protected $type = 'bool';
27+
protected string $type = 'bool';
2428

2529
/**
2630
* Process data using the filter rules.
2731
*
2832
* @param mixed $data
2933
* @return bool
30-
* @throws \TypeError
34+
* @throws TypeError
3135
* @throws InvalidDataException
3236
*/
33-
public function process($data = null)
37+
#[ReturnTypeWillChange]
38+
public function process(mixed $data = null): bool
3439
{
35-
if (\is_array($data)) {
36-
throw new \TypeError(
37-
\sprintf('Unexpected array for boolean filter (%s).', $this->index)
40+
if (is_array($data)) {
41+
throw new TypeError(
42+
sprintf('Unexpected array for boolean filter (%s).', $this->index)
3843
);
3944
}
4045
return (bool) parent::process(!empty($data));
@@ -45,12 +50,12 @@ public function process($data = null)
4550
*
4651
* @param string $typeIndicator
4752
* @return FilterInterface
48-
* @throws \TypeError
53+
* @throws TypeError
4954
*/
5055
public function setType(string $typeIndicator): FilterInterface
5156
{
5257
if ($typeIndicator !== 'bool') {
53-
throw new \TypeError(
58+
throw new TypeError(
5459
'Type must always be set to "bool".'
5560
);
5661
}

0 commit comments

Comments
 (0)