Skip to content

Commit 4f9d165

Browse files
authored
refactor: make BaseService and BaseCollector abstract (#10531)
* refactor: make `BaseService` and `BaseCollector` abstract * class pattern on 2nd arg * cs fix * no need new layer, use existing Source
1 parent ba5b218 commit 4f9d165

5 files changed

Lines changed: 36 additions & 29 deletions

File tree

‎.php-cs-fixer.dist.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
__DIR__ . '/.php-cs-fixer.user-guide.php',
3434
__DIR__ . '/preload.php',
3535
__DIR__ . '/rector.php',
36+
__DIR__ . '/structarmed.php',
3637
__DIR__ . '/spark',
3738
]);
3839

‎structarmed.php‎

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,39 @@
1010
* For the full copyright and license information, please view
1111
* the LICENSE file that was distributed with this source code.
1212
*/
13-
use Boundwize\StructArmed\Rule\Rules\Function_\MustHaveReturnTypeFunctionRule;
13+
14+
use Boundwize\StructArmed\Architecture;
15+
use Boundwize\StructArmed\Preset\Preset;
1416
use Boundwize\StructArmed\Preset\Presets\CodeQualityPreset;
17+
use Boundwize\StructArmed\Preset\Presets\Psr4Preset;
18+
use Boundwize\StructArmed\Rule\Rules\Class_\ExtendedClassMustBeAbstractOrInstantiatedRule;
19+
use Boundwize\StructArmed\Rule\Rules\Function_\MustHaveReturnTypeFunctionRule;
1520
use CodeIgniter\Cache\ResponseCache;
21+
use CodeIgniter\Database\BaseResult;
22+
use CodeIgniter\DataCaster\DataCaster;
23+
use CodeIgniter\DataConverter\DataConverter;
24+
use CodeIgniter\Entity\Cast\CastInterface;
25+
use CodeIgniter\Entity\Cast\URICast;
26+
use CodeIgniter\Entity\Entity;
27+
use CodeIgniter\Entity\Exceptions\CastException;
1628
use CodeIgniter\HTTP\CLIRequest;
29+
use CodeIgniter\HTTP\DownloadResponse;
1730
use CodeIgniter\HTTP\Header;
1831
use CodeIgniter\HTTP\IncomingRequest;
32+
use CodeIgniter\HTTP\RedirectResponse;
33+
use CodeIgniter\HTTP\Response;
34+
use CodeIgniter\HTTP\ResponseInterface;
35+
use CodeIgniter\HTTP\ResponseTrait;
1936
use CodeIgniter\HTTP\SSEResponse;
2037
use CodeIgniter\HTTP\StreamResponse;
21-
use CodeIgniter\HTTP\ResponseInterface;
22-
use CodeIgniter\DataCaster\DataCaster;
23-
use CodeIgniter\Entity\Cast\CastInterface;
24-
use CodeIgniter\Entity\Exceptions\CastException;
25-
use CodeIgniter\DataConverter\DataConverter;
26-
use CodeIgniter\Entity\Entity;
27-
use CodeIgniter\Entity\Cast\URICast;
2838
use CodeIgniter\HTTP\URI;
2939
use CodeIgniter\Log\Handlers\ChromeLoggerHandler;
30-
use CodeIgniter\Security\CheckPhpIni;
31-
use CodeIgniter\View\Table;
32-
use CodeIgniter\Database\BaseResult;
33-
use CodeIgniter\View\Plugins;
34-
use CodeIgniter\HTTP\ResponseTrait;
3540
use CodeIgniter\Pager\PagerInterface;
36-
use CodeIgniter\HTTP\Response;
37-
use CodeIgniter\HTTP\RedirectResponse;
38-
use CodeIgniter\HTTP\DownloadResponse;
41+
use CodeIgniter\Security\CheckPhpIni;
3942
use CodeIgniter\Validation\Validation;
43+
use CodeIgniter\View\Plugins;
4044
use CodeIgniter\View\RendererInterface;
41-
use Boundwize\StructArmed\Architecture;
42-
use Boundwize\StructArmed\Preset\Preset;
43-
use Boundwize\StructArmed\Preset\Presets\Psr4Preset;
45+
use CodeIgniter\View\Table;
4446

4547
return Architecture::define()
4648
->skip([
@@ -58,6 +60,8 @@
5860
->layer('Helpers', __DIR__ . '/system/Helpers')
5961
->rule('helpers.functions_must_have_return_type', new MustHaveReturnTypeFunctionRule('Helpers'))
6062

63+
->rule('base_classes.must_be_abstract', new ExtendedClassMustBeAbstractOrInstantiatedRule('Source', '/^CodeIgniter\\\\.*Base.*$/'))
64+
6165
// Resolve CodeIgniter layers from class names because several layers share directories.
6266
->layerPattern('API', '/^CodeIgniter\\\\API\\\\.*$/')
6367
->layerPattern('Cache', '/^CodeIgniter\\\\Cache\\\\.*$/')
@@ -115,13 +119,13 @@
115119
'Pager' => ['URI', 'View'],
116120
'Publisher' => ['Files', 'URI'],
117121
// +API = API + its allowed layers; +Controller = Controller + its allowed layers
118-
'RESTful' => ['+API', '+Controller'],
119-
'Router' => ['HTTP', 'I18n'],
120-
'Security' => ['Cookie', 'HTTP', 'I18n', 'Session'],
121-
'Session' => ['Cookie', 'Database', 'HTTP', 'I18n'],
122-
'Throttle' => ['Cache', 'I18n'],
123-
'Validation' => ['Database', 'HTTP', 'Helpers', 'I18n', 'Input'],
124-
'View' => ['Cache'],
122+
'RESTful' => ['+API', '+Controller'],
123+
'Router' => ['HTTP', 'I18n'],
124+
'Security' => ['Cookie', 'HTTP', 'I18n', 'Session'],
125+
'Session' => ['Cookie', 'Database', 'HTTP', 'I18n'],
126+
'Throttle' => ['Cache', 'I18n'],
127+
'Validation' => ['Database', 'HTTP', 'Helpers', 'I18n', 'Input'],
128+
'View' => ['Cache'],
125129
])
126130
->skipPathsForRuleset(['*test*'])
127131
// Skip violations for class-specific dependencies.
@@ -135,7 +139,7 @@
135139
CastInterface::class,
136140
CastException::class,
137141
])
138-
->skipClassViolation(\CodeIgniter\DataCaster\Exceptions\CastException::class, [
142+
->skipClassViolation(CodeIgniter\DataCaster\Exceptions\CastException::class, [
139143
CastException::class,
140144
])
141145
->skipClassViolation(DataConverter::class, [

‎system/Config/BaseService.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
* @method static ValidationInterface validation(ConfigValidation $config = null, $getShared = true)
150150
* @method static Cell viewcell($getShared = true)
151151
*/
152-
class BaseService
152+
abstract class BaseService
153153
{
154154
/**
155155
* Cache for instance of any services that

‎system/Debug/Toolbar/Collectors/BaseCollector.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Base Toolbar collector
1818
*/
19-
class BaseCollector
19+
abstract class BaseCollector
2020
{
2121
/**
2222
* Whether this collector has data that can

‎user_guide_src/source/changelogs/v4.8.0.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ Behavior Changes
4141
- **Commands:** The ``db:table`` output was reworded: the data and metadata column headers are now capitalized (e.g. ``Id``, ``Created_at``), the connection summary headers read ``Hostname``, ``Database``, ``Username``, ``DB Driver``, ``DB Prefix``, and ``Port``, and the section titles changed (e.g. ``Data of "users" table:``). Scripts that grep the previous output will need updating.
4242
- **Commands:** The ``worker:uninstall`` command now returns ``EXIT_SUCCESS`` (previously ``EXIT_ERROR``) when the user declines the interactive confirmation prompt, since user-initiated cancellation is not a failure. In non-interactive mode without ``--force`` it now aborts with ``EXIT_ERROR`` instead of prompting, and the redundant ``Uninstalling FrankenPHP Worker Mode`` header was dropped. Scripts that branch on the previous exit code or wording will need updating.
4343
- **Commands:** The ``phpini:check`` command's invalid-argument error now prints only ``You must specify a correct argument.``. The usage example and the argument listing moved to ``phpini:check --help``, where the argument is now named ``section``. Scripts that grep the previous output will need updating.
44+
- **Config:** ``CodeIgniter\Config\BaseService`` is now ``abstract``. It is intended to be extended (as ``Config\Services`` does) and accessed statically; code that instantiated it directly with ``new BaseService()`` will now throw an ``Error``.
4445
- **Database:** The Postgre driver's ``$db->error()['code']`` previously always returned ``''``. It now returns the 5-character SQLSTATE string for query and transaction failures (e.g., ``'42P01'``), or ``'08006'`` for connection-level failures. Code that relied on ``$db->error()['code'] === ''`` will need updating.
46+
- **Debug:** ``CodeIgniter\Debug\Toolbar\Collectors\BaseCollector`` is now ``abstract``. Custom toolbar collectors must extend it; code that instantiated it directly with ``new BaseCollector()`` will now throw an ``Error``.
4547
- **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method
4648
(e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match.
4749
- **HTTP:** Routes defined with ``$routes->add()`` now also match HTTP ``QUERY`` requests. If the route has CSRF protection, remember that CSRF verification does not protect safe methods such as ``GET`` and ``QUERY``.

0 commit comments

Comments
 (0)