Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/phpcompatibility-wp": "*",
"phpunit/phpunit": "^9.6",
"rector/rector": "^2.5",
"rector/rector": "2.7.0",
"captainhook/captainhook": "^5.29",
"captainhook/hook-installer": "^1.0"
},
Expand Down
4 changes: 1 addition & 3 deletions src/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function store(?string $name = null): Repository
{
$name ??= $this->defaultStoreName();

if (!isset($this->repositories[$name])) {
$this->repositories[$name] = new Repository($this->makeStore($name));
}
$this->repositories[$name] ??= new Repository($this->makeStore($name));

return $this->repositories[$name];
}
Expand Down
4 changes: 1 addition & 3 deletions src/Hooks/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ final class Hooks

public function __construct()
{
if (!isset(self::$_hook)) {
self::$_hook = new HooksWrapper();
}
self::$_hook ??= new HooksWrapper();
}

public function __call(string $method, array $parameters)
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Detection/ClientIpResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static function isTrustedProxy(string $ip): bool
return false;
}

private static function isIpInRange(string $ip, $range)
private static function isIpInRange(string $ip, $range): bool
{
$range = trim((string) $range);
if (!str_contains($range, '/')) {
Expand Down
4 changes: 1 addition & 3 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ private static function validateHeader($header, $value): array

private static function current(): Response
{
if (\is_null(self::$_current)) {
self::$_current = new self();
}
self::$_current ??= new self();

return self::$_current;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Router/AjaxRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function currentRoute()
return $this->_router->getRegisteredRoute($this->currentRouteName());
}

private function isRouteMatched(RouteRegister $route, string|array $requestPath)
private function isRouteMatched(RouteRegister $route, string|array $requestPath): bool
{
if ($route->getRoutePrefix() . $route->getPath() === $requestPath) {
return true;
Expand Down
4 changes: 1 addition & 3 deletions src/Http/Router/RouteBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ public function group(Closure $callback): self
*/
public function getRouter()
{
if (!isset($this->_router)) {
$this->_router = Router::instance();
}
$this->_router ??= Router::instance();

return $this->_router;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Http/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public function getRegisteredRoutes(): array
public static function instance($type = null, $namespace = null, $version = null)
{
if ($type === null) {
if (\is_null(self::$_instance)) {
self::$_instance = new self(RequestType::AJAX, $namespace, $version);
}
self::$_instance ??= new self(RequestType::AJAX, $namespace, $version);

return self::$_instance;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Settings/SettingsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public function get(string $key, $default = null)
}

$field = $this->schema->field($key);
if ($field === null) {
return $default;
}

return $field !== null ? $field->default() : $default;
// A declared field's own default wins, even when it is null.
return $field->default();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Shortcode/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ final class Shortcode

public function __construct()
{
if (!isset(self::$_wrapper)) {
self::$_wrapper = new ShortcodeWrapper();
}
self::$_wrapper ??= new ShortcodeWrapper();
}

public function __call(string $method, array $parameters)
Expand Down
9 changes: 9 additions & 0 deletions tests/Settings/SettingsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public function testSetSaveReload(): void
$this->assertFalse($fresh->get('logging_enabled'));
}

public function testDeclaredNullDefaultWinsOverCallerFallback(): void
{
$schema = (new SettingsSchema())->add(SettingField::string('label', null));
$repo = new SettingsRepository('demo_settings', $schema);

$this->assertNull($repo->get('label', 'fallback'));
$this->assertSame('fallback', $repo->get('undeclared', 'fallback'));
}

public function testUnknownKeyRejected(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down
Loading