Skip to content

Commit

Permalink
Update to latest PHP 8.1 syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Nov 3, 2024
1 parent ed6335e commit be4269b
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 44 deletions.
6 changes: 1 addition & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
<InvalidNullableReturnType>
<code><![CDATA[string]]></code>
</InvalidNullableReturnType>
<InvalidToString>
<code><![CDATA[string]]></code>
</InvalidToString>
<LessSpecificImplementedReturnType>
<code><![CDATA[array{
* label: string|null,
Expand Down Expand Up @@ -130,7 +127,6 @@
null]]></code>
</MixedReturnStatement>
<NullableReturnStatement>
<code><![CDATA[$this->label]]></code>
<code><![CDATA[$this->label]]></code>
<code><![CDATA[$this->rel[$relation] ?? null]]></code>
<code><![CDATA[$this->rev[$relation] ??
Expand Down Expand Up @@ -910,7 +906,7 @@
</file>
<file src="test/View/ViewHelperManagerDelegatorFactoryTest.php">
<MissingClosureReturnType>
<code><![CDATA[function () use ($helpers) {]]></code>
<code><![CDATA[fn() => $helpers]]></code>
</MissingClosureReturnType>
</file>
</files>
6 changes: 1 addition & 5 deletions src/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,7 @@ public function getChildren()
{
$hash = key($this->index);

if (isset($this->pages[$hash])) {
return $this->pages[$hash];
}

return null;
return $this->pages[$hash] ?? null;
}

// Countable interface:
Expand Down
7 changes: 4 additions & 3 deletions src/Page/AbstractPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use Laminas\Permissions\Acl\Resource\ResourceInterface as AclResource;
use Laminas\Stdlib\ArrayUtils;
use Stringable;
use Traversable;

use function array_keys;
Expand All @@ -31,7 +32,7 @@
*
* @template-extends AbstractContainer<AbstractPage>
*/
abstract class AbstractPage extends AbstractContainer
abstract class AbstractPage extends AbstractContainer implements Stringable
{
/**
* Page label
Expand Down Expand Up @@ -1091,9 +1092,9 @@ public function __unset($name)
*
* @return string page label
*/
public function __toString()
public function __toString(): string
{
return $this->label;
return (string) $this->label;
}

// Public methods:
Expand Down
24 changes: 10 additions & 14 deletions src/Page/Mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
use function array_intersect_assoc;
use function array_merge;
use function count;
use function gettype;
use function is_object;
use function get_debug_type;
use function is_string;
use function sprintf;
use function strlen;
Expand Down Expand Up @@ -250,16 +249,13 @@ public function getHref()
$params['action'] = $param;
}

switch (true) {
case $this->getRoute() !== null || static::getDefaultRoute() !== null:
$name = $this->getRoute() ?? static::getDefaultRoute();
break;
case $this->getRouteMatch() !== null:
$name = $this->getRouteMatch()->getMatchedRouteName();
break;
default:
throw new Exception\DomainException('No route name could be found');
}
$name = match (true) {
$this->getRoute() !== null || static::getDefaultRoute() !== null
=> $this->getRoute() ?? static::getDefaultRoute(),
$this->getRouteMatch() !== null
=> $this->getRouteMatch()->getMatchedRouteName(),
default => throw new Exception\DomainException('No route name could be found'),
};

$options = ['name' => $name];

Expand Down Expand Up @@ -459,7 +455,7 @@ public function setRouteMatch($matches)
__METHOD__,
RouteMatch::class,
MvcRouter\RouteMatch::class,
is_object($matches) ? $matches::class : gettype($matches)
get_debug_type($matches)
));
}
$this->routeMatch = $matches;
Expand Down Expand Up @@ -517,7 +513,7 @@ public function setRouter($router)
__METHOD__,
RouteStackInterface::class,
MvcRouter\RouteStackInterface::class,
is_object($router) ? $router::class : gettype($router)
get_debug_type($router)
));
}
$this->router = $router;
Expand Down
4 changes: 2 additions & 2 deletions src/Page/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use function array_merge;
use function is_string;
use function substr;
use function str_ends_with;

/**
* Represents a page that is defined by specifying a URI
Expand Down Expand Up @@ -73,7 +73,7 @@ public function getHref()

$fragment = $this->getFragment();
if (null !== $fragment) {
if ('#' === substr($uri, -1)) {
if (str_ends_with($uri, '#')) {
return $uri . $fragment;
} else {
return $uri . '#' . $fragment;
Expand Down
6 changes: 1 addition & 5 deletions src/Service/ConstructedNavigationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
*/
class ConstructedNavigationFactory extends AbstractNavigationFactory
{
/** @var string|Config|array */
protected $config;

/**
* @param string|Config|array $config
*/
public function __construct($config)
public function __construct(protected $config)
{
$this->config = $config;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Service/NavigationAbstractServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Psr\Container\ContainerInterface;

use function is_array;
use function str_starts_with;
use function strlen;
use function strpos;
use function strtolower;
use function substr;

Expand Down Expand Up @@ -54,7 +54,7 @@ final class NavigationAbstractServiceFactory implements AbstractFactoryInterface
*/
public function canCreate(ContainerInterface $container, $requestedName)
{
if (0 !== strpos($requestedName, self::SERVICE_PREFIX)) {
if (! str_starts_with($requestedName, self::SERVICE_PREFIX)) {
return false;
}
$config = $this->getConfig($container);
Expand Down
4 changes: 2 additions & 2 deletions test/Page/MvcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function testActionAndControllerAccessors(): void
$msg = "'$invalid' is invalid for $setter(), but no ";
$msg .= 'Laminas\Navigation\Exception\InvalidArgumentException was thrown';
$this->fail($msg);
} catch (Navigation\Exception\InvalidArgumentException $e) {
} catch (Navigation\Exception\InvalidArgumentException) {
}
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ public function testRouteAccessor(): void
$msg = "'$invalid' is invalid for $setter(), but no ";
$msg .= 'Laminas\Navigation\Exception\InvalidArgumentException was thrown';
$this->fail($msg);
} catch (Navigation\Exception\InvalidArgumentException $e) {
} catch (Navigation\Exception\InvalidArgumentException) {
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions test/View/HelperConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public function testConfigureServiceManagerWithConfig(
],
'factories' => [
'Navigation' => DefaultNavigationFactory::class,
'ViewHelperManager' => function ($services) {
return new HelperPluginManager($services);
},
'ViewHelperManager' => fn($services) => new HelperPluginManager($services),
],
]);

Expand Down
4 changes: 1 addition & 3 deletions test/View/ViewHelperManagerDelegatorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public function testFactoryConfiguresViewHelperManagerWithNavigationHelpers(): v
{
$services = new ServiceManager();
$helpers = new HelperPluginManager($services);
$callback = function () use ($helpers) {
return $helpers;
};
$callback = fn() => $helpers;

$factory = new ViewHelperManagerDelegatorFactory();
$this->assertSame($helpers, $factory($services, 'ViewHelperManager', $callback));
Expand Down

0 comments on commit be4269b

Please sign in to comment.