More PHP8.4 updates

This commit is contained in:
James Cole
2025-05-04 13:47:00 +02:00
parent e42107c03c
commit 51e86448c7
195 changed files with 524 additions and 715 deletions

View File

@@ -42,14 +42,11 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class BelongsUserGroup implements ValidationRule
{
private UserGroup $userGroup;
/**
* Create a new rule instance.
*/
public function __construct(UserGroup $userGroup)
public function __construct(private readonly UserGroup $userGroup)
{
$this->userGroup = $userGroup;
}
public function validate(string $attribute, mixed $value, \Closure $fail): void

View File

@@ -35,14 +35,10 @@ use Illuminate\Support\Facades\Log;
class IsAllowedGroupAction implements ValidationRule
{
private array $acceptedRoles;
private string $className;
private string $methodName;
private UserGroupRepositoryInterface $repository;
private readonly UserGroupRepositoryInterface $repository;
public function __construct(string $className, string $methodName)
public function __construct(private readonly string $className, private readonly string $methodName)
{
$this->className = $className;
$this->methodName = $methodName;
// you need these roles to do anything with any endpoint.
$this->acceptedRoles = [UserRoleEnum::OWNER, UserRoleEnum::FULL];
$this->repository = app(UserGroupRepositoryInterface::class);

View File

@@ -34,11 +34,8 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class IsDefaultUserGroupName implements ValidationRule
{
private UserGroup $userGroup;
public function __construct(UserGroup $userGroup)
public function __construct(private readonly UserGroup $userGroup)
{
$this->userGroup = $userGroup;
}
/**

View File

@@ -28,13 +28,8 @@ use Illuminate\Contracts\Validation\ValidationRule;
class IsFilterValueIn implements ValidationRule
{
private string $key;
private array $values;
public function __construct(string $key, array $values)
public function __construct(private readonly string $key, private readonly array $values)
{
$this->key = $key;
$this->values = $values;
}
/**

View File

@@ -47,7 +47,7 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class IsValidAttachmentModel implements ValidationRule
{
private string $model;
private readonly string $model;
/**
* IsValidAttachmentModel constructor.

View File

@@ -64,7 +64,7 @@ class IsValidBulkClause implements ValidationRule
{
try {
$array = \Safe\json_decode($value, true, 8, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
} catch (\JsonException) {
$this->error = (string) trans('validation.json');
return false;

View File

@@ -32,11 +32,9 @@ use Illuminate\Support\Facades\Log;
class IsValidZeroOrMoreAmount implements ValidationRule
{
use ValidatesAmountsTrait;
private bool $nullable = false;
public function __construct(bool $nullable = false)
public function __construct(private bool $nullable = false)
{
$this->nullable = $nullable;
}
/**

View File

@@ -34,27 +34,22 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class UniqueAccountNumber implements ValidationRule
{
private ?Account $account;
private ?string $expectedType;
/**
* Create a new rule instance.
*/
public function __construct(?Account $account, ?string $expectedType)
public function __construct(private readonly ?Account $account, private ?string $expectedType)
{
app('log')
->debug('Constructed UniqueAccountNumber')
;
$this->account = $account;
$this->expectedType = $expectedType;
// a very basic fix to make sure we get the correct account type:
if ('expense' === $expectedType) {
if ('expense' === $this->expectedType) {
$this->expectedType = AccountTypeEnum::EXPENSE->value;
}
if ('revenue' === $expectedType) {
if ('revenue' === $this->expectedType) {
$this->expectedType = AccountTypeEnum::REVENUE->value;
}
if ('asset' === $expectedType) {
if ('asset' === $this->expectedType) {
$this->expectedType = AccountTypeEnum::ASSET->value;
}
app('log')->debug(sprintf('Expected type is "%s"', $this->expectedType));

View File

@@ -34,15 +34,13 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/
class UniqueIban implements ValidationRule
{
private ?Account $account;
private array $expectedTypes;
/**
* Create a new rule instance.
*/
public function __construct(?Account $account, ?string $expectedType)
public function __construct(private readonly ?Account $account, ?string $expectedType)
{
$this->account = $account;
$this->expectedTypes = [];
if (null === $expectedType) {
return;