Skip to content

Commit 6ba1780

Browse files
committed
up: update some for run on php8.4
1 parent 01afddf commit 6ba1780

15 files changed

+47
-59
lines changed

.github/workflows/php.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ on:
1111

1212
jobs:
1313
test:
14-
name: Test on php ${{ matrix.php}} and ${{ matrix.os }}
15-
runs-on: ${{ matrix.os }}
14+
name: Test on php ${{ matrix.php}}
15+
runs-on: ubuntu-latest
1616
timeout-minutes: 10
1717
strategy:
1818
fail-fast: true
1919
matrix:
20-
php: [ 8.1, 8.2] # 7.1, 7.2,
21-
os: [ubuntu-latest] # windows-latest, macOS-latest
20+
php: [ 8.1, 8.2, 8.3, 8.4] # 7.1, 7.2,
2221

2322
steps:
2423
- name: Checkout
25-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2625

2726
# usage refer https://github.com/shivammathur/setup-php
2827
- name: Setup PHP
@@ -46,4 +45,4 @@ jobs:
4645

4746
- name: Run unit tests
4847
# run: composer run test
49-
run: phpunit -vv
48+
run: phpunit

.github/workflows/release.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ on:
77

88
jobs:
99
release:
10-
name: Test on php ${{ matrix.php}}
10+
name: New tag release
1111
runs-on: ubuntu-latest
1212
timeout-minutes: 10
1313
strategy:
1414
fail-fast: true
15-
matrix:
16-
php: [8.1]
1715

1816
steps:
1917
- name: Checkout
20-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
2119
with:
2220
fetch-depth: 0
2321

@@ -35,7 +33,7 @@ jobs:
3533
3634
# https://github.com/softprops/action-gh-release
3735
- name: Create release and upload assets
38-
uses: softprops/action-gh-release@v1
36+
uses: softprops/action-gh-release@v2
3937
env:
4038
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4139
with:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ composer.lock
1212
*.swo
1313
.DS_Store
1414
.phpunit.result.cache
15+
*.cache

README.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PHP Validate
22

33
[![License](https://img.shields.io/packagist/l/inhere/php-validate.svg?style=flat-square)](LICENSE)
4-
[![Php Version](https://img.shields.io/badge/php-%3E=8.1-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/php-validate)
4+
[![Php Version](https://img.shields.io/packagist/php-v/inhere/php-validate?maxAge=2592000)](https://packagist.org/packages/inhere/php-validate)
55
[![Latest Stable Version](http://img.shields.io/packagist/v/inhere/php-validate.svg)](https://packagist.org/packages/inhere/php-validate)
66
[![Coverage Status](https://coveralls.io/repos/github/inhere/php-validate/badge.svg?branch=master)](https://coveralls.io/github/inhere/php-validate?branch=master)
77
[![Github Actions Status](https://github.com/inhere/php-validate/workflows/Unit-tests/badge.svg)](https://github.com/inhere/php-validate/actions)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PHP Validate
22

33
[![License](https://img.shields.io/packagist/l/inhere/php-validate.svg?style=flat-square)](LICENSE)
4-
[![Php Version](https://img.shields.io/badge/php-%3E=8.1-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/php-validate)
4+
[![Php Version](https://img.shields.io/packagist/php-v/inhere/php-validate?maxAge=2592000)](https://packagist.org/packages/inhere/php-validate)
55
[![Latest Stable Version](http://img.shields.io/packagist/v/inhere/php-validate.svg)](https://packagist.org/packages/inhere/php-validate)
66
[![Coverage Status](https://coveralls.io/repos/github/inhere/php-validate/badge.svg?branch=master)](https://coveralls.io/github/inhere/php-validate?branch=master)
77
[![Github Actions Status](https://github.com/inhere/php-validate/workflows/Unit-tests/badge.svg)](https://github.com/inhere/php-validate/actions)

composer.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
"php": ">8.1.0",
2323
"toolkit/stdlib": "~2.0"
2424
},
25-
"require-dev": {
26-
"phpunit/phpunit": "^9.5"
27-
},
25+
"require-dev": {},
2826
"autoload": {
2927
"psr-4": {
3028
"Inhere\\Validate\\": "src/"

phpunit.xml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" backupGlobals="false" bootstrap="test/bootstrap.php" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.1/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Php Package Test Suite">
5+
<directory>test</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">src</directory>
11+
</include>
12+
</source>
13+
</phpunit>

phpunit.xml.dist

-23
This file was deleted.

src/AbstractValidation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class AbstractValidation implements ValidationInterface
2626
/**
2727
* @var array
2828
*/
29-
protected $data = [];
29+
protected array $data = [];
3030

3131
/**
3232
* @param array $data

src/Filter/Filters.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static function abs(mixed $val): int
156156
*
157157
* @return int|float
158158
*/
159-
public static function float(mixed $val, int $decimal = null, int|string $flags = FILTER_FLAG_ALLOW_FRACTION): int|float
159+
public static function float(mixed $val, ?int $decimal = null, int|string $flags = FILTER_FLAG_ALLOW_FRACTION): int|float
160160
{
161161
$options = (int)$flags !== 0 ? ['flags' => (int)$flags] : [];
162162

@@ -509,7 +509,7 @@ public static function str2array(string $string, string $delimiter = ',', int $l
509509
*
510510
* @return string
511511
*/
512-
public static function clearTags(mixed $val, string $allowedTags = null): string
512+
public static function clearTags(mixed $val, ?string $allowedTags = null): string
513513
{
514514
return self::stripTags($val, $allowedTags);
515515
}
@@ -520,7 +520,7 @@ public static function clearTags(mixed $val, string $allowedTags = null): string
520520
*
521521
* @return string
522522
*/
523-
public static function stripTags(mixed $val, string $allowedTags = null): string
523+
public static function stripTags(mixed $val, ?string $allowedTags = null): string
524524
{
525525
if (!$val || !is_string($val)) {
526526
return '';

src/Simple/ValidData.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function reset(): void
8080
*
8181
* @return int
8282
*/
83-
public static function getInt(string $field, int $min = null, ?int $max = null, ?int $default = null): int
83+
public static function getInt(string $field, ?int $min = null, ?int $max = null, ?int $default = null): int
8484
{
8585
if (!isset(self::$data[$field])) {
8686
if ($default === null) {
@@ -110,7 +110,7 @@ public static function getInt(string $field, int $min = null, ?int $max = null,
110110
*
111111
* @return array
112112
*/
113-
public static function getInts(string $field, int $min = null, int $max = null, array $default = null): array
113+
public static function getInts(string $field, ?int $min = null, ?int $max = null, ?array $default = null): array
114114
{
115115
$arr = self::getArray($field, $min, $max, $default);
116116

@@ -126,7 +126,7 @@ public static function getInts(string $field, int $min = null, int $max = null,
126126
*
127127
* @return array
128128
*/
129-
public static function getIntsBySplit(string $field, int $min = null, int $max = null, array $default = null, string $sep = ','): array
129+
public static function getIntsBySplit(string $field, ?int $min = null, ?int $max = null, ?array $default = null, string $sep = ','): array
130130
{
131131
$arr = self::getArrayBySplit($field, $min, $max, $default, $sep);
132132

@@ -141,7 +141,7 @@ public static function getIntsBySplit(string $field, int $min = null, int $max =
141141
*
142142
* @return float
143143
*/
144-
public static function getFloat(string $field, float $min = null, float $max = null, float $default = null): float
144+
public static function getFloat(string $field, ?float $min = null, ?float $max = null, ?float $default = null): float
145145
{
146146
if (!isset(self::$data[$field])) {
147147
if ($default === null) {
@@ -173,7 +173,7 @@ public static function getFloat(string $field, float $min = null, float $max = n
173173
*
174174
* @return string
175175
*/
176-
public static function getString(string $field, int $minLen = null, int $maxLen = null, string $default = null): string
176+
public static function getString(string $field, ?int $minLen = null, ?int $maxLen = null, ?string $default = null): string
177177
{
178178
if (!isset(self::$data[$field])) {
179179
if ($default === null) {
@@ -206,7 +206,7 @@ public static function getString(string $field, int $minLen = null, int $maxLen
206206
*
207207
* @return array
208208
*/
209-
public static function getStrings(string $field, int $min = null, int $max = null, array $default = null): array
209+
public static function getStrings(string $field, ?int $min = null, ?int $max = null, ?array $default = null): array
210210
{
211211
if (!isset(self::$data[$field])) {
212212
if ($default === null) {
@@ -244,7 +244,7 @@ public static function getStrings(string $field, int $min = null, int $max = nul
244244
*
245245
* @return array
246246
*/
247-
public static function getArray(string $field, int $min = null, int $max = null, array $default = null): array
247+
public static function getArray(string $field, ?int $min = null, ?int $max = null, ?array $default = null): array
248248
{
249249
if (!isset(self::$data[$field])) {
250250
if ($default === null) {
@@ -280,7 +280,7 @@ public static function getArray(string $field, int $min = null, int $max = null,
280280
*
281281
* @return array
282282
*/
283-
public static function getArrayBySplit(string $field, int $min = null, int $max = null, array $default = null, string $sep = ','): array
283+
public static function getArrayBySplit(string $field, ?int $min = null, ?int $max = null, ?array $default = null, string $sep = ','): array
284284
{
285285
if (!isset(self::$data[$field])) {
286286
if ($default === null) {
@@ -315,7 +315,7 @@ public static function getArrayBySplit(string $field, int $min = null, int $max
315315
*
316316
* @return array
317317
*/
318-
public static function getArrayByJSON(string $field, int $min = null, int $max = null, array $default = null): array
318+
public static function getArrayByJSON(string $field, ?int $min = null, ?int $max = null, ?array $default = null): array
319319
{
320320
if (!isset(self::$data[$field])) {
321321
if ($default === null) {
@@ -359,7 +359,7 @@ public static function getArrayByJSON(string $field, int $min = null, int $max =
359359
*
360360
* @return string
361361
*/
362-
public static function fmtMinMaxToMsg(string $prefix, int $min = null, int $max = null, string $sepMsg = 'and'): string
362+
public static function fmtMinMaxToMsg(string $prefix, ?int $min = null, ?int $max = null, string $sepMsg = 'and'): string
363363
{
364364
if ($min !== null && $max !== null) {
365365
return "$prefix $sepMsg must be >= $min and <= $max";

src/Traits/NameAliasTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
trait NameAliasTrait
1717
{
18-
/** @var array Name aliases map. please define on main-class */
18+
/* var array Name aliases map. please define on main-class */
1919
// protected static $aliases = [];
2020

2121
/**

src/Traits/ScopedValidatorsTrait.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
namespace Inhere\Validate\Traits;
1010

11+
use Inhere\Validate\AbstractValidation;
1112
use Inhere\Validate\Filter\Filters;
1213
use Inhere\Validate\Helper;
1314
use Inhere\Validate\Validators;
15+
use Inhere\ValidateTest\Example\DataModel;
1416
use InvalidArgumentException;
1517
use function array_shift;
1618
use function function_exists;
@@ -33,7 +35,7 @@
3335
*/
3436
trait ScopedValidatorsTrait
3537
{
36-
/** @var array user custom add's validators(current scope) */
38+
/** @var array user custom adds validators(current scope) */
3739
protected array $_validators = [];
3840

3941
/**
@@ -61,7 +63,7 @@ trait ScopedValidatorsTrait
6163
* @param callable $callback
6264
* @param string $message
6365
*
64-
* @return $this
66+
* @return AbstractValidation|ScopedValidatorsTrait|DataModel
6567
*/
6668
public function addValidator(string $name, callable $callback, string $message = ''): self
6769
{
@@ -75,7 +77,7 @@ public function addValidator(string $name, callable $callback, string $message =
7577
* @param callable $callback
7678
* @param string $message
7779
*
78-
* @return self
80+
* @return static
7981
*/
8082
public function setValidator(string $name, callable $callback, string $message = ''): self
8183
{

src/ValidationInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function translates(): array;
4040
*
4141
* @return static
4242
*/
43-
public function validate(array $onlyChecked = [], bool $stopOnError = null): static;
43+
public function validate(array $onlyChecked = [], ?bool $stopOnError = null): static;
4444

4545
/**
4646
* alias of the fail()

src/ValidationTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function afterValidate(): void
198198
*
199199
* @return static
200200
*/
201-
public function validate(array $onlyChecked = [], bool $stopOnError = null): static
201+
public function validate(array $onlyChecked = [], ?bool $stopOnError = null): static
202202
{
203203
if (!property_exists($this, 'data')) {
204204
throw new InvalidArgumentException('Must be defined property "data"(array) in the sub-class used.');

0 commit comments

Comments
 (0)