fix: Fix psalm issues and add missing methods to ITemplate interface

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2025-02-27 11:05:44 +01:00 committed by Côme Chilliet
parent f19ddd5525
commit 253628ad5a
6 changed files with 19 additions and 17 deletions

View file

@ -2601,11 +2601,6 @@
<code><![CDATA[getQuota]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/private/legacy/OC_Template.php">
<InvalidReturnType>
<code><![CDATA[bool|string]]></code>
</InvalidReturnType>
</file>
<file src="lib/private/legacy/OC_User.php">
<UndefinedClass>
<code><![CDATA[\Test\Util\User\Dummy]]></code>

View file

@ -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;
}
/**

View file

@ -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) {

View file

@ -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();
}
}

View file

@ -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;
}

View file

@ -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;