diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index a72e437..eda5b18 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: [ '8.3', '8.4', '8.5' ]
+ php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
name: PHP ${{ matrix.php }}
diff --git a/composer.json b/composer.json
index 6070388..015b6b7 100644
--- a/composer.json
+++ b/composer.json
@@ -9,13 +9,13 @@
}
],
"require": {
- "php": ">=8.0"
+ "php": ">=7.4"
},
"suggest": {
"ext-apcu": "*"
},
"require-dev": {
- "phpunit/phpunit": "^12"
+ "phpunit/phpunit": "~9"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index 89f26ad..564f4ce 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,15 +1,23 @@
-
+ * 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
{
return isset($this->_items[$offset]);
}
- #[\Override]
- public function offsetGet(mixed $offset): mixed
+ /**
+ * (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) { return $this->getItem($offset); } - #[\Override] - public function offsetSet(mixed $offset, mixed $value): void + /** + * (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 { $this->addItem($offset, $value); } - #[\Override] - public function offsetUnset(mixed $offset): void + /** + * (PHP 5 >= 5.0.0)+ * The offset to unset. + *
+ * + * @return void + */ + public function offsetUnset($offset): void { unset($this->_items[$offset]); } diff --git a/src/Provider/Ini/AbstractIniConfigProvider.php b/src/Provider/Ini/AbstractIniConfigProvider.php index c8a3c99..bfed470 100644 --- a/src/Provider/Ini/AbstractIniConfigProvider.php +++ b/src/Provider/Ini/AbstractIniConfigProvider.php @@ -9,8 +9,11 @@ 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(string $iniString, bool $parseEnv): void + protected function _loadString($iniString, $parseEnv) { if($parseEnv) { @@ -28,7 +31,12 @@ protected function _loadString(string $iniString, bool $parseEnv): void $this->_buildFromData($data); } - protected function _buildFromData(array $iniData): void + /** + * Build up the configuration from the sectioned array + * + * @param array $iniData + */ + protected function _buildFromData(array $iniData) { foreach($iniData as $section => $sectionData) { @@ -49,12 +57,16 @@ protected function _buildFromData(array $iniData): void * 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(string $iniString): string + protected function _parseEnvVars($iniString) { return preg_replace_callback( '/{{ENV:([0-9A-Za-z_]*)(:([^{}]*))?}}/', - function(array $matches): string { + function ($matches) { $varName = $matches[1]; $default = $matches[3] ?? ''; $value = getenv($varName); diff --git a/src/Provider/Ini/CachedIniConfigProvider.php b/src/Provider/Ini/CachedIniConfigProvider.php index f9f09a7..0e3b4c4 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 = [], ?string $filename = null, bool $parseEnv = false, int $cacheTTL = 5) + public function __construct(array $directories = [], $filename = null, $parseEnv = false, $cacheTTL = 5) { self::$_hasApcu = self::$_hasApcu ?? function_exists('apcu_fetch'); @@ -15,7 +15,7 @@ public function __construct(array $directories = [], ?string $filename = null, b } } - public function loadCached(array $directories, string $filename, bool $parseEnv = false, int $cacheTTL = 5): static + public function loadCached($directories, $filename, $parseEnv = false, $cacheTTL = 5) { $dirsHash = md5(implode('|', $directories)); $lastCheckKey = 'CachedIniCP:' . $dirsHash . ':lastCheck:' . $filename; diff --git a/src/Provider/Ini/IniConfigProvider.php b/src/Provider/Ini/IniConfigProvider.php index e6fd195..2e02b17 100644 --- a/src/Provider/Ini/IniConfigProvider.php +++ b/src/Provider/Ini/IniConfigProvider.php @@ -5,7 +5,11 @@ class IniConfigProvider extends AbstractIniConfigProvider { - public function __construct(?string $file = null, bool $parseEnv = false) + /** + * @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) { if($file !== null) { @@ -14,9 +18,15 @@ public function __construct(?string $file = null, bool $parseEnv = false) } /** - * @throws RuntimeException + * 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 */ - public function loadFile(string $fullPath, bool $parseEnv = false): static + public function loadFile($fullPath, $parseEnv = false) { if(!file_exists($fullPath)) { @@ -42,7 +52,16 @@ public function loadFile(string $fullPath, bool $parseEnv = false): static return $this; } - public function loadFiles(array $paths, bool $parseEnv = false, bool $throw = false): static + /** + * 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) { foreach($paths as $path) { @@ -62,9 +81,15 @@ public function loadFiles(array $paths, bool $parseEnv = false, bool $throw = fa } /** - * @throws RuntimeException + * 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 */ - public function loadString(string $iniString, bool $parseEnv = false): static + public function loadString($iniString, $parseEnv = false) { $this->_loadString($iniString, $parseEnv); return $this; diff --git a/src/Provider/Test/TestConfigProvider.php b/src/Provider/Test/TestConfigProvider.php index 7c9aaa4..ce75523 100644 --- a/src/Provider/Test/TestConfigProvider.php +++ b/src/Provider/Test/TestConfigProvider.php @@ -3,7 +3,15 @@ use Packaged\Config\Provider\ConfigProvider; -/** @deprecated Use \Packaged\Config\Provider\ConfigProvider directly */ +/** + * @deprecated \Packaged\Config\Provider\ConfigProvider + * + * Class TestConfigProvider + * + * Config provider for testing basics + * + * @package Packaged\Config\Provider\Test + */ class TestConfigProvider extends ConfigProvider { } diff --git a/src/Provider/Test/TestConfigSection.php b/src/Provider/Test/TestConfigSection.php index eb73e2f..6570af9 100644 --- a/src/Provider/Test/TestConfigSection.php +++ b/src/Provider/Test/TestConfigSection.php @@ -3,7 +3,15 @@ use Packaged\Config\Provider\ConfigSection; -/** @deprecated Use \Packaged\Config\Provider\ConfigSection directly */ +/** + * @deprecated \Packaged\Config\Provider\ConfigSection + * + * Class TestConfigSection + * + * Configuration section + * + * @package Packaged\Config\Provider\Test + */ class TestConfigSection extends ConfigSection { } diff --git a/tests/ConfigProviderBaseTest.php b/tests/ConfigProviderBaseTest.php index 36d416c..2c7f5fd 100644 --- a/tests/ConfigProviderBaseTest.php +++ b/tests/ConfigProviderBaseTest.php @@ -5,7 +5,6 @@ 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 @@ -16,7 +15,10 @@ public function testCanBeLoaded() $this->assertNotNull($provider); } - abstract public function getConfigProvider(): ConfigProviderInterface; + /** + * @return ConfigProviderInterface + */ + abstract public function getConfigProvider(); public function testValidProvider() { @@ -27,7 +29,9 @@ public function testValidProvider() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddItem() { $provider = $this->getConfigProvider(); @@ -54,7 +58,9 @@ public function testCanAddItem() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddItemAndRetrieve() { $provider = $this->getConfigProvider(); @@ -63,7 +69,9 @@ public function testCanAddItemAndRetrieve() $this->assertEquals("localhost", $item); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddItemAndRetrieveSection() { $provider = $this->getConfigProvider(); @@ -75,7 +83,9 @@ public function testCanAddItemAndRetrieveSection() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddRemoveItem() { $provider = $this->getConfigProvider(); @@ -85,7 +95,9 @@ public function testCanAddRemoveItem() $this->assertEquals("rm", $provider->getItem("db", "hostname", 'rm')); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testGetSections() { $provider = $this->getConfigProvider(); @@ -101,7 +113,9 @@ public function testGetSections() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionAdd() { $section = new ConfigSection("db"); @@ -115,7 +129,9 @@ public function testSectionAdd() $provider->addSection($section); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionSet() { $section = new ConfigSection("db"); @@ -127,7 +143,9 @@ public function testSectionSet() $provider->setSection($section); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionGetItem() { $provider = $this->getConfigProvider(); @@ -136,7 +154,9 @@ public function testSectionGetItem() $this->assertEquals("localhost", $section->getItem("hostname", "notset")); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testMissingSectionThrows() { $provider = $this->getConfigProvider(); @@ -145,7 +165,9 @@ public function testMissingSectionThrows() $provider->getSection("database"); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testMissingSectionNoThrow() { $provider = $this->getConfigProvider(); @@ -154,7 +176,9 @@ public function testMissingSectionNoThrow() $this->assertEquals("missing", $section->getName()); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testGetMissingItem() { $provider = $this->getConfigProvider(); @@ -169,7 +193,9 @@ public function testGetMissingItem() $this->assertEquals("notset", $section->getItem("hostname", "notset")); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testDefaultExceptionThrown() { $provider = $this->getConfigProvider(); @@ -179,7 +205,9 @@ public function testDefaultExceptionThrown() $provider->getItem('', 'gone', new Exception("Config Item Not Found", 999)); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionExists() { $provider = $this->getConfigProvider(); @@ -198,7 +226,9 @@ public function testSectionExists() $this->assertFalse($provider->sectionExists("database")); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testHasItem() { $provider = $this->getConfigProvider(); @@ -209,7 +239,9 @@ 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 55b068c..a9dc72f 100644 --- a/tests/ConfigProviderTest.php +++ b/tests/ConfigProviderTest.php @@ -6,7 +6,7 @@ class ConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider(): ConfigProvider + public function getConfigProvider() { return new ConfigProvider([]); } diff --git a/tests/ConfigSectionBaseTest.php b/tests/ConfigSectionBaseTest.php index ab6e50d..fcad5d9 100644 --- a/tests/ConfigSectionBaseTest.php +++ b/tests/ConfigSectionBaseTest.php @@ -14,7 +14,10 @@ public function testNameSetAndGet() $this->assertEquals("testing", $section->getName()); } - abstract public function getConfigSection(): ConfigSectionInterface; + /** + * @return ConfigSectionInterface + */ + abstract public function getConfigSection(); public function testCanAddItemAndRetrieve() { diff --git a/tests/ConfigSectionTest.php b/tests/ConfigSectionTest.php index 9f3c72f..0820fc0 100644 --- a/tests/ConfigSectionTest.php +++ b/tests/ConfigSectionTest.php @@ -30,7 +30,10 @@ public function testArrayAccess() $section->getItem('ghj', new Exception("Config Item Not Found", 999)); } - public function getConfigSection(): ConfigSection + /** + * @return ConfigSectionInterface + */ + public function getConfigSection() { return new ConfigSection(); } diff --git a/tests/ConfigurableTraitTest.php b/tests/ConfigurableTraitTest.php index 2089cc3..73a11f4 100644 --- a/tests/ConfigurableTraitTest.php +++ b/tests/ConfigurableTraitTest.php @@ -28,7 +28,10 @@ class MockConfigurableTrait { use ConfigurableTrait; - public function config(): ConfigSectionInterface + /** + * @return ConfigSectionInterface + */ + public function config() { return $this->_config(); } diff --git a/tests/IniCachedConfigProviderTest.php b/tests/IniCachedConfigProviderTest.php index 1658ada..829fca1 100644 --- a/tests/IniCachedConfigProviderTest.php +++ b/tests/IniCachedConfigProviderTest.php @@ -3,9 +3,10 @@ namespace Packaged\Config\Test; use Packaged\Config\Provider\Ini\CachedIniConfigProvider; -use PHPUnit\Framework\Attributes\RequiresPhpExtension; -#[RequiresPhpExtension('apcu')] +/** + * @requires extension apcu + */ class IniCachedConfigProviderTest extends ConfigProviderBaseTest { public function testMissingLoadFile() @@ -15,12 +16,15 @@ public function testMissingLoadFile() $this->assertSame($provider, $result); } - public function getConfigProvider(): CachedIniConfigProvider + /** + * @return CachedIniConfigProvider + */ + public function getConfigProvider() { return new CachedIniConfigProvider(); } - private function _dataDir(): array + private function _dataDir() { return [__DIR__ . '/testData']; } @@ -59,10 +63,6 @@ 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 9126c57..9a2c2a2 100644 --- a/tests/IniConfigProviderTest.php +++ b/tests/IniConfigProviderTest.php @@ -15,7 +15,7 @@ public function testMissingLoadFile() $provider->loadFile($file); } - public function getConfigProvider(): IniConfigProvider + public function getConfigProvider() { return new IniConfigProvider(); } diff --git a/tests/TestConfigProviderTest.php b/tests/TestConfigProviderTest.php index 33b48cf..e199b2a 100644 --- a/tests/TestConfigProviderTest.php +++ b/tests/TestConfigProviderTest.php @@ -6,7 +6,7 @@ class TestConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider(): TestConfigProvider + public function getConfigProvider() { return new TestConfigProvider(); } diff --git a/tests/TestConfigSectionTest.php b/tests/TestConfigSectionTest.php index 34eade8..7763e24 100644 --- a/tests/TestConfigSectionTest.php +++ b/tests/TestConfigSectionTest.php @@ -7,7 +7,10 @@ class TestConfigSectionTest extends ConfigSectionBaseTest { - public function getConfigSection(): TestConfigSection + /** + * @return ConfigSectionInterface + */ + public function getConfigSection() { return new TestConfigSection(); }