From 62a781560e8e3c81386a8df90119bf1d46937bfe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 18:59:36 +0200 Subject: [PATCH 1/5] Use more readable way to call dynamic function --- packages/framework/src/Facades/Config.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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))); } From 879658ef79bfbe2204a2d673d41c54cc2ce98ba1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 18:55:24 +0200 Subject: [PATCH 2/5] Add missing test --- .../framework/tests/Feature/TypedConfigFacadeTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) 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]); From 26b727f2830db77067216eb612f2f5a449685425 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 20:05:33 +0200 Subject: [PATCH 3/5] Replace if blocks with single match expression --- .../Features/Metadata/MetadataBag.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) 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 From 125a57fa0fb7928ba266d93d6b537c038265dfc7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 20:08:26 +0200 Subject: [PATCH 4/5] Merge coverage annotations --- .../tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 From f7a13bc452b323d3f09e4059b86a487409616d6f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 20:14:20 +0200 Subject: [PATCH 5/5] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.