diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index 3891bba..da22eeb 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
+ php: [ '8.3', '8.4', '8.5' ]
name: PHP ${{ matrix.php }}
diff --git a/composer.json b/composer.json
index 015b6b7..6070388 100644
--- a/composer.json
+++ b/composer.json
@@ -9,13 +9,13 @@
}
],
"require": {
- "php": ">=7.4"
+ "php": ">=8.0"
},
"suggest": {
"ext-apcu": "*"
},
"require-dev": {
- "phpunit/phpunit": "~9"
+ "phpunit/phpunit": "^12"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index 564f4ce..89f26ad 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,23 +1,15 @@
-
- * An offset to check for.
- *
- * Whether a offset exists
- *
- * @link http://php.net/manual/en/arrayaccess.offsetexists.php
- *
- * @param mixed $offset
- * The return value will be casted to boolean if non-boolean was returned.
- */
- public function offsetExists($offset): bool
+ #[\Override]
+ public function offsetExists(mixed $offset): bool
{
return isset($this->_items[$offset]);
}
- /**
- * (PHP 5 >= 5.0.0)
- * Offset to retrieve
- *
- * @link http://php.net/manual/en/arrayaccess.offsetget.php
- *
- * @param mixed $offset
- * The offset to retrieve. - *
- * - * @return mixed Can return all value types. - */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + #[\Override] + public function offsetGet(mixed $offset): mixed { return $this->getItem($offset); } - /** - * (PHP 5 >= 5.0.0)- * The offset to assign the value to. - *
- * @param mixed $value- * The value to set. - *
- * - * @return void - */ - public function offsetSet($offset, $value): void + #[\Override] + public function offsetSet(mixed $offset, mixed $value): void { $this->addItem($offset, $value); } - /** - * (PHP 5 >= 5.0.0)- * The offset to unset. - *
- * - * @return void - */ - public function offsetUnset($offset): void + #[\Override] + public function offsetUnset(mixed $offset): void { unset($this->_items[$offset]); } diff --git a/src/Provider/Ini/AbstractIniConfigProvider.php b/src/Provider/Ini/AbstractIniConfigProvider.php index bfed470..c8a3c99 100644 --- a/src/Provider/Ini/AbstractIniConfigProvider.php +++ b/src/Provider/Ini/AbstractIniConfigProvider.php @@ -9,11 +9,8 @@ abstract class AbstractIniConfigProvider extends AbstractConfigProvider /** * Load configuration from a string containing INI data and optionally parse * environment variable placeholders - * - * @param string $iniString - * @param bool $parseEnv */ - protected function _loadString($iniString, $parseEnv) + protected function _loadString(string $iniString, bool $parseEnv): void { if($parseEnv) { @@ -31,12 +28,7 @@ protected function _loadString($iniString, $parseEnv) $this->_buildFromData($data); } - /** - * Build up the configuration from the sectioned array - * - * @param array $iniData - */ - protected function _buildFromData(array $iniData) + protected function _buildFromData(array $iniData): void { foreach($iniData as $section => $sectionData) { @@ -57,16 +49,12 @@ protected function _buildFromData(array $iniData) * variable's value. * Variables are expected to be in this format: {{ENV:VARNAME:defaultValue}} * The ":defaultValue" part is optional and defaults to an empty string - * - * @param string $iniString - * - * @return string */ - protected function _parseEnvVars($iniString) + protected function _parseEnvVars(string $iniString): string { return preg_replace_callback( '/{{ENV:([0-9A-Za-z_]*)(:([^{}]*))?}}/', - function ($matches) { + function(array $matches): string { $varName = $matches[1]; $default = $matches[3] ?? ''; $value = getenv($varName); diff --git a/src/Provider/Ini/CachedIniConfigProvider.php b/src/Provider/Ini/CachedIniConfigProvider.php index 0e3b4c4..f9f09a7 100644 --- a/src/Provider/Ini/CachedIniConfigProvider.php +++ b/src/Provider/Ini/CachedIniConfigProvider.php @@ -5,7 +5,7 @@ class CachedIniConfigProvider extends AbstractIniConfigProvider { protected static bool $_hasApcu; - public function __construct(array $directories = [], $filename = null, $parseEnv = false, $cacheTTL = 5) + public function __construct(array $directories = [], ?string $filename = null, bool $parseEnv = false, int $cacheTTL = 5) { self::$_hasApcu = self::$_hasApcu ?? function_exists('apcu_fetch'); @@ -15,7 +15,7 @@ public function __construct(array $directories = [], $filename = null, $parseEnv } } - public function loadCached($directories, $filename, $parseEnv = false, $cacheTTL = 5) + public function loadCached(array $directories, string $filename, bool $parseEnv = false, int $cacheTTL = 5): static { $dirsHash = md5(implode('|', $directories)); $lastCheckKey = 'CachedIniCP:' . $dirsHash . ':lastCheck:' . $filename; diff --git a/src/Provider/Ini/IniConfigProvider.php b/src/Provider/Ini/IniConfigProvider.php index 2e02b17..e6fd195 100644 --- a/src/Provider/Ini/IniConfigProvider.php +++ b/src/Provider/Ini/IniConfigProvider.php @@ -5,11 +5,7 @@ class IniConfigProvider extends AbstractIniConfigProvider { - /** - * @param null|string $file Full path of ini file to create configuration from - * @param bool $parseEnv If true then parse environment variables in the INI file - */ - public function __construct($file = null, $parseEnv = false) + public function __construct(?string $file = null, bool $parseEnv = false) { if($file !== null) { @@ -18,15 +14,9 @@ public function __construct($file = null, $parseEnv = false) } /** - * Add items from an ini file to the configuration - * - * @param string $fullPath full path to the ini file to load - * @param bool $parseEnv If true then parse environment variables in the INI file - * - * @return $this - * @throws \RuntimeException + * @throws RuntimeException */ - public function loadFile($fullPath, $parseEnv = false) + public function loadFile(string $fullPath, bool $parseEnv = false): static { if(!file_exists($fullPath)) { @@ -52,16 +42,7 @@ public function loadFile($fullPath, $parseEnv = false) return $this; } - /** - * Add items from multiple ini files - * - * @param array $paths - * @param bool $parseEnv - * @param bool $throw - * - * @return $this - */ - public function loadFiles(array $paths, $parseEnv = false, $throw = false) + public function loadFiles(array $paths, bool $parseEnv = false, bool $throw = false): static { foreach($paths as $path) { @@ -81,15 +62,9 @@ public function loadFiles(array $paths, $parseEnv = false, $throw = false) } /** - * Add items from an ini string to the configuration - * - * @param string $iniString valid ini string - * @param bool $parseEnv If true then parse environment variables in the INI file - * - * @return $this - * @throws \RuntimeException + * @throws RuntimeException */ - public function loadString($iniString, $parseEnv = false) + public function loadString(string $iniString, bool $parseEnv = false): static { $this->_loadString($iniString, $parseEnv); return $this; diff --git a/src/Provider/Test/TestConfigProvider.php b/src/Provider/Test/TestConfigProvider.php index ce75523..7c9aaa4 100644 --- a/src/Provider/Test/TestConfigProvider.php +++ b/src/Provider/Test/TestConfigProvider.php @@ -3,15 +3,7 @@ use Packaged\Config\Provider\ConfigProvider; -/** - * @deprecated \Packaged\Config\Provider\ConfigProvider - * - * Class TestConfigProvider - * - * Config provider for testing basics - * - * @package Packaged\Config\Provider\Test - */ +/** @deprecated Use \Packaged\Config\Provider\ConfigProvider directly */ class TestConfigProvider extends ConfigProvider { } diff --git a/src/Provider/Test/TestConfigSection.php b/src/Provider/Test/TestConfigSection.php index 6570af9..eb73e2f 100644 --- a/src/Provider/Test/TestConfigSection.php +++ b/src/Provider/Test/TestConfigSection.php @@ -3,15 +3,7 @@ use Packaged\Config\Provider\ConfigSection; -/** - * @deprecated \Packaged\Config\Provider\ConfigSection - * - * Class TestConfigSection - * - * Configuration section - * - * @package Packaged\Config\Provider\Test - */ +/** @deprecated Use \Packaged\Config\Provider\ConfigSection directly */ class TestConfigSection extends ConfigSection { } diff --git a/tests/ConfigProviderBaseTest.php b/tests/ConfigProviderBaseTest.php index 2c7f5fd..36d416c 100644 --- a/tests/ConfigProviderBaseTest.php +++ b/tests/ConfigProviderBaseTest.php @@ -5,6 +5,7 @@ use Exception; use Packaged\Config\ConfigProviderInterface; use Packaged\Config\Provider\ConfigSection; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; abstract class ConfigProviderBaseTest extends TestCase @@ -15,10 +16,7 @@ public function testCanBeLoaded() $this->assertNotNull($provider); } - /** - * @return ConfigProviderInterface - */ - abstract public function getConfigProvider(); + abstract public function getConfigProvider(): ConfigProviderInterface; public function testValidProvider() { @@ -29,9 +27,7 @@ public function testValidProvider() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddItem() { $provider = $this->getConfigProvider(); @@ -58,9 +54,7 @@ public function testCanAddItem() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddItemAndRetrieve() { $provider = $this->getConfigProvider(); @@ -69,9 +63,7 @@ public function testCanAddItemAndRetrieve() $this->assertEquals("localhost", $item); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddItemAndRetrieveSection() { $provider = $this->getConfigProvider(); @@ -83,9 +75,7 @@ public function testCanAddItemAndRetrieveSection() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddRemoveItem() { $provider = $this->getConfigProvider(); @@ -95,9 +85,7 @@ public function testCanAddRemoveItem() $this->assertEquals("rm", $provider->getItem("db", "hostname", 'rm')); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testGetSections() { $provider = $this->getConfigProvider(); @@ -113,9 +101,7 @@ public function testGetSections() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionAdd() { $section = new ConfigSection("db"); @@ -129,9 +115,7 @@ public function testSectionAdd() $provider->addSection($section); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionSet() { $section = new ConfigSection("db"); @@ -143,9 +127,7 @@ public function testSectionSet() $provider->setSection($section); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionGetItem() { $provider = $this->getConfigProvider(); @@ -154,9 +136,7 @@ public function testSectionGetItem() $this->assertEquals("localhost", $section->getItem("hostname", "notset")); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testMissingSectionThrows() { $provider = $this->getConfigProvider(); @@ -165,9 +145,7 @@ public function testMissingSectionThrows() $provider->getSection("database"); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testMissingSectionNoThrow() { $provider = $this->getConfigProvider(); @@ -176,9 +154,7 @@ public function testMissingSectionNoThrow() $this->assertEquals("missing", $section->getName()); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testGetMissingItem() { $provider = $this->getConfigProvider(); @@ -193,9 +169,7 @@ public function testGetMissingItem() $this->assertEquals("notset", $section->getItem("hostname", "notset")); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testDefaultExceptionThrown() { $provider = $this->getConfigProvider(); @@ -205,9 +179,7 @@ public function testDefaultExceptionThrown() $provider->getItem('', 'gone', new Exception("Config Item Not Found", 999)); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionExists() { $provider = $this->getConfigProvider(); @@ -226,9 +198,7 @@ public function testSectionExists() $this->assertFalse($provider->sectionExists("database")); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testHasItem() { $provider = $this->getConfigProvider(); @@ -239,9 +209,7 @@ public function testHasItem() $this->assertTrue($provider->hasItem('newsection', 'newitem')); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionNameGet() { $provider = $this->getConfigProvider(); diff --git a/tests/ConfigProviderTest.php b/tests/ConfigProviderTest.php index a9dc72f..55b068c 100644 --- a/tests/ConfigProviderTest.php +++ b/tests/ConfigProviderTest.php @@ -6,7 +6,7 @@ class ConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider() + public function getConfigProvider(): ConfigProvider { return new ConfigProvider([]); } diff --git a/tests/ConfigSectionBaseTest.php b/tests/ConfigSectionBaseTest.php index fcad5d9..ab6e50d 100644 --- a/tests/ConfigSectionBaseTest.php +++ b/tests/ConfigSectionBaseTest.php @@ -14,10 +14,7 @@ public function testNameSetAndGet() $this->assertEquals("testing", $section->getName()); } - /** - * @return ConfigSectionInterface - */ - abstract public function getConfigSection(); + abstract public function getConfigSection(): ConfigSectionInterface; public function testCanAddItemAndRetrieve() { diff --git a/tests/ConfigSectionTest.php b/tests/ConfigSectionTest.php index 0820fc0..9f3c72f 100644 --- a/tests/ConfigSectionTest.php +++ b/tests/ConfigSectionTest.php @@ -30,10 +30,7 @@ public function testArrayAccess() $section->getItem('ghj', new Exception("Config Item Not Found", 999)); } - /** - * @return ConfigSectionInterface - */ - public function getConfigSection() + public function getConfigSection(): ConfigSection { return new ConfigSection(); } diff --git a/tests/ConfigurableTraitTest.php b/tests/ConfigurableTraitTest.php index 73a11f4..2089cc3 100644 --- a/tests/ConfigurableTraitTest.php +++ b/tests/ConfigurableTraitTest.php @@ -28,10 +28,7 @@ class MockConfigurableTrait { use ConfigurableTrait; - /** - * @return ConfigSectionInterface - */ - public function config() + public function config(): ConfigSectionInterface { return $this->_config(); } diff --git a/tests/IniCachedConfigProviderTest.php b/tests/IniCachedConfigProviderTest.php index 829fca1..1658ada 100644 --- a/tests/IniCachedConfigProviderTest.php +++ b/tests/IniCachedConfigProviderTest.php @@ -3,10 +3,9 @@ namespace Packaged\Config\Test; use Packaged\Config\Provider\Ini\CachedIniConfigProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; -/** - * @requires extension apcu - */ +#[RequiresPhpExtension('apcu')] class IniCachedConfigProviderTest extends ConfigProviderBaseTest { public function testMissingLoadFile() @@ -16,15 +15,12 @@ public function testMissingLoadFile() $this->assertSame($provider, $result); } - /** - * @return CachedIniConfigProvider - */ - public function getConfigProvider() + public function getConfigProvider(): CachedIniConfigProvider { return new CachedIniConfigProvider(); } - private function _dataDir() + private function _dataDir(): array { return [__DIR__ . '/testData']; } @@ -63,6 +59,10 @@ public function testLoadFileMissingFirstDir() public function testCachedLoad() { + if(!ini_get('apc.enable_cli')) + { + $this->markTestSkipped('Requires apc.enable_cli=1'); + } $dir = sys_get_temp_dir(); $tempFile = tempnam($dir, 'cached-ini'); $filename = basename($tempFile); diff --git a/tests/IniConfigProviderTest.php b/tests/IniConfigProviderTest.php index 9a2c2a2..9126c57 100644 --- a/tests/IniConfigProviderTest.php +++ b/tests/IniConfigProviderTest.php @@ -15,7 +15,7 @@ public function testMissingLoadFile() $provider->loadFile($file); } - public function getConfigProvider() + public function getConfigProvider(): IniConfigProvider { return new IniConfigProvider(); } diff --git a/tests/TestConfigProviderTest.php b/tests/TestConfigProviderTest.php index e199b2a..33b48cf 100644 --- a/tests/TestConfigProviderTest.php +++ b/tests/TestConfigProviderTest.php @@ -6,7 +6,7 @@ class TestConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider() + public function getConfigProvider(): TestConfigProvider { return new TestConfigProvider(); } diff --git a/tests/TestConfigSectionTest.php b/tests/TestConfigSectionTest.php index 7763e24..34eade8 100644 --- a/tests/TestConfigSectionTest.php +++ b/tests/TestConfigSectionTest.php @@ -7,10 +7,7 @@ class TestConfigSectionTest extends ConfigSectionBaseTest { - /** - * @return ConfigSectionInterface - */ - public function getConfigSection() + public function getConfigSection(): TestConfigSection { return new TestConfigSection(); }