From 253628ad5a0c3b4242d2dbcb05bb802381b0d49f Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 27 Feb 2025 11:05:44 +0100 Subject: fix: Fix psalm issues and add missing methods to ITemplate interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- build/psalm-baseline.xml | 5 ----- lib/private/Template/Base.php | 7 +------ lib/private/Template/TemplateManager.php | 8 ++++++-- lib/public/AppFramework/Http/TooManyRequestsResponse.php | 5 +++-- lib/public/Template/ITemplate.php | 2 +- lib/public/Template/ITemplateManager.php | 9 ++++++++- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index cecea953d00..3e3b373ec34 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -2601,11 +2601,6 @@ - - - - - diff --git a/lib/private/Template/Base.php b/lib/private/Template/Base.php index 35c2bf596ad..6603473af33 100644 --- a/lib/private/Template/Base.php +++ b/lib/private/Template/Base.php @@ -8,7 +8,6 @@ namespace OC\Template; use OCP\Defaults; -use Throwable; class Base { private $template; // The template @@ -70,18 +69,14 @@ class Base { /** * Assign variables - * @param string $key key - * @param float|array|bool|integer|string|Throwable $value value - * @return bool * * This function assigns a variable. It can be accessed via $_[$key] in * the template. * * If the key existed before, it will be overwritten */ - public function assign($key, $value) { + public function assign(string $key, float|array|bool|int|string|\Throwable|null $value): void { $this->vars[$key] = $value; - return true; } /** diff --git a/lib/private/Template/TemplateManager.php b/lib/private/Template/TemplateManager.php index db8d83c1bf9..7745f6d3b8b 100644 --- a/lib/private/Template/TemplateManager.php +++ b/lib/private/Template/TemplateManager.php @@ -15,6 +15,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\IEventDispatcher; use OCP\IRequest; use OCP\Server; +use OCP\Template\ITemplate; use Psr\Log\LoggerInterface; class TemplateManager { @@ -24,6 +25,9 @@ class TemplateManager { ) { } + /** + * @param TemplateResponse::RENDER_AS_* $renderAs + */ public function getTemplate(string $app, string $name, string $renderAs = TemplateResponse::RENDER_AS_BLANK, bool $registerCall = true): ITemplate { return new Template($app, $name, $renderAs, $registerCall); } @@ -105,7 +109,7 @@ class TemplateManager { $debug = false; http_response_code($statusCode); try { - $debug = Server::get(\OC\SystemConfig::class)->getValue('debug', false); + $debug = (bool)Server::get(\OC\SystemConfig::class)->getValue('debug', false); $serverLogsDocumentation = Server::get(\OC\SystemConfig::class)->getValue('documentation_url.server_logs', ''); $request = Server::get(IRequest::class); $content = new Template('', 'exception', 'error', false); @@ -122,7 +126,7 @@ class TemplateManager { $content->printPage(); } catch (\Exception $e) { try { - $logger = \OCP\Server::get(LoggerInterface::class); + $logger = Server::get(LoggerInterface::class); $logger->error($exception->getMessage(), ['app' => 'core', 'exception' => $exception]); $logger->error($e->getMessage(), ['app' => 'core', 'exception' => $e]); } catch (\Throwable $e) { diff --git a/lib/public/AppFramework/Http/TooManyRequestsResponse.php b/lib/public/AppFramework/Http/TooManyRequestsResponse.php index 6b2ef5b1b90..f7084ec768d 100644 --- a/lib/public/AppFramework/Http/TooManyRequestsResponse.php +++ b/lib/public/AppFramework/Http/TooManyRequestsResponse.php @@ -8,7 +8,8 @@ declare(strict_types=1); namespace OCP\AppFramework\Http; use OCP\AppFramework\Http; -use OCP\Template; +use OCP\Server; +use OCP\Template\ITemplateManager; /** * A generic 429 response showing an 404 error page as well to the end-user @@ -34,7 +35,7 @@ class TooManyRequestsResponse extends Response { * @since 19.0.0 */ public function render() { - $template = new Template('core', '429', 'blank'); + $template = Server::get(ITemplateManager::class)->getTemplate('core', '429', TemplateResponse::RENDER_AS_BLANK); return $template->fetchPage(); } } diff --git a/lib/public/Template/ITemplate.php b/lib/public/Template/ITemplate.php index a37f7d12337..455ae3fb856 100644 --- a/lib/public/Template/ITemplate.php +++ b/lib/public/Template/ITemplate.php @@ -34,5 +34,5 @@ interface ITemplate { * If the key existed before, it will be overwritten * @since 32.0.0 */ - public function assign(string $key, float|array|bool|int|string|\Throwable $value): void; + public function assign(string $key, float|array|bool|int|string|\Throwable|null $value): void; } diff --git a/lib/public/Template/ITemplateManager.php b/lib/public/Template/ITemplateManager.php index 267439d4070..94a2ee49399 100644 --- a/lib/public/Template/ITemplateManager.php +++ b/lib/public/Template/ITemplateManager.php @@ -11,7 +11,14 @@ namespace OCP\Template; use OCP\AppFramework\Http\TemplateResponse; +/** + * @since 32.0.0 + */ interface ITemplateManager { + /** + * @param TemplateResponse::RENDER_AS_* $renderAs + * @since 32.0.0 + */ public function getTemplate(string $app, string $name, string $renderAs = TemplateResponse::RENDER_AS_BLANK, bool $registerCall = true): ITemplate; /** @@ -29,7 +36,7 @@ interface ITemplateManager { public function printErrorPage(string $error_msg, string $hint = '', int $statusCode = 500): never; /** - * print error page using Exception details + * Print error page using Exception details * @since 32.0.0 */ public function printExceptionErrorPage(\Throwable $exception, int $statusCode = 503): never; -- cgit v1.2.3