diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index b6e24dd6..f5afcbc5 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -70,9 +70,6 @@
-
-
-
- label]]>
label]]>
rel[$relation] ?? null]]>
rev[$relation] ??
@@ -910,7 +906,7 @@
-
+ $helpers]]>
diff --git a/src/AbstractContainer.php b/src/AbstractContainer.php
index d395f811..bccd4f62 100644
--- a/src/AbstractContainer.php
+++ b/src/AbstractContainer.php
@@ -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:
diff --git a/src/Page/AbstractPage.php b/src/Page/AbstractPage.php
index d34c9e90..ae4a58c5 100644
--- a/src/Page/AbstractPage.php
+++ b/src/Page/AbstractPage.php
@@ -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;
@@ -31,7 +32,7 @@
*
* @template-extends AbstractContainer
*/
-abstract class AbstractPage extends AbstractContainer
+abstract class AbstractPage extends AbstractContainer implements Stringable
{
/**
* Page label
@@ -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:
diff --git a/src/Page/Mvc.php b/src/Page/Mvc.php
index 73f3bc7e..622863dc 100644
--- a/src/Page/Mvc.php
+++ b/src/Page/Mvc.php
@@ -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;
@@ -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];
@@ -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;
@@ -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;
diff --git a/src/Page/Uri.php b/src/Page/Uri.php
index 213ce119..312bd2c8 100644
--- a/src/Page/Uri.php
+++ b/src/Page/Uri.php
@@ -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
@@ -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;
diff --git a/src/Service/ConstructedNavigationFactory.php b/src/Service/ConstructedNavigationFactory.php
index e7fea9b4..7a85bb80 100644
--- a/src/Service/ConstructedNavigationFactory.php
+++ b/src/Service/ConstructedNavigationFactory.php
@@ -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;
}
/**
diff --git a/src/Service/NavigationAbstractServiceFactory.php b/src/Service/NavigationAbstractServiceFactory.php
index 16bc36a0..5cf731ae 100644
--- a/src/Service/NavigationAbstractServiceFactory.php
+++ b/src/Service/NavigationAbstractServiceFactory.php
@@ -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;
@@ -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);
diff --git a/test/Page/MvcTest.php b/test/Page/MvcTest.php
index a97cd437..4c9e2bcc 100644
--- a/test/Page/MvcTest.php
+++ b/test/Page/MvcTest.php
@@ -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) {
}
}
}
@@ -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) {
}
}
}
diff --git a/test/View/HelperConfigTest.php b/test/View/HelperConfigTest.php
index 46387102..191f0a05 100644
--- a/test/View/HelperConfigTest.php
+++ b/test/View/HelperConfigTest.php
@@ -72,9 +72,7 @@ public function testConfigureServiceManagerWithConfig(
],
'factories' => [
'Navigation' => DefaultNavigationFactory::class,
- 'ViewHelperManager' => function ($services) {
- return new HelperPluginManager($services);
- },
+ 'ViewHelperManager' => fn($services) => new HelperPluginManager($services),
],
]);
diff --git a/test/View/ViewHelperManagerDelegatorFactoryTest.php b/test/View/ViewHelperManagerDelegatorFactoryTest.php
index 866f7501..b9a7b776 100644
--- a/test/View/ViewHelperManagerDelegatorFactoryTest.php
+++ b/test/View/ViewHelperManagerDelegatorFactoryTest.php
@@ -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));