Skip to content

Commit 458204d

Browse files
authored
refactor: update rector, psalm and add strict types (#159)
* refactor: update rector, psalm and add strict types * fix randomly failing tests
1 parent ad2ba91 commit 458204d

24 files changed

+171
-153
lines changed

.php-cs-fixer.dist.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use CodeIgniter\CodingStandard\CodeIgniter4;
46
use Nexus\CsConfig\Factory;
57
use PhpCsFixer\Finder;
@@ -20,8 +22,8 @@
2022
]);
2123

2224
$overrides = [
23-
// 'declare_strict_types' => true,
24-
// 'void_return' => true,
25+
'declare_strict_types' => true,
26+
'void_return' => true,
2527
];
2628

2729
$options = [

UPGRADING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Upgrade Guide
22

3+
## Version 2.2.0 to 2.3.0
4+
5+
* The minimum required version of CodeIgniter is now `4.3` and PHP `8.2`.
6+
* All source files now declare `strict_types=1`.
7+
* `BaseHandler` methods `set()`, `forget()`, `flush()`, and `persistPendingProperties()` now have `void` return types. Any custom handler extending `BaseHandler` must update its method signatures to include `: void`.
8+
39
## Version 1 to 2
410
***
511

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"require-dev": {
2323
"codeigniter4/devkit": "^1.3",
24-
"codeigniter4/framework": "^4.2.3"
24+
"codeigniter4/framework": "^4.3"
2525
},
2626
"minimum-stability": "dev",
2727
"prefer-stable": true,

docs/limitations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ The following are known limitations of the library:
1010
2. **Deferred writes (`deferWrites => true`)**: All settings are batched and written to storage at the end of the request
1111
(during the `post_system` event). This minimizes the number of database queries and file writes, improving performance.
1212
However, there are important considerations:
13-
- Write operations will not appear in CodeIgniter's Debug Toolbar, since the `post_system` event executes after toolbar data collection.
14-
- If the request terminates early (fatal error, `exit()`, etc.) before `post_system`, pending writes are lost.
15-
- Write failures are logged but handled silently - no exceptions are thrown back to the calling code.
13+
- Write operations will not appear in CodeIgniter's Debug Toolbar, since the `post_system` event executes after toolbar data collection.
14+
- If the request terminates early (fatal error, `exit()`, etc.) before `post_system`, pending writes are lost.
15+
- Write failures are logged but handled silently - no exceptions are thrown back to the calling code.
1616

1717
3. **First-level property access only**: You can only access the first level of a config property directly. In most config classes
1818
this is not an issue, since properties are simple values. However, some config files (like `Database`) contain properties that

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
phpVersion="8.1"
3+
phpVersion="8.2"
44
errorLevel="7"
55
resolveFromConfigFile="true"
66
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

rector.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@
4242
use Rector\ValueObject\PhpVersion;
4343

4444
return static function (RectorConfig $rectorConfig): void {
45-
$rectorConfig->sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_80]);
45+
$rectorConfig->sets([
46+
SetList::DEAD_CODE,
47+
LevelSetList::UP_TO_PHP_82,
48+
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
49+
PHPUnitSetList::PHPUNIT_100,
50+
]);
51+
4652
$rectorConfig->parallel();
4753
// The paths to refactor (can also be supplied with CLI arguments)
4854
$rectorConfig->paths([
@@ -65,7 +71,7 @@
6571
}
6672

6773
// Set the target version for refactoring
68-
$rectorConfig->phpVersion(PhpVersion::PHP_74);
74+
$rectorConfig->phpVersion(PhpVersion::PHP_82);
6975

7076
// Auto-import fully qualified class names
7177
$rectorConfig->importNames();

src/Commands/ClearSettings.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace CodeIgniter\Settings\Commands;
46

57
use CodeIgniter\CLI\BaseCommand;
@@ -12,7 +14,7 @@ class ClearSettings extends BaseCommand
1214
protected $name = 'settings:clear';
1315
protected $description = 'Clears all settings from persistent storage.';
1416

15-
public function run(array $params)
17+
public function run(array $params): void
1618
{
1719
$config = config('Settings');
1820
$handlers = $this->getHandlerNames($config);

src/Config/Services.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace CodeIgniter\Settings\Config;
46

57
use CodeIgniter\Config\BaseService;

src/Config/Settings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace CodeIgniter\Settings\Config;
46

57
use CodeIgniter\Config\BaseConfig;

src/Database/Migrations/2021-07-04-041948_CreateSettingsTable.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace CodeIgniter\Settings\Database\Migrations;
46

57
use CodeIgniter\Database\Forge;
@@ -8,7 +10,7 @@
810

911
class CreateSettingsTable extends Migration
1012
{
11-
private Settings $config;
13+
private readonly Settings $config;
1214

1315
public function __construct(?Forge $forge = null)
1416
{
@@ -18,7 +20,7 @@ public function __construct(?Forge $forge = null)
1820
parent::__construct($forge);
1921
}
2022

21-
public function up()
23+
public function up(): void
2224
{
2325
$this->forge->addField('id');
2426
$this->forge->addField([
@@ -51,7 +53,7 @@ public function up()
5153
$this->forge->createTable($this->config->database['table'], true);
5254
}
5355

54-
public function down()
56+
public function down(): void
5557
{
5658
$this->forge->dropTable($this->config->database['table']);
5759
}

0 commit comments

Comments
 (0)