From cb822151b30e9c6ad34f8350d1d46bece864a222 Mon Sep 17 00:00:00 2001
From: Michael Sievenpiper
Date: Fri, 15 May 2026 15:43:40 +0100
Subject: [PATCH] - php 8.4 support including fixing notices and deprecations
---
.github/workflows/phpunit.yml | 2 +-
composer.json | 4 +-
phpunit.xml | 24 +--
src/ConfigProviderInterface.php | 95 ++--------
src/ConfigSectionInterface.php | 42 +----
src/ConfigurableInterface.php | 9 +-
src/ConfigurableTrait.php | 21 +--
src/Provider/AbstractConfigProvider.php | 126 +++----------
src/Provider/ConfigSection.php | 168 +++---------------
.../Ini/AbstractIniConfigProvider.php | 20 +--
src/Provider/Ini/CachedIniConfigProvider.php | 4 +-
src/Provider/Ini/IniConfigProvider.php | 37 +---
src/Provider/Test/TestConfigProvider.php | 10 +-
src/Provider/Test/TestConfigSection.php | 10 +-
tests/ConfigProviderBaseTest.php | 66 ++-----
tests/ConfigProviderTest.php | 2 +-
tests/ConfigSectionBaseTest.php | 5 +-
tests/ConfigSectionTest.php | 5 +-
tests/ConfigurableTraitTest.php | 5 +-
tests/IniCachedConfigProviderTest.php | 16 +-
tests/IniConfigProviderTest.php | 2 +-
tests/TestConfigProviderTest.php | 2 +-
tests/TestConfigSectionTest.php | 5 +-
23 files changed, 138 insertions(+), 542 deletions(-)
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 @@
-
-
-
- src
-
-
+tests
+ tests/ConfigProviderBaseTest.php
+ tests/ConfigSectionBaseTest.php
+
+
+ src
+
+
diff --git a/src/ConfigProviderInterface.php b/src/ConfigProviderInterface.php
index a3df917..9ee61d0 100644
--- a/src/ConfigProviderInterface.php
+++ b/src/ConfigProviderInterface.php
@@ -15,106 +15,39 @@ interface ConfigProviderInterface
*
* @return ConfigSectionInterface[]
*/
- public function getSections();
+ public function getSections(): array;
/**
- * @param string $name Name/Key of the configuration section
- *
- * @return ConfigSectionInterface
- * @throws \Exception
+ * @throws \Exception when the section does not exist (and $throw is true)
*/
- public function getSection($name);
+ public function getSection(string $name): ConfigSectionInterface;
/**
- * @param ConfigSectionInterface $section Section container to add
- *
- * @return $this
* @throws \Exception when the section already exists
*/
- public function addSection(ConfigSectionInterface $section);
+ public function addSection(ConfigSectionInterface $section): static;
/**
* Same as addSection, however, will replace an existing section if one exists
- *
- * @param ConfigSectionInterface $section Section container to add
- *
- * @return $this
*/
- public function setSection(ConfigSectionInterface $section);
+ public function setSection(ConfigSectionInterface $section): static;
- /**
- * Check to see if a section exists within the configuration
- *
- * @param string $name Section name
- *
- * @return bool
- */
- public function sectionExists($name);
+ public function sectionExists(string $name): bool;
- /**
- * Check to see if a section exists within the configuration
- *
- * @param string $name Section name
- *
- * @return bool
- */
- public function has($name);
+ public function has(string $name): bool;
/**
- * @param string $section Section Name
- * @param string $key Config Item Key
- * @param mixed $default Default value for missing item
- *
- * @return mixed Configuration Value
- *
- * @throws \Exception when default is passed as an exception
+ * @throws \Exception when $default is passed as an Exception
*/
- public function getItem($section, $key, $default = null);
+ public function getItem(string $section, string $key, mixed $default = null): mixed;
- /**
- * @param string $section Section Name
- * @param string $key Config Item Key
- *
- * @return bool
- */
- public function hasItem($section, $key);
+ public function hasItem(string $section, string $key): bool;
- /**
- * Add an item to the configuration
- *
- * @param string $section Section Name
- * @param string $item Config Item Key
- * @param mixed $value Config Item Value
- *
- * @return $this
- */
- public function addItem($section, $item, $value);
+ public function addItem(string $section, string $item, mixed $value): static;
- /**
- * Remove an item from the configuration
- *
- * @param $section
- * @param $item
- *
- * @return $this
- */
- public function removeItem($section, $item);
+ public function removeItem(string $section, string $item): static;
- /**
- * Remove a section from the configuration
- *
- * @param ConfigSectionInterface $section Section container to remove
- *
- * @return $this
- */
- public function removeSection(ConfigSectionInterface $section);
+ public function removeSection(ConfigSectionInterface $section): static;
- /**
- * Remove a section from the configuration by its name
- *
- * @param string $sectionName Section name to remove
- *
- * @return $this
- */
- public function removeSectionByName($sectionName);
+ public function removeSectionByName(string $sectionName): static;
}
diff --git a/src/ConfigSectionInterface.php b/src/ConfigSectionInterface.php
index 3f62978..0df78fc 100644
--- a/src/ConfigSectionInterface.php
+++ b/src/ConfigSectionInterface.php
@@ -14,64 +14,38 @@ interface ConfigSectionInterface
{
/**
* Get the name of the current section e.g. database
- *
- * @return string
*/
- public function getName();
+ public function getName(): string;
/**
* Name the current section
- *
- * @param string $name Name of this section
- *
- * @return $this
*/
- public function setName($name);
+ public function setName(string $name): static;
/**
* Retrieve an item from the configuration
*
- * @param string $key Configuration item key e.g. hostname
- * @param mixed $default Default value if the config item does not exist
- *
- * @return mixed
- *
- * @throws \Exception when default is passed as an exception
+ * @throws \Exception when $default is passed as an Exception
*/
- public function getItem($key, $default = null);
+ public function getItem(string $key, mixed $default = null): mixed;
/**
* Check to see if a config item exists within the configuration
- *
- * @param $key
- *
- * @return bool
*/
- public function has($key);
+ public function has(string $key): bool;
/**
* Retrieve all the items in the configuration section
- *
- * @return array
*/
- public function getItems();
+ public function getItems(): array;
/**
* Add an item to the configuration section
- *
- * @param string $item Config Item Key
- * @param mixed $value Config Item Value
- *
- * @return $this
*/
- public function addItem($item, $value);
+ public function addItem(string $item, mixed $value): static;
/**
* Remove a configuration item
- *
- * @param string $key Configuration item key e.g. hostname
- *
- * @return $this
*/
- public function removeItem($key);
+ public function removeItem(string $key): static;
}
diff --git a/src/ConfigurableInterface.php b/src/ConfigurableInterface.php
index 0bcf4de..dc01289 100644
--- a/src/ConfigurableInterface.php
+++ b/src/ConfigurableInterface.php
@@ -3,12 +3,5 @@
interface ConfigurableInterface
{
- /**
- * Configure the data connection
- *
- * @param ConfigSectionInterface $configuration
- *
- * @return static
- */
- public function configure(ConfigSectionInterface $configuration);
+ public function configure(ConfigSectionInterface $configuration): static;
}
diff --git a/src/ConfigurableTrait.php b/src/ConfigurableTrait.php
index 2e234e7..d9624ea 100644
--- a/src/ConfigurableTrait.php
+++ b/src/ConfigurableTrait.php
@@ -5,30 +5,15 @@
trait ConfigurableTrait
{
- /**
- * @var ConfigSectionInterface
- */
- protected $_configuration;
+ protected ?ConfigSectionInterface $_configuration = null;
- /**
- * Configure the data connection
- *
- * @param ConfigSectionInterface $configuration
- *
- * @return $this
- */
- public function configure(ConfigSectionInterface $configuration)
+ public function configure(ConfigSectionInterface $configuration): static
{
$this->_configuration = $configuration;
return $this;
}
- /**
- * Retrieve the configuration
- *
- * @return ConfigSectionInterface
- */
- protected function _config()
+ protected function _config(): ConfigSectionInterface
{
if($this->_configuration === null)
{
diff --git a/src/Provider/AbstractConfigProvider.php b/src/Provider/AbstractConfigProvider.php
index 5b4b615..4f7d910 100644
--- a/src/Provider/AbstractConfigProvider.php
+++ b/src/Provider/AbstractConfigProvider.php
@@ -7,22 +7,11 @@
abstract class AbstractConfigProvider implements ConfigProviderInterface
{
- /**
- * @var ConfigSection[]
- */
- protected $_sections;
+ /** @var ConfigSection[] */
+ protected array $_sections = [];
- /**
- * Add an item to the configuration
- *
- * @param string $section Section Name
- * @param string $item Config Item Key
- * @param mixed $value Config Item Value
- *
- * @return $this
- * @throws \RuntimeException
- */
- public function addItem($section, $item, $value)
+ #[\Override]
+ public function addItem(string $section, string $item, mixed $value): static
{
if(isset($this->_sections[$section]))
{
@@ -36,15 +25,8 @@ public function addItem($section, $item, $value)
return $this;
}
- /**
- * Remove an item from the configuration
- *
- * @param $section
- * @param $item
- *
- * @return $this
- */
- public function removeItem($section, $item)
+ #[\Override]
+ public function removeItem(string $section, string $item): static
{
if(isset($this->_sections[$section]))
{
@@ -53,16 +35,8 @@ public function removeItem($section, $item)
return $this;
}
- /**
- * @param string $section Section Name
- * @param string $key Config Item Key
- * @param mixed $default Default value for missing item
- *
- * @return mixed Configuration Value
- *
- * @throws \Exception when default is passed as an exception
- */
- public function getItem($section, $key, $default = null)
+ #[\Override]
+ public function getItem(string $section, string $key, mixed $default = null): mixed
{
if(!$this->sectionExists($section))
{
@@ -75,13 +49,8 @@ public function getItem($section, $key, $default = null)
return $this->getSection($section)->getItem($key, $default);
}
- /**
- * @param string $section Section Name
- * @param string $key Config Item Key
- *
- * @return bool
- */
- public function hasItem($section, $key)
+ #[\Override]
+ public function hasItem(string $section, string $key): bool
{
try
{
@@ -94,24 +63,18 @@ public function hasItem($section, $key)
}
/**
- * Retrieve all configuration sections
- *
* @return ConfigSectionInterface[]
*/
- public function getSections()
+ #[\Override]
+ public function getSections(): array
{
return $this->_sections;
}
/**
- * @param string $name Name/Key of the configuration section
- *
- * @param bool $throw
- *
- * @return ConfigSectionInterface
- * @throws Exception
+ * @throws Exception when the section does not exist and $throw is true
*/
- public function getSection($name, $throw = true)
+ public function getSection(string $name, bool $throw = true): ConfigSectionInterface
{
if(isset($this->_sections[$name]))
{
@@ -124,39 +87,20 @@ public function getSection($name, $throw = true)
throw new Exception("Configuration section $name could not be found");
}
- /**
- * Check to see if a section exists within the configuration
- *
- * @alias has
- *
- * @param string $name Section name
- *
- * @return bool
- */
- public function sectionExists($name)
+ #[\Override]
+ public function sectionExists(string $name): bool
{
return isset($this->_sections[$name]);
}
- /**
- * Check to see if a section exists within the configuration
- *
- * @param string $name Section name
- *
- * @return bool
- */
- public function has($name)
+ #[\Override]
+ public function has(string $name): bool
{
return isset($this->_sections[$name]);
}
- /**
- * @param ConfigSectionInterface $section Section container to add
- *
- * @return $this
- * @throws \Exception when the section already exists
- */
- public function addSection(ConfigSectionInterface $section)
+ #[\Override]
+ public function addSection(ConfigSectionInterface $section): static
{
if($this->sectionExists($section->getName()))
{
@@ -169,40 +113,22 @@ public function addSection(ConfigSectionInterface $section)
return $this;
}
- /**
- * Same as addSection, however, will replace an existing section if one exists
- *
- * @param ConfigSectionInterface $section Section container to add
- *
- * @return $this
- */
- public function setSection(ConfigSectionInterface $section)
+ #[\Override]
+ public function setSection(ConfigSectionInterface $section): static
{
$this->_sections[$section->getName()] = $section;
return $this;
}
- /**
- * Remove a section from the configuration
- *
- * @param ConfigSectionInterface $section Section container to remove
- *
- * @return $this
- */
- public function removeSection(ConfigSectionInterface $section)
+ #[\Override]
+ public function removeSection(ConfigSectionInterface $section): static
{
$this->removeSectionByName($section->getName());
return $this;
}
- /**
- * Remove a section from the configuration by its name
- *
- * @param string $sectionName Section name to remove
- *
- * @return $this
- */
- public function removeSectionByName($sectionName)
+ #[\Override]
+ public function removeSectionByName(string $sectionName): static
{
if(isset($this->_sections[$sectionName]))
{
diff --git a/src/Provider/ConfigSection.php b/src/Provider/ConfigSection.php
index 7529f65..07572a8 100644
--- a/src/Provider/ConfigSection.php
+++ b/src/Provider/ConfigSection.php
@@ -5,117 +5,64 @@
use Exception;
use Packaged\Config\ConfigSectionInterface;
-/**
- * Configuration section
- */
class ConfigSection implements ConfigSectionInterface, ArrayAccess
{
- protected $_name;
- protected $_items;
+ protected string $_name;
+ protected array $_items;
- /**
- * @param string $name Name of this configuration section
- * @param array $items all configuration items e.g. [host => localhost]
- */
- public function __construct($name = '', array $items = [])
+ public function __construct(string $name = '', array $items = [])
{
$this->_name = $name;
$this->_items = $items;
}
- /**
- * Name the current section
- *
- * @param string $name Name of this section
- *
- * @return $this
- */
- public function setName($name)
+ #[\Override]
+ public function setName(string $name): static
{
$this->_name = $name;
return $this;
}
- /**
- * Get the name of the current section e.g. database
- *
- * @return string
- */
- public function getName()
+ #[\Override]
+ public function getName(): string
{
return $this->_name;
}
- /**
- * Check to see if a config item exists within the configuration
- *
- * @param $key
- *
- * @return bool
- */
- public function has($key)
+ #[\Override]
+ public function has(string $key): bool
{
return isset($this->_items[$key]);
}
- /**
- * Retrieve an item from the configuration
- *
- * @param string $key Configuration item key e.g. hostname
- * @param mixed $default Default value if the config item does not exist
- *
- * @return mixed
- *
- * @throws \Exception when default is passed as an exception
- */
- public function getItem($key, $default = null)
+ #[\Override]
+ public function getItem(string $key, mixed $default = null): mixed
{
if(isset($this->_items[$key]))
{
return $this->_items[$key];
}
- else
+ if($default instanceof Exception)
{
- if($default instanceof Exception)
- {
- throw $default;
- }
- return $default;
+ throw $default;
}
+ return $default;
}
- /**
- * Retrieve all the items in the configuration section
- *
- * @return array
- */
- public function getItems()
+ #[\Override]
+ public function getItems(): array
{
return $this->_items;
}
- /**
- * Add a new configuration item
- *
- * @param string $key Configuration item key e.g. hostname
- * @param mixed $value Configuration item value e.g. localhost
- *
- * @return $this
- */
- public function addItem($key, $value)
+ #[\Override]
+ public function addItem(string $key, mixed $value): static
{
$this->_items[$key] = $value;
return $this;
}
- /**
- * Add a new configuration item
- *
- * @param array $keyValueItems
- *
- * @return $this
- */
- public function addItems(array $keyValueItems)
+ public function addItems(array $keyValueItems): static
{
foreach($keyValueItems as $k => $v)
{
@@ -124,90 +71,33 @@ public function addItems(array $keyValueItems)
return $this;
}
- /**
- * Remove a configuration item
- *
- * @param string $key Configuration item key e.g. hostname
- *
- * @return $this
- */
- public function removeItem($key)
+ #[\Override]
+ public function removeItem(string $key): static
{
unset($this->_items[$key]);
return $this;
}
- /**
- * (PHP 5 >= 5.0.0)
- * Whether a offset exists
- *
- * @link http://php.net/manual/en/arrayaccess.offsetexists.php
- *
- * @param mixed $offset
- * An offset to check for.
- *
- *
- * @return boolean true on success or false on failure.
- *
- *
- * 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)
- * Offset to set
- *
- * @link http://php.net/manual/en/arrayaccess.offsetset.php
- *
- * @param mixed $offset