Skip to content

Feature: uses PHP 7.4 syntax #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: '7.4'
coverage: none
tools: composer:v2

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"config": {
"platform": {
"php": "7.2"
"php": "7.4"
}
},
"repositories": [
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includes:

parameters:
# Level 5 is a good balance between strictness and practicality
level: 5
level: 6

# Paths to analyze
paths:
Expand All @@ -20,7 +20,7 @@ parameters:
# Add specific error patterns to ignore here if needed

# PHP version (must be an integer)
phpVersion: 70200
phpVersion: 70400

# Treat missing return types as mixed
treatPhpDocTypesAsCertain: false
8 changes: 4 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Config
*
* @param ContainerInterface $container
*/
public static function setServiceContainer($container)
public static function setServiceContainer($container): void
{
self::$container = $container;
}
Expand All @@ -74,7 +74,7 @@ public static function getHookPrefix(): string
/**
* @since 1.0.0
*/
public static function setHookPrefix(string $prefix)
public static function setHookPrefix(string $prefix): void
{
self::$hookPrefix = $prefix;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public static function getValidationExceptionClass(): string
*
* @param class-string<ValidationException> $validationExceptionClass
*/
public static function setValidationExceptionClass(string $validationExceptionClass)
public static function setValidationExceptionClass(string $validationExceptionClass): void
{
if (!is_a($validationExceptionClass, ValidationExceptionInterface::class, true)) {
throw new RuntimeException(
Expand Down Expand Up @@ -142,7 +142,7 @@ public static function getInvalidArgumentExceptionClass(): string
*
* @param class-string<InvalidArgumentException> $invalidArgumentExceptionClass
*/
public static function setInvalidArgumentExceptionClass(string $invalidArgumentExceptionClass)
public static function setInvalidArgumentExceptionClass(string $invalidArgumentExceptionClass): void
{
if (!is_a($invalidArgumentExceptionClass, InvalidArgumentException::class, true)) {
throw new RuntimeException(
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ValidatesOnFrontEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ValidatesOnFrontEnd
*
* @since 1.0.0
*
* @return int|float|string|bool|array|null
* @return mixed
*/
public function serializeOption();
}
5 changes: 5 additions & 0 deletions src/Contracts/ValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static function fromString(?string $options = null): ValidationRule;
* @since 1.2.0 add ExcludeValue return option
* @since 1.0.0
*
* @param mixed $value
* @param Closure $fail
* @param string $key
* @param array<string, mixed> $values
*
* @return void|ExcludeValue|SkipValidationRules
*/
public function __invoke($value, Closure $fail, string $key, array $values);
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/Abstracts/ConditionalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
namespace StellarWP\Validation\Rules\Abstracts;

use StellarWP\FieldConditions\ComplexConditionSet;
use StellarWP\FieldConditions\SimpleConditionSet;
use StellarWP\FieldConditions\Contracts\Condition;
use StellarWP\FieldConditions\Contracts\ConditionSet;
use StellarWP\FieldConditions\SimpleConditionSet;
use StellarWP\Validation\Config;
use StellarWP\Validation\Contracts\ValidatesOnFrontEnd;
use StellarWP\Validation\Contracts\ValidationRule;

abstract class ConditionalRule implements ValidationRule, ValidatesOnFrontEnd
{
/**
* @var ConditionSet
* @var SimpleConditionSet|ComplexConditionSet
*/
protected $conditions;
protected ConditionSet $conditions;

/**
* @param ConditionSet|Condition[] $conditions
* @param SimpleConditionSet|ComplexConditionSet|Condition[] $conditions
*/
public function __construct($conditions)
{
Expand Down
8 changes: 6 additions & 2 deletions src/Rules/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class In implements ValidationRule, ValidatesOnFrontEnd
{
/**
* @var array
* @var array<mixed>
*/
protected $acceptedValues;
protected array $acceptedValues;

/**
* @since 1.2.0
Expand All @@ -24,6 +24,8 @@ public static function id(): string

/**
* @since 1.2.0
*
* @param mixed ...$acceptedValues
*/
final public function __construct(...$acceptedValues)
{
Expand Down Expand Up @@ -64,6 +66,8 @@ public function __invoke($value, Closure $fail, string $key, array $values)

/**
* @since 1.2.0
*
* @return array<mixed>
*/
public function serializeOption(): array
{
Expand Down
7 changes: 5 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

class ServiceProvider
{
private $validationRules = [
/**
* @var array<class-string>
*/
private array $validationRules = [
Required::class,
Min::class,
Max::class,
Expand All @@ -55,7 +58,7 @@ class ServiceProvider
/**
* Registers the validation rules registrar with the container
*/
public function register()
public function register(): void
{
Config::getServiceContainer()->singleton(ValidationRulesRegistrar::class, function () {
$register = new ValidationRulesRegistrar();
Expand Down
12 changes: 7 additions & 5 deletions src/ValidationRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
use StellarWP\Validation\Contracts\ValidationRule;
use Traversable;

/**
* @implements IteratorAggregate<int, ValidationRule|Closure>
*/
class ValidationRuleSet implements IteratorAggregate, JsonSerializable
{
/**
* @var ValidationRulesRegistrar
*/
private $register;
private ValidationRulesRegistrar $register;

/**
* @var array<int, ValidationRule|Closure>
*/
private $rules = [];
private array $rules = [];

/**
* @since 1.0.0
Expand Down Expand Up @@ -168,6 +168,8 @@ public function removeRuleWithId(string $id): self
* Returns the validation rules.
*
* @since 1.0.0
*
* @return array<int, ValidationRule|Closure>
*/
public function getRules(): array
{
Expand Down
6 changes: 4 additions & 2 deletions src/ValidationRulesRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
*/
class ValidationRulesRegistrar
{
/** @var array */
protected $rules = [];
/**
* @var array<string, class-string<ValidationRule>>
*/
protected array $rules = [];

/**
* Register one or many validation rules.
Expand Down
23 changes: 13 additions & 10 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use StellarWP\Validation\Commands\ExcludeValue;
use StellarWP\Validation\Commands\SkipValidationRules;
use StellarWP\Validation\Contracts\Sanitizer;
use StellarWP\Validation\Contracts\ValidationRule;
use Closure;

/**
* A tool for taking in a set of values and corresponding validation rules, and then validating the values.
Expand All @@ -18,38 +20,39 @@ class Validator
/**
* @var array<string, ValidationRuleSet>
*/
private $ruleSets;
private array $ruleSets;

/**
* @var array<string, mixed>
*/
private $values;
private array $values;

/**
* @var array<string, string>
*/
private $labels;
private array $labels;

/**
* @var array<string, string>
*/
private $errors = [];
private array $errors = [];

/**
* @var array<string, mixed>
*/
private $validatedValues = [];
private array $validatedValues = [];

/**
* @var bool
*/
private $ranValidationRules = false;
private bool $ranValidationRules = false;

/**
* @since 1.0.0
*
* @param array<string, ValidationRuleSet|array> $ruleSets
* @param array<string, ValidationRuleSet|array<string|ValidationRule|Closure>> $ruleSets
* @param array<string, mixed> $values
* @param array<string, string> $labels
*/
public function __construct(array $ruleSets, array $values, array $labels = [])
{
Expand Down Expand Up @@ -98,10 +101,8 @@ public function passes(): bool
* Will run only once, and then store the results for subsequent calls.
*
* @since 1.0.0
*
* @return void
*/
private function runValidationRules()
private function runValidationRules(): void
{
if ($this->ranValidationRules) {
return;
Expand Down Expand Up @@ -156,6 +157,8 @@ public function errors(): array
* Returns the validated values, with any sanitization rules applied.
*
* @since 1.0.0
*
* @return array<string, mixed>
*/
public function validated(): array
{
Expand Down