Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Factory;
use PhpCsFixer\Finder;
Expand All @@ -20,8 +22,8 @@
]);

$overrides = [
// 'declare_strict_types' => true,
// 'void_return' => true,
'declare_strict_types' => true,
'void_return' => true,
];

$options = [
Expand Down
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Upgrade Guide

## Version 2.2.0 to 2.3.0

* The minimum required version of CodeIgniter is now `4.3` and PHP `8.2`.
* All source files now declare `strict_types=1`.
* `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`.

## Version 1 to 2
***

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"require-dev": {
"codeigniter4/devkit": "^1.3",
"codeigniter4/framework": "^4.2.3"
"codeigniter4/framework": "^4.3"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
6 changes: 3 additions & 3 deletions docs/limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ The following are known limitations of the library:
2. **Deferred writes (`deferWrites => true`)**: All settings are batched and written to storage at the end of the request
(during the `post_system` event). This minimizes the number of database queries and file writes, improving performance.
However, there are important considerations:
- Write operations will not appear in CodeIgniter's Debug Toolbar, since the `post_system` event executes after toolbar data collection.
- If the request terminates early (fatal error, `exit()`, etc.) before `post_system`, pending writes are lost.
- Write failures are logged but handled silently - no exceptions are thrown back to the calling code.
- Write operations will not appear in CodeIgniter's Debug Toolbar, since the `post_system` event executes after toolbar data collection.
- If the request terminates early (fatal error, `exit()`, etc.) before `post_system`, pending writes are lost.
- Write failures are logged but handled silently - no exceptions are thrown back to the calling code.

3. **First-level property access only**: You can only access the first level of a config property directly. In most config classes
this is not an issue, since properties are simple values. However, some config files (like `Database`) contain properties that
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
phpVersion="8.1"
phpVersion="8.2"
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
10 changes: 8 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_80]);
$rectorConfig->sets([
SetList::DEAD_CODE,
LevelSetList::UP_TO_PHP_82,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_100,
]);

$rectorConfig->parallel();
// The paths to refactor (can also be supplied with CLI arguments)
$rectorConfig->paths([
Expand All @@ -65,7 +71,7 @@
}

// Set the target version for refactoring
$rectorConfig->phpVersion(PhpVersion::PHP_74);
$rectorConfig->phpVersion(PhpVersion::PHP_82);

// Auto-import fully qualified class names
$rectorConfig->importNames();
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/ClearSettings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Commands;

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

public function run(array $params)
public function run(array $params): void
{
$config = config('Settings');
$handlers = $this->getHandlerNames($config);
Expand Down
2 changes: 2 additions & 0 deletions src/Config/Services.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Config;

use CodeIgniter\Config\BaseService;
Expand Down
2 changes: 2 additions & 0 deletions src/Config/Settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Config;

use CodeIgniter\Config\BaseConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Database\Migrations;

use CodeIgniter\Database\Forge;
Expand All @@ -8,7 +10,7 @@

class CreateSettingsTable extends Migration
{
private Settings $config;
private readonly Settings $config;

public function __construct(?Forge $forge = null)
{
Expand All @@ -18,7 +20,7 @@ public function __construct(?Forge $forge = null)
parent::__construct($forge);
}

public function up()
public function up(): void
{
$this->forge->addField('id');
$this->forge->addField([
Expand Down Expand Up @@ -51,7 +53,7 @@ public function up()
$this->forge->createTable($this->config->database['table'], true);
}

public function down()
public function down(): void
{
$this->forge->dropTable($this->config->database['table']);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Database\Migrations;

use CodeIgniter\Database\Forge;
Expand All @@ -8,7 +10,7 @@

class AddContextColumn extends Migration
{
private Settings $config;
private readonly Settings $config;

public function __construct(?Forge $forge = null)
{
Expand All @@ -18,7 +20,7 @@ public function __construct(?Forge $forge = null)
parent::__construct($forge);
}

public function up()
public function up(): void
{
$this->forge->addColumn($this->config->database['table'], [
'context' => [
Expand All @@ -30,7 +32,7 @@ public function up()
]);
}

public function down()
public function down(): void
{
$this->forge->dropColumn($this->config->database['table'], 'context');
}
Expand Down
10 changes: 6 additions & 4 deletions src/Handlers/ArrayHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Handlers;

use CodeIgniter\Events\Events;
Expand Down Expand Up @@ -54,17 +56,17 @@ public function get(string $class, string $property, ?string $context = null)
return $this->getStored($class, $property, $context);
}

public function set(string $class, string $property, $value = null, ?string $context = null)
public function set(string $class, string $property, $value = null, ?string $context = null): void
{
$this->setStored($class, $property, $value, $context);
}

public function forget(string $class, string $property, ?string $context = null)
public function forget(string $class, string $property, ?string $context = null): void
{
$this->forgetStored($class, $property, $context);
}

public function flush()
public function flush(): void
{
$this->general = [];
$this->contexts = [];
Expand Down Expand Up @@ -189,7 +191,7 @@ protected function setupDeferredWrites(bool $enabled): void
$this->deferWrites = $enabled;

if ($this->deferWrites) {
Events::on('post_system', [$this, 'persistPendingProperties']);
Events::on('post_system', $this->persistPendingProperties(...));
}
}
}
18 changes: 6 additions & 12 deletions src/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Handlers;

use RuntimeException;
Expand All @@ -26,11 +28,9 @@ abstract public function get(string $class, string $property, ?string $context =
*
* @param mixed $value
*
* @return void
*
* @throws RuntimeException
*/
public function set(string $class, string $property, $value = null, ?string $context = null)
public function set(string $class, string $property, $value = null, ?string $context = null): void
{
throw new RuntimeException('Set method not implemented for current Settings handler.');
}
Expand All @@ -41,35 +41,29 @@ public function set(string $class, string $property, $value = null, ?string $con
* Not all Handlers will support writing values.
* Must throw RuntimeException for any failures.
*
* @return void
*
* @throws RuntimeException
*/
public function forget(string $class, string $property, ?string $context = null)
public function forget(string $class, string $property, ?string $context = null): void
{
throw new RuntimeException('Forget method not implemented for current Settings handler.');
}

/**
* All handlers MUST support flushing all values.
*
* @return void
*
* @throws RuntimeException
*/
public function flush()
public function flush(): void
{
throw new RuntimeException('Flush method not implemented for current Settings handler.');
}

/**
* All handlers that support deferWrites MUST support this method.
*
* @return void
*
* @throws RuntimeException
*/
public function persistPendingProperties()
public function persistPendingProperties(): void
{
throw new RuntimeException('PersistPendingProperties method not implemented for current Settings handler.');
}
Expand Down
24 changes: 9 additions & 15 deletions src/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Settings\Handlers;

use CodeIgniter\Database\BaseBuilder;
Expand All @@ -18,12 +20,12 @@ class DatabaseHandler extends ArrayHandler
/**
* The DB connection for the Settings.
*/
private BaseConnection $db;
private readonly BaseConnection $db;

/**
* The Query Builder for the Settings table.
*/
private BaseBuilder $builder;
private readonly BaseBuilder $builder;

/**
* Array of contexts that have been stored.
Expand All @@ -32,7 +34,7 @@ class DatabaseHandler extends ArrayHandler
*/
private array $hydrated = [];

private Settings $config;
private readonly Settings $config;

/**
* Stores the configured database table.
Expand Down Expand Up @@ -74,11 +76,9 @@ public function get(string $class, string $property, ?string $context = null)
*
* @param mixed $value
*
* @return void
*
* @throws RuntimeException For database failures
*/
public function set(string $class, string $property, $value = null, ?string $context = null)
public function set(string $class, string $property, $value = null, ?string $context = null): void
{
if ($this->deferWrites) {
$this->markPending($class, $property, $value, $context);
Expand Down Expand Up @@ -137,10 +137,8 @@ private function persist(string $class, string $property, $value, ?string $conte
/**
* Deletes the record from persistent storage, if found,
* and from the local cache.
*
* @return void
*/
public function forget(string $class, string $property, ?string $context = null)
public function forget(string $class, string $property, ?string $context = null): void
{
$this->hydrate($context);

Expand Down Expand Up @@ -175,10 +173,8 @@ private function persistForget(string $class, string $property, ?string $context
/**
* Deletes all records from persistent storage, if found,
* and from the local cache.
*
* @return void
*/
public function flush()
public function flush(): void
{
$this->builder->truncate();

Expand Down Expand Up @@ -228,10 +224,8 @@ private function hydrate(?string $context): void
* Persists all pending properties to the database.
* Called automatically at the end of request via post_system
* event when deferWrites is enabled.
*
* @return void
*/
public function persistPendingProperties()
public function persistPendingProperties(): void
{
if ($this->pendingProperties === []) {
return;
Expand Down
Loading
Loading