diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-24 17:16:05 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-24 17:16:05 +0300 |
| commit | 6f660eedb640eaa31e75cfd2543692d7f494ddd6 (patch) | |
| tree | bf5a6d43ae77daf7a63d5c1770ec5dac6af5bc06 | |
| parent | 8ca1fb36999b0e2eceed1388d1a1f7cc115a2f3c (diff) | |
| download | the-epube-6f660eedb640eaa31e75cfd2543692d7f494ddd6.tar.gz the-epube-6f660eedb640eaa31e75cfd2543692d7f494ddd6.tar.xz | |
fix phpstan issues
| -rw-r--r-- | AGENTS.md | 2 | ||||
| -rw-r--r-- | backend.php | 7 | ||||
| -rw-r--r-- | classes/AuthMiddleware.php | 1 | ||||
| -rw-r--r-- | classes/Handler/DefineHandler.php | 2 | ||||
| -rw-r--r-- | classes/Request.php | 16 | ||||
| -rw-r--r-- | classes/Response.php | 1 | ||||
| -rw-r--r-- | classes/Router.php | 3 | ||||
| -rw-r--r-- | classes/Sanitizer.php | 5 | ||||
| -rw-r--r-- | index.php | 7 | ||||
| -rw-r--r-- | login.php | 4 | ||||
| -rw-r--r-- | phpstan.neon | 8 | ||||
| -rw-r--r-- | update.php | 5 |
12 files changed, 29 insertions, 32 deletions
diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..9089629 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,2 @@ +- after making any changes to the project, you should invoke phpstan (`npm run phpstan`) and eslint (`npm run eslint`) to verify correctness; +- frontend should be built with `npm run build`; diff --git a/backend.php b/backend.php index 4589378..de308a7 100644 --- a/backend.php +++ b/backend.php @@ -1,7 +1,4 @@ <?php - set_include_path(__DIR__ ."/include" . PATH_SEPARATOR . - get_include_path()); - if (!isset($_COOKIE['epube_sid'])) { header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized"); echo "Unauthorized"; @@ -10,8 +7,8 @@ header("Content-type: text/json"); - require_once "common.php"; - require_once "sessions.php"; + require_once __DIR__ . "/include/common.php"; + require_once __DIR__ . "/include/sessions.php"; Config::sanity_check(); diff --git a/classes/AuthMiddleware.php b/classes/AuthMiddleware.php index 4f1f11d..68b2585 100644 --- a/classes/AuthMiddleware.php +++ b/classes/AuthMiddleware.php @@ -2,6 +2,7 @@ class AuthMiddleware implements MiddlewareInterface { + /** @var array<string> */ private array $csrfIgnore = [ "cover", "download", "getpagination", "getlastread" ]; diff --git a/classes/Handler/DefineHandler.php b/classes/Handler/DefineHandler.php index 2d683b8..30ae72e 100644 --- a/classes/Handler/DefineHandler.php +++ b/classes/Handler/DefineHandler.php @@ -38,7 +38,7 @@ class DefineHandler implements RequestHandlerInterface for ($i = 0; $i < 3; $i++) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, sprintf("dict://%s/define:%s", Config::get(Config::DICT_SERVER), $word)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $dictReply = curl_exec($ch); if ($dictReply) { diff --git a/classes/Request.php b/classes/Request.php index 57fe862..b3d2b62 100644 --- a/classes/Request.php +++ b/classes/Request.php @@ -2,34 +2,42 @@ class Request { + /** @var array<string, mixed> */ private array $serverParams; + /** @var array<string, mixed> */ private array $queryParams; + /** @var array<string, mixed> */ private array $bodyParams; + /** @var array<string, mixed> */ private array $cookies; public function __construct() { - $this->serverParams = $_SERVER ?? []; - $this->queryParams = $_GET ?? []; - $this->bodyParams = $_POST ?? []; - $this->cookies = $_COOKIE ?? []; + $this->serverParams = $_SERVER; + $this->queryParams = $_GET; + $this->bodyParams = $_POST; + $this->cookies = $_COOKIE; } + /** @return array<string, mixed> */ public function getServerParams(): array { return $this->serverParams; } + /** @return array<string, mixed> */ public function getQueryParams(): array { return $this->queryParams; } + /** @return array<string, mixed> */ public function getParsedBody(): array { return array_merge($this->queryParams, $this->bodyParams); } + /** @return array<string, mixed> */ public function getCookieParams(): array { return $this->cookies; diff --git a/classes/Response.php b/classes/Response.php index aa3302a..dcbbc5b 100644 --- a/classes/Response.php +++ b/classes/Response.php @@ -3,6 +3,7 @@ class Response { private int $status = 200; + /** @var array<string, string> */ private array $headers = []; private string $body = ''; diff --git a/classes/Router.php b/classes/Router.php index f55173f..b4f4837 100644 --- a/classes/Router.php +++ b/classes/Router.php @@ -2,7 +2,7 @@ class Router { - /** @var array<string, \Handler\RequestHandlerInterface> */ + /** @var array<string, RequestHandlerInterface> */ private array $routes = []; /** @var MiddlewareInterface[] */ @@ -30,7 +30,6 @@ class Router exit; } - /** @var callable $pipe */ $pipe = $handler->handle(...); // wrap middleware in reverse order (last added = outermost) diff --git a/classes/Sanitizer.php b/classes/Sanitizer.php index d751245..9d2f5a3 100644 --- a/classes/Sanitizer.php +++ b/classes/Sanitizer.php @@ -19,7 +19,6 @@ class Sanitizer { $rel_parts['host'] = $parts['host']; $rel_parts['scheme'] = $parts['scheme']; - /** @phpstan-ignore-next-line */ if (isset($rel_parts['path'])) { if (strpos($rel_parts['path'], '/') !== 0) $rel_parts['path'] = '/' . $rel_parts['path']; @@ -47,6 +46,7 @@ class Sanitizer { $entries = $xpath->query('(//a[@href]|//img[@src]|//source[@srcset|@src])'); foreach ($entries as $entry) { + /** @var DOMElement $entry */ if ($entry->hasAttribute('href')) { $entry->setAttribute('href', @@ -109,10 +109,13 @@ class Sanitizer { $entries = $xpath->query('//*'); foreach ($entries as $entry) { + /** @var DOMElement $entry */ if (!in_array($entry->nodeName, $allowed_elements)) { $entry->parentNode->removeChild($entry); + continue; } + if ($entry->hasAttributes()) { $attrs_to_remove = array(); diff --git a/index.php b/index.php index 99106f3..26261a6 100644 --- a/index.php +++ b/index.php @@ -1,14 +1,11 @@ <?php - set_include_path(__DIR__ ."/include" . PATH_SEPARATOR . - get_include_path()); - if (!isset($_COOKIE['epube_sid'])) { header("Location: login.php"); exit; } - require_once "common.php"; - require_once "sessions.php"; + require_once __DIR__ . "/include/common.php"; + require_once __DIR__ . "/include/sessions.php"; Config::sanity_check(); diff --git a/login.php b/login.php index 61531cd..41147d9 100644 --- a/login.php +++ b/login.php @@ -1,8 +1,8 @@ <?php set_include_path(__DIR__ . "/include" . PATH_SEPARATOR . get_include_path()); - require_once "common.php"; - require_once "sessions.php"; + require_once __DIR__ . "/include/common.php"; + require_once __DIR__ . "/include/sessions.php"; use Jumbojett\OpenIDConnectClient; diff --git a/phpstan.neon b/phpstan.neon index d83c594..e6efb02 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,14 +1,6 @@ parameters: level: 6 ignoreErrors: - #- '#Comparison operation ">" between int<1, max> and 0 is always true.#' - #- '#Access to an undefined property DOMNode::\$tagName.#' - #- '#Call to an undefined method DOMNode::(get|remove|set)Attribute\(\).#' - #- '#PHPDoc tag @param has invalid value#' - - message: '##' - paths: - #- lib/* - - vendor/* excludePaths: - node_modules/* - vendor/**/* diff --git a/update.php b/update.php index fda9ecf..c0b4d30 100644 --- a/update.php +++ b/update.php @@ -5,12 +5,9 @@ exit; } - set_include_path(__DIR__ ."/include" . PATH_SEPARATOR . - get_include_path()); - chdir(__DIR__); - require_once "common.php"; + require_once __DIR__ . "/include/common.php"; Config::sanity_check(); |
