Skip to content

Commit 4cc43fb

Browse files
committed
refactor: apply ClassPropertyAssignToConstructorPromotionRector and manual tweaks
1 parent 9590def commit 4cc43fb

13 files changed

+115
-205
lines changed

system/Autoloader/FileLocatorCached.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
*/
2222
final class FileLocatorCached implements FileLocatorInterface
2323
{
24-
private readonly FileLocator $locator;
25-
2624
/**
2725
* @var CacheInterface|FileVarExportHandler
2826
*/
@@ -49,10 +47,11 @@ final class FileLocatorCached implements FileLocatorInterface
4947
/**
5048
* @param CacheInterface|FileVarExportHandler|null $cache
5149
*/
52-
public function __construct(FileLocator $locator, $cache = null)
53-
{
50+
public function __construct(
51+
private readonly FileLocator $locator,
52+
$cache = null
53+
) {
5454
$this->cacheHandler = $cache ?? new FileVarExportHandler();
55-
$this->locator = $locator;
5655

5756
$this->loadCache();
5857
}

system/Cache/ResponseCache.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ final class ResponseCache
4747
*/
4848
private int $ttl = 0;
4949

50-
private readonly CacheInterface $cache;
51-
52-
public function __construct(CacheConfig $config, CacheInterface $cache)
53-
{
50+
public function __construct(
51+
CacheConfig $config,
52+
private readonly CacheInterface $cache
53+
) {
5454
$this->cacheQueryString = $config->cacheQueryString;
55-
$this->cache = $cache;
5655
}
5756

5857
/**

system/Commands/Utilities/Routes/AutoRouteCollector.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818
*/
1919
final class AutoRouteCollector
2020
{
21-
/**
22-
* @var string namespace to search
23-
*/
24-
private readonly string $namespace;
25-
26-
private readonly string $defaultController;
27-
private readonly string $defaultMethod;
28-
2921
/**
3022
* @param string $namespace namespace to search
3123
*/
32-
public function __construct(string $namespace, string $defaultController, string $defaultMethod)
33-
{
34-
$this->namespace = $namespace;
35-
$this->defaultController = $defaultController;
36-
$this->defaultMethod = $defaultMethod;
24+
public function __construct(
25+
/**
26+
* @var string namespace to search
27+
*/
28+
private readonly string $namespace,
29+
private readonly string $defaultController,
30+
private readonly string $defaultMethod
31+
) {
3732
}
3833

3934
/**

system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,25 @@
2121
*/
2222
final class AutoRouteCollector
2323
{
24-
/**
25-
* @var string namespace to search
26-
*/
27-
private readonly string $namespace;
28-
29-
private readonly string $defaultController;
30-
private readonly string $defaultMethod;
31-
private readonly array $httpMethods;
32-
33-
/**
34-
* List of controllers in Defined Routes that should not be accessed via Auto-Routing.
35-
*
36-
* @var class-string[]
37-
*/
38-
private readonly array $protectedControllers;
39-
40-
/**
41-
* @var string URI prefix for Module Routing
42-
*/
43-
private string $prefix;
44-
45-
/**
46-
* @param string $namespace namespace to search
47-
*/
4824
public function __construct(
49-
string $namespace,
50-
string $defaultController,
51-
string $defaultMethod,
52-
array $httpMethods,
53-
array $protectedControllers,
54-
string $prefix = ''
25+
/**
26+
* @var string namespace to search
27+
*/
28+
private readonly string $namespace,
29+
private readonly string $defaultController,
30+
private readonly string $defaultMethod,
31+
private readonly array $httpMethods,
32+
/**
33+
* List of controllers in Defined Routes that should not be accessed via Auto-Routing.
34+
*
35+
* @var class-string[]
36+
*/
37+
private readonly array $protectedControllers,
38+
/**
39+
* @var string URI prefix for Module Routing
40+
*/
41+
private string $prefix = ''
5542
) {
56-
$this->namespace = $namespace;
57-
$this->defaultController = $defaultController;
58-
$this->defaultMethod = $defaultMethod;
59-
$this->httpMethods = $httpMethods;
60-
$this->protectedControllers = $protectedControllers;
61-
$this->prefix = $prefix;
6243
}
6344

6445
/**

system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,16 @@
2121
*/
2222
final class ControllerMethodReader
2323
{
24-
/**
25-
* @var string the default namespace
26-
*/
27-
private readonly string $namespace;
28-
29-
/**
30-
* @var list<string>
31-
*/
32-
private readonly array $httpMethods;
33-
34-
/**
35-
* @param string $namespace the default namespace
36-
*/
37-
public function __construct(string $namespace, array $httpMethods)
38-
{
39-
$this->namespace = $namespace;
40-
$this->httpMethods = $httpMethods;
24+
public function __construct(
25+
/**
26+
* @var string $namespace the default namespace
27+
*/
28+
private readonly string $namespace,
29+
/**
30+
* list<string>
31+
*/
32+
private readonly array $httpMethods
33+
) {
4134
}
4235

4336
/**

system/Commands/Utilities/Routes/ControllerFinder.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,15 @@
2121
*/
2222
final class ControllerFinder
2323
{
24-
/**
25-
* @var string namespace to search
26-
*/
27-
private readonly string $namespace;
28-
2924
private readonly FileLocatorInterface $locator;
3025

31-
/**
32-
* @param string $namespace namespace to search
33-
*/
34-
public function __construct(string $namespace)
35-
{
36-
$this->namespace = $namespace;
37-
$this->locator = Services::locator();
26+
public function __construct(
27+
/**
28+
* @var string namespace to search
29+
*/
30+
private readonly string $namespace
31+
) {
32+
$this->locator = Services::locator();
3833
}
3934

4035
/**

system/Commands/Utilities/Routes/ControllerMethodReader.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@
2121
*/
2222
final class ControllerMethodReader
2323
{
24-
/**
25-
* @var string the default namespace
26-
*/
27-
private readonly string $namespace;
28-
29-
/**
30-
* @param string $namespace the default namespace
31-
*/
32-
public function __construct(string $namespace)
33-
{
34-
$this->namespace = $namespace;
24+
public function __construct(
25+
/**
26+
* @var string $namespace the default namespace
27+
*/
28+
private readonly string $namespace
29+
) {
3530
}
3631

3732
/**

system/Commands/Utilities/Routes/FilterCollector.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424
*/
2525
final class FilterCollector
2626
{
27-
/**
28-
* Whether to reset Defined Routes.
29-
*
30-
* If set to true, route filters are not found.
31-
*/
32-
private readonly bool $resetRoutes;
33-
34-
public function __construct(bool $resetRoutes = false)
35-
{
36-
$this->resetRoutes = $resetRoutes;
27+
public function __construct(
28+
/**
29+
* Whether to reset Defined Routes.
30+
*
31+
* If set to true, route filters are not found.
32+
*/
33+
private readonly bool $resetRoutes = false
34+
) {
3735
}
3836

3937
/**

system/HTTP/SiteURIFactory.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
*/
2525
final class SiteURIFactory
2626
{
27-
private readonly App $appConfig;
28-
private readonly Superglobals $superglobals;
29-
30-
public function __construct(App $appConfig, Superglobals $superglobals)
31-
{
32-
$this->appConfig = $appConfig;
33-
$this->superglobals = $superglobals;
27+
public function __construct(
28+
private readonly App $appConfig,
29+
private readonly Superglobals $superglobals
30+
) {
3431
}
3532

3633
/**

system/Router/AutoRouter.php

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,60 +19,41 @@
1919
*/
2020
final class AutoRouter implements AutoRouterInterface
2121
{
22-
/**
23-
* List of CLI routes that do not contain '*' routes.
24-
*
25-
* @var array<string, Closure|string> [routeKey => handler]
26-
*/
27-
private readonly array $cliRoutes;
28-
2922
/**
3023
* Sub-directory that contains the requested controller class.
3124
* Primarily used by 'autoRoute'.
3225
*/
3326
private ?string $directory = null;
3427

35-
/**
36-
* The name of the controller class.
37-
*/
38-
private string $controller;
39-
40-
/**
41-
* The name of the method to use.
42-
*/
43-
private string $method;
44-
45-
/**
46-
* Whether dashes in URI's should be converted
47-
* to underscores when determining method names.
48-
*/
49-
private bool $translateURIDashes;
50-
51-
/**
52-
* HTTP verb for the request.
53-
*/
54-
private readonly string $httpVerb;
55-
56-
/**
57-
* Default namespace for controllers.
58-
*/
59-
private readonly string $defaultNamespace;
60-
6128
public function __construct(
62-
array $cliRoutes,
63-
string $defaultNamespace,
64-
string $defaultController,
65-
string $defaultMethod,
66-
bool $translateURIDashes,
67-
string $httpVerb
29+
/**
30+
* List of CLI routes that do not contain '*' routes.
31+
*
32+
* @var array<string, Closure|string> [routeKey => handler]
33+
*/
34+
private readonly array $cliRoutes,
35+
/**
36+
* Default namespace for controllers.
37+
*/
38+
private readonly string $defaultNamespace,
39+
/**
40+
* The name of the controller class.
41+
*/
42+
private string $controller,
43+
/**
44+
* The name of the method to use.
45+
*/
46+
private string $method,
47+
/**
48+
* Whether dashes in URI's should be converted
49+
* to underscores when determining method names.
50+
*/
51+
private bool $translateURIDashes,
52+
/**
53+
* HTTP verb for the request.
54+
*/
55+
private readonly string $httpVerb
6856
) {
69-
$this->cliRoutes = $cliRoutes;
70-
$this->defaultNamespace = $defaultNamespace;
71-
$this->translateURIDashes = $translateURIDashes;
72-
$this->httpVerb = $httpVerb;
73-
74-
$this->controller = $defaultController;
75-
$this->method = $defaultMethod;
7657
}
7758

7859
/**

0 commit comments

Comments
 (0)