diff --git a/src/Config.php b/src/Config.php index e6de5a5..89f79cd 100644 --- a/src/Config.php +++ b/src/Config.php @@ -4,6 +4,7 @@ namespace Roots\WPConfig; use Roots\WPConfig\Exceptions\ConstantAlreadyDefinedException; +use Roots\WPConfig\Exceptions\NumericConstantNameException; use Roots\WPConfig\Exceptions\UndefinedConfigKeyException; /** @@ -24,6 +25,10 @@ class Config */ public static function define(string $key, $value): void { + if (is_numeric($key)) { + throw new NumericConstantNameException("Numeric constant name '$key' is not allowed."); + } + self::defined($key) or self::$configMap[$key] = $value; } diff --git a/src/Exceptions/NumericConstantNameException.php b/src/Exceptions/NumericConstantNameException.php new file mode 100644 index 0000000..4e5c431 --- /dev/null +++ b/src/Exceptions/NumericConstantNameException.php @@ -0,0 +1,9 @@ +assertEquals(true, Config::get('WP_SCRIPT_DEBUG')); } + + public function testDefineSadIntegerKey() { + $this->expectException(NumericConstantNameException::class); + + Config::define('123', true); + } public function testDefineSad() { $this->expectException(ConstantAlreadyDefinedException::class);