diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b9119bd8bb5..5194be7073a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -22,7 +22,7 @@ This serves two purposes: - Updated the navigation menu generator to remove duplicates after running the sorting method in https://github.com/hydephp/develop/pull/1407 (fixes https://github.com/hydephp/develop/issues/1406) - Updated the exception message caused by missing source option for featured images to include the path of the file that caused the error in https://github.com/hydephp/develop/pull/1409 - Narrows down parsed `BladeMatter` array types to `array` (Experimental feature not covered by BC promise) in https://github.com/hydephp/develop/pull/1410 -- Internal code refactors and improvements in https://github.com/hydephp/develop/pull/1410 +- Internal code refactors and improvements in https://github.com/hydephp/develop/pull/1410 and https://github.com/hydephp/develop/pull/1411 ### Deprecated - for soon-to-be removed features. diff --git a/packages/framework/src/Facades/Config.php b/packages/framework/src/Facades/Config.php index aaaa51d508b..cc0c3b9ad41 100644 --- a/packages/framework/src/Facades/Config.php +++ b/packages/framework/src/Facades/Config.php @@ -7,6 +7,7 @@ use TypeError; use function sprintf; +use function call_user_func; /** * An extension of the Laravel Config facade with extra @@ -56,7 +57,7 @@ public static function getNullableString(string $key, string $default = null): ? protected static function validated(mixed $value, string $type, string $key): mixed { - if (! ("is_$type")($value)) { + if (! call_user_func("is_$type", $value)) { throw new TypeError(sprintf('%s(): Config value %s must be of type %s, %s given', __METHOD__, $key, $type, gettype($value))); } diff --git a/packages/framework/src/Framework/Features/Metadata/MetadataBag.php b/packages/framework/src/Framework/Features/Metadata/MetadataBag.php index 5d0c2aa40d6..ff8a036d516 100644 --- a/packages/framework/src/Framework/Features/Metadata/MetadataBag.php +++ b/packages/framework/src/Framework/Features/Metadata/MetadataBag.php @@ -54,19 +54,12 @@ public function get(): array public function add(MetadataElementContract|string $element): static { - if ($element instanceof LinkElement) { - return $this->addElement('links', $element); - } - - if ($element instanceof MetadataElement) { - return $this->addElement('metadata', $element); - } - - if ($element instanceof OpenGraphElement) { - return $this->addElement('properties', $element); - } - - return $this->addGenericElement((string) $element); + return match (true) { + $element instanceof LinkElement => $this->addElement('links', $element), + $element instanceof MetadataElement => $this->addElement('metadata', $element), + $element instanceof OpenGraphElement => $this->addElement('properties', $element), + default => $this->addGenericElement((string) $element), + }; } protected function addElement(string $type, MetadataElementContract $element): static diff --git a/packages/framework/tests/Feature/TypedConfigFacadeTest.php b/packages/framework/tests/Feature/TypedConfigFacadeTest.php index e216665362d..2f0afd3e26a 100644 --- a/packages/framework/tests/Feature/TypedConfigFacadeTest.php +++ b/packages/framework/tests/Feature/TypedConfigFacadeTest.php @@ -7,6 +7,7 @@ use Hyde\Facades\Config; use Hyde\Testing\TestCase; use TypeError; +use stdClass; use function config; @@ -159,6 +160,14 @@ public function testGetNullableString() $this->assertNull(Config::getNullableString('foo')); } + public function testInvalidTypeMessage() + { + config(['foo' => new stdClass()]); + $this->expectException(TypeError::class); + $this->expectExceptionMessage('Hyde\Facades\Config::validated(): Config value foo must be of type array, object given'); + Config::getArray('foo'); + } + protected function runUnitTest($actual, $expected, $method): void { config(['foo' => $actual]); diff --git a/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php b/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php index 4e7811aa349..8a400d7a78b 100644 --- a/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php +++ b/packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php @@ -10,8 +10,7 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Foundation\Kernel\Hyperlinks::hasSiteUrl - * @covers \Hyde\Foundation\Kernel\Hyperlinks::url + * @covers \Hyde\Foundation\Kernel\Hyperlinks * @covers \Hyde\Framework\Exceptions\BaseUrlNotSetException */ class HyperlinksUrlPathHelpersTest extends TestCase