Skip to content

Commit 5bbc948

Browse files
committed
PHP 8.1 syntax with Rector
1 parent 5aae42f commit 5bbc948

20 files changed

+34
-98
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
'mb_str_functions' => true,
9090
'method_argument_space' => true,
9191
'method_chaining_indentation' => true,
92-
'modernize_strpos' => false, // Require PHP 8.0
92+
'modernize_strpos' => true,
9393
'modernize_types_casting' => true,
9494
'multiline_comment_opening_closing' => true,
9595
'multiline_whitespace_before_semicolons' => true,

src/Acl/Acl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function reject(string $reason): bool
6363

6464
private function getClass(Model $resource): string
6565
{
66-
return ClassUtils::getRealClass(get_class($resource));
66+
return ClassUtils::getRealClass($resource::class);
6767
}
6868

6969
private function getCurrentRole(): string

src/Acl/Assertion/All.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class All implements AssertionInterface
1414
/**
1515
* @var AssertionInterface[]
1616
*/
17-
private array $asserts;
17+
private readonly array $asserts;
1818

1919
/**
2020
* Check if all asserts are true.

src/Acl/Assertion/One.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class One implements AssertionInterface
1414
/**
1515
* @var AssertionInterface[]
1616
*/
17-
private array $asserts;
17+
private readonly array $asserts;
1818

1919
/**
2020
* Check if at least one assert is true.

src/Acl/ModelResource.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,23 @@
2020
*/
2121
final class ModelResource extends GenericResource
2222
{
23-
/**
24-
* Unique id of the instance of resource.
25-
*/
26-
private ?Model $instance;
27-
2823
/**
2924
* Sets the Resource identifier.
3025
*
3126
* @param string $class must be a model class name
3227
* @param Model $instance the instance itself
3328
*/
34-
public function __construct(string $class, ?Model $instance = null)
35-
{
29+
public function __construct(
30+
string $class,
31+
private readonly ?Model $instance = null
32+
) {
3633
if (!is_subclass_of($class, Model::class)) {
3734
throw new InvalidArgumentException('The class name must be an implementation of Model but given: ' . $class);
3835
}
3936

4037
$class = ClassUtils::getRealClass($class);
4138

4239
parent::__construct($class);
43-
$this->instance = $instance;
4440
}
4541

4642
/**

src/Api/FilteredFieldResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
final class FilteredFieldResolver
1616
{
17-
private DefaultFieldResolver $resolver;
17+
private readonly DefaultFieldResolver $resolver;
1818

1919
public function __construct()
2020
{
@@ -51,7 +51,7 @@ private function load($object)
5151
if ($object instanceof Proxy) {
5252
try {
5353
$object->__load();
54-
} catch (EntityNotFoundException $exception) {
54+
} catch (EntityNotFoundException) {
5555
return null;
5656
}
5757
}

src/Api/Server.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
class Server
2222
{
23-
private StandardServer $server;
23+
private readonly StandardServer $server;
2424

25-
private ServerConfig $config;
25+
private readonly ServerConfig $config;
2626

2727
public function __construct(Schema $schema, bool $debug, array $rootValue = [])
2828
{
@@ -51,7 +51,7 @@ public function __construct(Schema $schema, bool $debug, array $rootValue = [])
5151
/**
5252
* @return ExecutionResult|ExecutionResult[]
5353
*/
54-
public function execute(ServerRequestInterface $request)
54+
public function execute(ServerRequestInterface $request): array|ExecutionResult
5555
{
5656
if (!$request->getParsedBody()) {
5757
/** @var array $parsedBody */
@@ -77,7 +77,7 @@ public function execute(ServerRequestInterface $request)
7777
*
7878
* @param ExecutionResult|ExecutionResult[] $result
7979
*/
80-
public function sendHttp($result): void
80+
public function sendHttp(array|ExecutionResult $result): void
8181
{
8282
$this->server->getHelper()->sendResponse($result);
8383
}

src/Handler/FileHandler.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212

1313
final class FileHandler extends AbstractHandler
1414
{
15-
private ObjectRepository $fileRepository;
16-
17-
public function __construct(ObjectRepository $fileRepository)
15+
public function __construct(private readonly ObjectRepository $fileRepository)
1816
{
19-
$this->fileRepository = $fileRepository;
2017
}
2118

2219
/**

src/Handler/GraphQLHandler.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212

1313
final class GraphQLHandler implements RequestHandlerInterface
1414
{
15-
private Server $server;
16-
17-
public function __construct(Server $server)
15+
public function __construct(private readonly Server $server)
1816
{
19-
$this->server = $server;
2017
}
2118

2219
/**

src/Handler/ImageHandler.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313

1414
final class ImageHandler extends AbstractHandler
1515
{
16-
private ObjectRepository $imageRepository;
17-
18-
private ImageResizer $imageResizer;
19-
20-
public function __construct(ObjectRepository $imageRepository, ImageResizer $imageService)
16+
public function __construct(private readonly ObjectRepository $imageRepository, private readonly ImageResizer $imageResizer)
2117
{
22-
$this->imageRepository = $imageRepository;
23-
$this->imageResizer = $imageService;
2418
}
2519

2620
/**
@@ -44,7 +38,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4438
$maxHeight = (int) $request->getAttribute('maxHeight');
4539
if ($maxHeight) {
4640
$accept = $request->getHeaderLine('accept');
47-
$useWebp = mb_strpos($accept, 'image/webp') !== false;
41+
$useWebp = str_contains($accept, 'image/webp');
4842

4943
$path = $this->imageResizer->resize($image, $maxHeight, $useWebp);
5044
}

0 commit comments

Comments
 (0)