Skip to content

Commit c00dbf4

Browse files
authored
Merge pull request #1411 from hydephp/code-quality
General code quality cleanups
2 parents 68471d7 + f7a13bc commit c00dbf4

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

RELEASE_NOTES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This serves two purposes:
2222
- 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)
2323
- 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
2424
- Narrows down parsed `BladeMatter` array types to `array<string, scalar>` (Experimental feature not covered by BC promise) in https://github.com/hydephp/develop/pull/1410
25-
- Internal code refactors and improvements in https://github.com/hydephp/develop/pull/1410
25+
- Internal code refactors and improvements in https://github.com/hydephp/develop/pull/1410 and https://github.com/hydephp/develop/pull/1411
2626

2727
### Deprecated
2828
- for soon-to-be removed features.

packages/framework/src/Facades/Config.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use TypeError;
88

99
use function sprintf;
10+
use function call_user_func;
1011

1112
/**
1213
* An extension of the Laravel Config facade with extra
@@ -56,7 +57,7 @@ public static function getNullableString(string $key, string $default = null): ?
5657

5758
protected static function validated(mixed $value, string $type, string $key): mixed
5859
{
59-
if (! ("is_$type")($value)) {
60+
if (! call_user_func("is_$type", $value)) {
6061
throw new TypeError(sprintf('%s(): Config value %s must be of type %s, %s given', __METHOD__, $key, $type, gettype($value)));
6162
}
6263

packages/framework/src/Framework/Features/Metadata/MetadataBag.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,12 @@ public function get(): array
5454

5555
public function add(MetadataElementContract|string $element): static
5656
{
57-
if ($element instanceof LinkElement) {
58-
return $this->addElement('links', $element);
59-
}
60-
61-
if ($element instanceof MetadataElement) {
62-
return $this->addElement('metadata', $element);
63-
}
64-
65-
if ($element instanceof OpenGraphElement) {
66-
return $this->addElement('properties', $element);
67-
}
68-
69-
return $this->addGenericElement((string) $element);
57+
return match (true) {
58+
$element instanceof LinkElement => $this->addElement('links', $element),
59+
$element instanceof MetadataElement => $this->addElement('metadata', $element),
60+
$element instanceof OpenGraphElement => $this->addElement('properties', $element),
61+
default => $this->addGenericElement((string) $element),
62+
};
7063
}
7164

7265
protected function addElement(string $type, MetadataElementContract $element): static

packages/framework/tests/Feature/TypedConfigFacadeTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Hyde\Facades\Config;
88
use Hyde\Testing\TestCase;
99
use TypeError;
10+
use stdClass;
1011

1112
use function config;
1213

@@ -159,6 +160,14 @@ public function testGetNullableString()
159160
$this->assertNull(Config::getNullableString('foo'));
160161
}
161162

163+
public function testInvalidTypeMessage()
164+
{
165+
config(['foo' => new stdClass()]);
166+
$this->expectException(TypeError::class);
167+
$this->expectExceptionMessage('Hyde\Facades\Config::validated(): Config value foo must be of type array, object given');
168+
Config::getArray('foo');
169+
}
170+
162171
protected function runUnitTest($actual, $expected, $method): void
163172
{
164173
config(['foo' => $actual]);

packages/framework/tests/Unit/Foundation/HyperlinksUrlPathHelpersTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
use Hyde\Testing\TestCase;
1111

1212
/**
13-
* @covers \Hyde\Foundation\Kernel\Hyperlinks::hasSiteUrl
14-
* @covers \Hyde\Foundation\Kernel\Hyperlinks::url
13+
* @covers \Hyde\Foundation\Kernel\Hyperlinks
1514
* @covers \Hyde\Framework\Exceptions\BaseUrlNotSetException
1615
*/
1716
class HyperlinksUrlPathHelpersTest extends TestCase

0 commit comments

Comments
 (0)