summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Http/Dispatcher.php81
-rw-r--r--app/Http/Middleware/Router.php56
-rw-r--r--app/Http/RequestHandlers/NotFound.php (renamed from app/Http/Middleware/NoRouteFound.php)24
-rw-r--r--app/Webtrees.php8
-rw-r--r--composer.json1
-rw-r--r--composer.lock151
-rw-r--r--phpstan-baseline.neon38
-rw-r--r--tests/app/Http/RequestHandlers/NotFoundTest.php (renamed from tests/app/Http/Middleware/NoRouteFoundTest.php)21
8 files changed, 165 insertions, 215 deletions
diff --git a/app/Http/Dispatcher.php b/app/Http/Dispatcher.php
new file mode 100644
index 0000000000..5b6d323601
--- /dev/null
+++ b/app/Http/Dispatcher.php
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2023 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http;
+
+use Fisharebest\Webtrees\Http\RequestHandlers\NotFound;
+use Fisharebest\Webtrees\Registry;
+use LogicException;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function array_reduce;
+use function array_reverse;
+use function is_string;
+
+readonly class Dispatcher
+{
+ /**
+ * @param list<class-string|MiddlewareInterface> $middleware
+ */
+ public static function dispatch(array $middleware, ServerRequestInterface $request): ResponseInterface
+ {
+ $pipeline = array_reduce(
+ array: array_reverse(array: $middleware),
+ callback: self::reduceMiddleware(...),
+ initial: new NotFound(),
+ );
+
+ return $pipeline->handle(request: $request);
+ }
+
+ /**
+ * @param class-string|MiddlewareInterface $item
+ */
+ private static function reduceMiddleware(RequestHandlerInterface $carry, string|MiddlewareInterface $item): RequestHandlerInterface
+ {
+ return new readonly class (carry: $carry, item: $item) implements RequestHandlerInterface {
+ /**
+ * @param class-string|MiddlewareInterface $item
+ */
+ public function __construct(
+ private RequestHandlerInterface $carry,
+ private string|MiddlewareInterface $item,
+ ) {
+ }
+
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $item = $this->item;
+
+ if (is_string($item)) {
+ $item = Registry::container()->get(id: $item);
+ }
+
+ if ($item instanceof MiddlewareInterface) {
+ return $item->process(request: $request, handler: $this->carry);
+ }
+
+ throw new LogicException(message: 'Invalid or undefined middleware');
+ }
+ };
+ }
+}
diff --git a/app/Http/Middleware/Router.php b/app/Http/Middleware/Router.php
index f066c9891f..082eeb2a4f 100644
--- a/app/Http/Middleware/Router.php
+++ b/app/Http/Middleware/Router.php
@@ -24,13 +24,12 @@ use Aura\Router\RouterContainer;
use Aura\Router\Rule\Accepts;
use Aura\Router\Rule\Allows;
use Fig\Http\Message\StatusCodeInterface;
+use Fisharebest\Webtrees\Http\Dispatcher;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Services\TreeService;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\Validator;
-use Fisharebest\Webtrees\Webtrees;
-use Middleland\Dispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
@@ -43,35 +42,15 @@ use function str_contains;
/**
* Simple class to help migrate to a third-party routing library.
*/
-class Router implements MiddlewareInterface
+readonly class Router implements MiddlewareInterface
{
- private ModuleService $module_service;
-
- private RouterContainer $router_container;
-
- private TreeService $tree_service;
-
- /**
- * @param ModuleService $module_service
- * @param RouterContainer $router_container
- * @param TreeService $tree_service
- */
public function __construct(
- ModuleService $module_service,
- RouterContainer $router_container,
- TreeService $tree_service
+ private ModuleService $module_service,
+ private RouterContainer $router_container,
+ private TreeService $tree_service
) {
- $this->module_service = $module_service;
- $this->router_container = $router_container;
- $this->tree_service = $tree_service;
}
- /**
- * @param ServerRequestInterface $request
- * @param RequestHandlerInterface $handler
- *
- * @return ResponseInterface
- */
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// Ugly URLs store the path in a query parameter.
@@ -116,31 +95,22 @@ class Router implements MiddlewareInterface
}
}
- // Not found
return $handler->handle($request);
}
// Add the route as attribute of the request
$request = $request->withAttribute('route', $route);
- // This middleware cannot run until after the routing, as it needs to know the route.
- $post_routing_middleware = [CheckCsrf::class];
-
- // Firstly, apply the route middleware
$route_middleware = $route->extras['middleware'] ?? [];
- // Secondly, apply any module middleware
$module_middleware = $this->module_service->findByInterface(MiddlewareInterface::class)->all();
- // Finally, run the handler using middleware
- $handler_middleware = [RequestHandler::class];
-
- $middleware = array_merge(
- $post_routing_middleware,
- $route_middleware,
- $module_middleware,
- $handler_middleware
- );
+ $middleware = [
+ ...$route_middleware,
+ CheckCsrf::class,
+ ...$module_middleware,
+ RequestHandler::class,
+ ];
// Add the matched attributes to the request.
foreach ($route->attributes as $key => $value) {
@@ -163,8 +133,6 @@ class Router implements MiddlewareInterface
// Bind the updated request into the container
Registry::container()->set(ServerRequestInterface::class, $request);
- $dispatcher = new Dispatcher($middleware, Registry::container());
-
- return $dispatcher->dispatch($request);
+ return Dispatcher::dispatch(middleware: $middleware, request: $request);
}
}
diff --git a/app/Http/Middleware/NoRouteFound.php b/app/Http/RequestHandlers/NotFound.php
index a8054ef560..feb67f368a 100644
--- a/app/Http/Middleware/NoRouteFound.php
+++ b/app/Http/RequestHandlers/NotFound.php
@@ -17,43 +17,29 @@
declare(strict_types=1);
-namespace Fisharebest\Webtrees\Http\Middleware;
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
use Fig\Http\Message\RequestMethodInterface;
use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
-use Fisharebest\Webtrees\Http\RequestHandlers\HomePage;
-use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\Registry;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
-use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function redirect;
use function route;
-/**
- * Middleware to generate a response when no route was matched.
- */
-class NoRouteFound implements MiddlewareInterface
+class NotFound implements RequestHandlerInterface
{
- use ViewResponseTrait;
-
- /**
- * @param ServerRequestInterface $request
- * @param RequestHandlerInterface $handler
- *
- * @return ResponseInterface
- */
- public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+ public function handle(ServerRequestInterface $request): ResponseInterface
{
- // Bind the request into the container. We'll need it to generate an error page.
+ // Need the request to generate a route/error page.
Registry::container()->set(ServerRequestInterface::class, $request);
if ($request->getMethod() !== RequestMethodInterface::METHOD_GET) {
throw new HttpNotFoundException();
}
- return redirect(route(HomePage::class));
+ return redirect(url: route(route_name: HomePage::class));
}
}
diff --git a/app/Webtrees.php b/app/Webtrees.php
index 83cf335975..a9f45eb5a9 100644
--- a/app/Webtrees.php
+++ b/app/Webtrees.php
@@ -48,6 +48,7 @@ use Fisharebest\Webtrees\Factories\TimeFactory;
use Fisharebest\Webtrees\Factories\TimestampFactory;
use Fisharebest\Webtrees\Factories\XrefFactory;
use Fisharebest\Webtrees\GedcomFilters\GedcomEncodingFilter;
+use Fisharebest\Webtrees\Http\Dispatcher;
use Fisharebest\Webtrees\Http\Middleware\BadBotBlocker;
use Fisharebest\Webtrees\Http\Middleware\BaseUrl;
use Fisharebest\Webtrees\Http\Middleware\BootModules;
@@ -61,7 +62,6 @@ use Fisharebest\Webtrees\Http\Middleware\EmitResponse;
use Fisharebest\Webtrees\Http\Middleware\ErrorHandler;
use Fisharebest\Webtrees\Http\Middleware\HandleExceptions;
use Fisharebest\Webtrees\Http\Middleware\LoadRoutes;
-use Fisharebest\Webtrees\Http\Middleware\NoRouteFound;
use Fisharebest\Webtrees\Http\Middleware\PublicFiles;
use Fisharebest\Webtrees\Http\Middleware\ReadConfigIni;
use Fisharebest\Webtrees\Http\Middleware\RegisterGedcomTags;
@@ -73,7 +73,6 @@ use Fisharebest\Webtrees\Http\Middleware\UseLanguage;
use Fisharebest\Webtrees\Http\Middleware\UseSession;
use Fisharebest\Webtrees\Http\Middleware\UseTheme;
use Fisharebest\Webtrees\Http\Middleware\UseTransaction;
-use Middleland\Dispatcher;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7Server\ServerRequestCreator;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -174,7 +173,6 @@ class Webtrees
RegisterGedcomTags::class,
BootModules::class,
Router::class,
- NoRouteFound::class,
];
public static function new(): self
@@ -275,8 +273,6 @@ class Webtrees
$request = $server_request_creator->fromGlobals();
- $dispatcher = new Dispatcher(self::MIDDLEWARE, Registry::container());
-
- return $dispatcher->dispatch($request);
+ return Dispatcher::dispatch(middleware: self::MIDDLEWARE, request: $request);
}
}
diff --git a/composer.json b/composer.json
index ca18d3a33c..32e0bd350e 100644
--- a/composer.json
+++ b/composer.json
@@ -61,7 +61,6 @@
"nesbot/carbon": "3.8.2",
"nyholm/psr7": "1.8.2",
"nyholm/psr7-server": "1.1.0",
- "oscarotero/middleland": "1.0.1",
"psr/cache": "3.0.0",
"psr/http-message": "1.1",
"psr/http-server-handler": "1.0.2",
diff --git a/composer.lock b/composer.lock
index ed3d5327f1..898a21edfd 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "2c47b6277e87896332e181dafea8132e",
+ "content-hash": "aade2e37db9c28f0fc8c8694618a1c0d",
"packages": [
{
"name": "aura/router",
@@ -1123,16 +1123,16 @@
},
{
"name": "illuminate/collections",
- "version": "v11.34.2",
+ "version": "v11.35.1",
"source": {
"type": "git",
"url": "https://github.com/illuminate/collections.git",
- "reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1"
+ "reference": "b8be9c0fedfc5be1524b290fed640d4b7d42c813"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/collections/zipball/fd2103ddc121449a7926fc34a9d220e5b88183c1",
- "reference": "fd2103ddc121449a7926fc34a9d220e5b88183c1",
+ "url": "https://api.github.com/repos/illuminate/collections/zipball/b8be9c0fedfc5be1524b290fed640d4b7d42c813",
+ "reference": "b8be9c0fedfc5be1524b290fed640d4b7d42c813",
"shasum": ""
},
"require": {
@@ -1152,6 +1152,7 @@
},
"autoload": {
"files": [
+ "functions.php",
"helpers.php"
],
"psr-4": {
@@ -1174,11 +1175,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-11-27T14:51:56+00:00"
+ "time": "2024-12-10T14:54:28+00:00"
},
{
"name": "illuminate/conditionable",
- "version": "v11.34.2",
+ "version": "v11.35.1",
"source": {
"type": "git",
"url": "https://github.com/illuminate/conditionable.git",
@@ -1224,16 +1225,16 @@
},
{
"name": "illuminate/container",
- "version": "v11.34.2",
+ "version": "v11.35.1",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
- "reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26"
+ "reference": "4a777578ce2388384565bf5c8e76881f0da68e54"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/container/zipball/b057b0bbb38d7c7524df1ca5c38e7318f4c64d26",
- "reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26",
+ "url": "https://api.github.com/repos/illuminate/container/zipball/4a777578ce2388384565bf5c8e76881f0da68e54",
+ "reference": "4a777578ce2388384565bf5c8e76881f0da68e54",
"shasum": ""
},
"require": {
@@ -1271,11 +1272,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2024-11-21T20:07:31+00:00"
+ "time": "2024-12-08T15:40:56+00:00"
},
{
"name": "illuminate/contracts",
- "version": "v11.34.2",
+ "version": "v11.35.1",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
@@ -1392,7 +1393,7 @@
},
{
"name": "illuminate/macroable",
- "version": "v11.34.2",
+ "version": "v11.35.1",
"source": {
"type": "git",
"url": "https://github.com/illuminate/macroable.git",
@@ -2713,63 +2714,6 @@
"time": "2023-11-08T09:30:43+00:00"
},
{
- "name": "oscarotero/middleland",
- "version": "v1.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/oscarotero/middleland.git",
- "reference": "4848543d59f753aa3352c52d88c66f978debafb2"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/oscarotero/middleland/zipball/4848543d59f753aa3352c52d88c66f978debafb2",
- "reference": "4848543d59f753aa3352c52d88c66f978debafb2",
- "shasum": ""
- },
- "require": {
- "php": "^7.0|^8.0",
- "psr/container": "^1.0",
- "psr/http-server-middleware": "^1.0"
- },
- "require-dev": {
- "friendsofphp/php-cs-fixer": "^2.0",
- "laminas/laminas-diactoros": "^1.3",
- "phpunit/phpunit": ">=6.0"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Middleland\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Oscar Otero",
- "email": "oom@oscarotero.com",
- "homepage": "http://oscarotero.com",
- "role": "Developer"
- }
- ],
- "description": "PSR-15 middleware dispatcher",
- "homepage": "https://github.com/oscarotero/dispatcher",
- "keywords": [
- "http",
- "middleware",
- "psr-15",
- "psr-7"
- ],
- "support": {
- "email": "oom@oscarotero.com",
- "issues": "https://github.com/oscarotero/dispatcher/issues",
- "source": "https://github.com/oscarotero/middleland/tree/v1.0.1"
- },
- "time": "2020-12-06T00:59:17+00:00"
- },
- {
"name": "psr/cache",
"version": "3.0.0",
"source": {
@@ -2868,22 +2812,27 @@
},
{
"name": "psr/container",
- "version": "1.1.2",
+ "version": "2.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
- "reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
+ "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
- "reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
+ "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963",
+ "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0.x-dev"
+ }
+ },
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
@@ -2910,9 +2859,9 @@
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
- "source": "https://github.com/php-fig/container/tree/1.1.2"
+ "source": "https://github.com/php-fig/container/tree/2.0.2"
},
- "time": "2021-11-05T16:50:12+00:00"
+ "time": "2021-11-05T16:47:00+00:00"
},
{
"name": "psr/event-dispatcher",
@@ -4506,16 +4455,16 @@
},
{
"name": "symfony/mime",
- "version": "v7.2.0",
+ "version": "v7.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/mime.git",
- "reference": "cc84a4b81f62158c3846ac7ff10f696aae2b524d"
+ "reference": "7f9617fcf15cb61be30f8b252695ed5e2bfac283"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/mime/zipball/cc84a4b81f62158c3846ac7ff10f696aae2b524d",
- "reference": "cc84a4b81f62158c3846ac7ff10f696aae2b524d",
+ "url": "https://api.github.com/repos/symfony/mime/zipball/7f9617fcf15cb61be30f8b252695ed5e2bfac283",
+ "reference": "7f9617fcf15cb61be30f8b252695ed5e2bfac283",
"shasum": ""
},
"require": {
@@ -4570,7 +4519,7 @@
"mime-type"
],
"support": {
- "source": "https://github.com/symfony/mime/tree/v7.2.0"
+ "source": "https://github.com/symfony/mime/tree/v7.2.1"
},
"funding": [
{
@@ -4586,7 +4535,7 @@
"type": "tidelift"
}
],
- "time": "2024-11-23T09:19:39+00:00"
+ "time": "2024-12-07T08:50:44+00:00"
},
{
"name": "symfony/polyfill-ctype",
@@ -4769,8 +4718,8 @@
"type": "library",
"extra": {
"thanks": {
- "name": "symfony/polyfill",
- "url": "https://github.com/symfony/polyfill"
+ "url": "https://github.com/symfony/polyfill",
+ "name": "symfony/polyfill"
}
},
"autoload": {
@@ -4935,8 +4884,8 @@
"type": "library",
"extra": {
"thanks": {
- "name": "symfony/polyfill",
- "url": "https://github.com/symfony/polyfill"
+ "url": "https://github.com/symfony/polyfill",
+ "name": "symfony/polyfill"
}
},
"autoload": {
@@ -6081,16 +6030,16 @@
},
{
"name": "phpunit/php-code-coverage",
- "version": "11.0.7",
+ "version": "11.0.8",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca"
+ "reference": "418c59fd080954f8c4aa5631d9502ecda2387118"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f7f08030e8811582cc459871d28d6f5a1a4d35ca",
- "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/418c59fd080954f8c4aa5631d9502ecda2387118",
+ "reference": "418c59fd080954f8c4aa5631d9502ecda2387118",
"shasum": ""
},
"require": {
@@ -6109,7 +6058,7 @@
"theseer/tokenizer": "^1.2.3"
},
"require-dev": {
- "phpunit/phpunit": "^11.4.1"
+ "phpunit/phpunit": "^11.5.0"
},
"suggest": {
"ext-pcov": "PHP extension that provides line coverage",
@@ -6147,7 +6096,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.7"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.8"
},
"funding": [
{
@@ -6155,7 +6104,7 @@
"type": "github"
}
],
- "time": "2024-10-09T06:21:38+00:00"
+ "time": "2024-12-11T12:34:27+00:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -6562,23 +6511,23 @@
},
{
"name": "sebastian/code-unit",
- "version": "3.0.1",
+ "version": "3.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/code-unit.git",
- "reference": "6bb7d09d6623567178cf54126afa9c2310114268"
+ "reference": "ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/6bb7d09d6623567178cf54126afa9c2310114268",
- "reference": "6bb7d09d6623567178cf54126afa9c2310114268",
+ "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca",
+ "reference": "ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca",
"shasum": ""
},
"require": {
"php": ">=8.2"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^11.5"
},
"type": "library",
"extra": {
@@ -6607,7 +6556,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/code-unit/issues",
"security": "https://github.com/sebastianbergmann/code-unit/security/policy",
- "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.1"
+ "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.2"
},
"funding": [
{
@@ -6615,7 +6564,7 @@
"type": "github"
}
],
- "time": "2024-07-03T04:44:28+00:00"
+ "time": "2024-12-12T09:59:06+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index ef2baed9b1..d63d13526b 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1303,19 +1303,19 @@ parameters:
path: app/Http/Middleware/RequestHandler.php
-
- message: '#^Parameter \#1 \$key of method Illuminate\\Support\\Collection\<\(int\|string\),Fisharebest\\Webtrees\\Tree\>\:\:get\(\) expects \(int\|string\), mixed given\.$#'
- identifier: argument.type
+ message: '#^Only iterables can be unpacked, mixed given\.$#'
+ identifier: arrayUnpacking.nonIterable
count: 1
path: app/Http/Middleware/Router.php
-
- message: '#^Parameter \#1 \$middleware of class Middleland\\Dispatcher constructor expects array\<array\|Closure\|Psr\\Http\\Server\\MiddlewareInterface\|string\>, non\-empty\-array given\.$#'
+ message: '#^Parameter \#1 \$key of method Illuminate\\Support\\Collection\<\(int\|string\),Fisharebest\\Webtrees\\Tree\>\:\:get\(\) expects \(int\|string\), mixed given\.$#'
identifier: argument.type
count: 1
path: app/Http/Middleware/Router.php
-
- message: '#^Parameter \#2 \.\.\.\$arrays of function array_merge expects array, mixed given\.$#'
+ message: '#^Parameter \$middleware of static method Fisharebest\\Webtrees\\Http\\Dispatcher\:\:dispatch\(\) expects list\<class\-string\|Psr\\Http\\Server\\MiddlewareInterface\>, non\-empty\-array given\.$#'
identifier: argument.type
count: 1
path: app/Http/Middleware/Router.php
@@ -2167,7 +2167,7 @@ parameters:
path: app/Http/RequestHandlers/MapDataImportAction.php
-
- message: '#^Parameter \#1 \$str of function strtr expects string, mixed given\.$#'
+ message: '#^Parameter \#1 \$str of function strtr expects string, string\|null given\.$#'
identifier: argument.type
count: 2
path: app/Http/RequestHandlers/MapDataImportAction.php
@@ -6421,19 +6421,19 @@ parameters:
path: app/Report/ReportParserGenerate.php
-
- message: '#^Property Fisharebest\\Webtrees\\Report\\ReportParserGenerate\:\:\$list \(array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\>\) does not accept array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\|null\>\.$#'
+ message: '#^Property Fisharebest\\Webtrees\\Report\\ReportParserGenerate\:\:\$list \(array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\>\) does not accept array\<Fisharebest\\Webtrees\\GedcomRecord\|null\>\.$#'
identifier: assign.propertyType
- count: 2
+ count: 1
path: app/Report/ReportParserGenerate.php
-
- message: '#^Property Fisharebest\\Webtrees\\Report\\ReportParserGenerate\:\:\$list \(array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\>\) does not accept array\<int, Fisharebest\\Webtrees\\GedcomRecord\|null\>\.$#'
+ message: '#^Property Fisharebest\\Webtrees\\Report\\ReportParserGenerate\:\:\$list \(array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\>\) does not accept array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\|null\>\.$#'
identifier: assign.propertyType
- count: 1
+ count: 2
path: app/Report/ReportParserGenerate.php
-
- message: '#^Property Fisharebest\\Webtrees\\Report\\ReportParserGenerate\:\:\$list \(array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\>\) does not accept array\<int\|string, Fisharebest\\Webtrees\\GedcomRecord\|null\>\.$#'
+ message: '#^Property Fisharebest\\Webtrees\\Report\\ReportParserGenerate\:\:\$list \(array\<Fisharebest\\Webtrees\\GedcomRecord\|static\(Fisharebest\\Webtrees\\Report\\ReportParserGenerate\)\>\) does not accept array\<int, Fisharebest\\Webtrees\\GedcomRecord\|null\>\.$#'
identifier: assign.propertyType
count: 1
path: app/Report/ReportParserGenerate.php
@@ -6883,12 +6883,6 @@ parameters:
path: app/Services/GedcomEditService.php
-
- message: '#^Parameter \#2 \$array of function implode expects array\<string\>, mixed given\.$#'
- identifier: argument.type
- count: 1
- path: app/Services/GedcomEditService.php
-
- -
message: '#^Parameter \#2 \$array of function implode expects array\|null, mixed given\.$#'
identifier: argument.type
count: 1
@@ -7879,12 +7873,6 @@ parameters:
path: app/Statistics/Google/ChartAge.php
-
- message: '#^Parameter \#1 \$century of method Fisharebest\\Webtrees\\Statistics\\Service\\CenturyService\:\:centuryName\(\) expects int, int\|string given\.$#'
- identifier: argument.type
- count: 1
- path: app/Statistics/Google/ChartAge.php
-
- -
message: '#^Parameter \#1 \$num of function round expects float\|int, mixed given\.$#'
identifier: argument.type
count: 2
@@ -8125,12 +8113,6 @@ parameters:
path: app/Statistics/Google/ChartMarriageAge.php
-
- message: '#^Parameter \#1 \$century of method Fisharebest\\Webtrees\\Statistics\\Service\\CenturyService\:\:centuryName\(\) expects int, int\|string given\.$#'
- identifier: argument.type
- count: 1
- path: app/Statistics/Google/ChartMarriageAge.php
-
- -
message: '#^Parameter \#1 \$num of function round expects float\|int, mixed given\.$#'
identifier: argument.type
count: 2
diff --git a/tests/app/Http/Middleware/NoRouteFoundTest.php b/tests/app/Http/RequestHandlers/NotFoundTest.php
index 9f5310a05b..e90b4f0437 100644
--- a/tests/app/Http/Middleware/NoRouteFoundTest.php
+++ b/tests/app/Http/RequestHandlers/NotFoundTest.php
@@ -17,27 +17,16 @@
declare(strict_types=1);
-namespace Fisharebest\Webtrees\Http\Middleware;
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
-use Fig\Http\Message\StatusCodeInterface;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
-use Psr\Http\Server\RequestHandlerInterface;
-use function response;
-
-#[CoversClass(NoRouteFound::class)]
-class NoRouteFoundTest extends TestCase
+#[CoversClass(NotFound::class)]
+class NotFoundTest extends TestCase
{
- public function testMiddleware(): void
+ public function testClass(): void
{
- $handler = $this->createMock(RequestHandlerInterface::class);
- $handler->method('handle')->willReturn(response());
-
- $request = self::createRequest();
- $middleware = new NoRouteFound();
- $response = $middleware->process($request, $handler);
-
- self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
+ self::assertTrue(class_exists(NotFound::class));
}
}