update code, add psalm
This commit is contained in:
parent
427d474f7c
commit
224925e56b
8 changed files with 1909 additions and 7 deletions
|
@ -18,7 +18,8 @@
|
|||
"php": ">=8.2",
|
||||
"php-di/php-di": "^7.0.1",
|
||||
"nikic/fast-route": "^1.3",
|
||||
"symfony/http-foundation": "^6.2.5"
|
||||
"symfony/http-foundation": "^6.2.5",
|
||||
"vimeo/psalm": "^5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.9.14",
|
||||
|
@ -38,8 +39,14 @@
|
|||
"Composer\\Config::disableProcessTimeout",
|
||||
"php -S 0.0.0.0:1235 -t public"
|
||||
],
|
||||
"phpstan": "./vendor/bin/phpstan analyze",
|
||||
"baseline": "./vendor/bin/phpstan analyze --generate-baseline",
|
||||
"check": [
|
||||
"./vendor/bin/phpstan analyze",
|
||||
"./vendor/bin/psalm"
|
||||
],
|
||||
"baseline": [
|
||||
"./vendor/bin/phpstan analyze --generate-baseline",
|
||||
"./vendor/bin/psalm --set-baseline=psalm-baseline.xml"
|
||||
],
|
||||
"style": "./vendor/bin/ecs",
|
||||
"fix": [
|
||||
"rector process" ,"ecs --fix", "ecs --fix"
|
||||
|
|
1849
composer.lock
generated
1849
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,6 @@
|
|||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$data of function unserialize expects string, string\\|false given\\.$#"
|
||||
count: 1
|
||||
path: src/Infrastructure/WebApp/Route/CachedRouteCollector.php
|
8
psalm-baseline.xml
Normal file
8
psalm-baseline.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<files psalm-version="5.6.0@e784128902dfe01d489c4123d69918a9f3c1eac5">
|
||||
<file src="src/Infrastructure/Finder.php">
|
||||
<UnresolvableInclude>
|
||||
<code>require_once (string) $file</code>
|
||||
</UnresolvableInclude>
|
||||
</file>
|
||||
</files>
|
18
psalm.xml
Normal file
18
psalm.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
<psalm
|
||||
errorLevel="2"
|
||||
resolveFromConfigFile="true"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://getpsalm.org/schema/config"
|
||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||
findUnusedBaselineEntry="true"
|
||||
errorBaseline="psalm-baseline.xml"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
<directory name="config" />
|
||||
<ignoreFiles>
|
||||
<directory name="vendor" />
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
</psalm>
|
|
@ -7,6 +7,8 @@ use Lubian\AttributeMagic\Infrastructure\WebApp\Request\RequestEvent;
|
|||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use function apcu_add;
|
||||
use function apcu_fetch;
|
||||
use function is_string;
|
||||
use function md5;
|
||||
use function serialize;
|
||||
use function unserialize;
|
||||
|
@ -16,8 +18,17 @@ final class CachedResponse
|
|||
#[AsListener(RequestEvent::class, -99)]
|
||||
public function cachedResponse(RequestEvent $event): void
|
||||
{
|
||||
$response = new Response('lol');
|
||||
$serialized = serialize($response);
|
||||
if ($event->request->getMethod() !== 'GET') {
|
||||
return;
|
||||
}
|
||||
|
||||
$path = md5($event->request->getPathInfo());
|
||||
$serialized = apcu_fetch($path);
|
||||
|
||||
if (! is_string($serialized)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Response|null $response */
|
||||
$response = unserialize($serialized);
|
||||
$event->response = $response;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Lubian\AttributeMagic\Infrastructure\WebApp\Route;
|
||||
|
||||
use Lubian\AttributeMagic\Infrastructure\Event\AsListener;
|
||||
use Lubian\AttributeMagic\Infrastructure\Route\Handler;
|
||||
|
||||
use function file_exists;
|
||||
use function file_get_contents;
|
||||
|
@ -25,7 +26,10 @@ final class CachedRouteCollector
|
|||
return;
|
||||
}
|
||||
|
||||
$event->routes = unserialize(file_get_contents(self::ROUTES_DIR)); //@phpstan-ignore-line
|
||||
/** @var Handler[] $routes */
|
||||
$routes = unserialize(file_get_contents(self::ROUTES_DIR));
|
||||
$event->routes = $routes;
|
||||
|
||||
$event->stopped = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ final readonly class HandlerCaller
|
|||
}
|
||||
|
||||
ob_start();
|
||||
/** @var mixed $response */
|
||||
$response = $this->invoker->call(
|
||||
[$event->handler->handlerClass, $event->handler->handlerMethod],
|
||||
$event->request->attributes->all()
|
||||
|
|
Loading…
Reference in a new issue