Skip to content

Commit 253628a

Browse files
committed
fix: Fix psalm issues and add missing methods to ITemplate interface
Signed-off-by: Côme Chilliet <[email protected]>
1 parent f19ddd5 commit 253628a

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

build/psalm-baseline.xml

-5
Original file line numberDiff line numberDiff line change
@@ -2601,11 +2601,6 @@
26012601
<code><![CDATA[getQuota]]></code>
26022602
</UndefinedInterfaceMethod>
26032603
</file>
2604-
<file src="lib/private/legacy/OC_Template.php">
2605-
<InvalidReturnType>
2606-
<code><![CDATA[bool|string]]></code>
2607-
</InvalidReturnType>
2608-
</file>
26092604
<file src="lib/private/legacy/OC_User.php">
26102605
<UndefinedClass>
26112606
<code><![CDATA[\Test\Util\User\Dummy]]></code>

lib/private/Template/Base.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace OC\Template;
99

1010
use OCP\Defaults;
11-
use Throwable;
1211

1312
class Base {
1413
private $template; // The template
@@ -70,18 +69,14 @@ protected function getCoreTemplateDirs(string $theme, string $serverRoot): array
7069

7170
/**
7271
* Assign variables
73-
* @param string $key key
74-
* @param float|array|bool|integer|string|Throwable $value value
75-
* @return bool
7672
*
7773
* This function assigns a variable. It can be accessed via $_[$key] in
7874
* the template.
7975
*
8076
* If the key existed before, it will be overwritten
8177
*/
82-
public function assign($key, $value) {
78+
public function assign(string $key, float|array|bool|int|string|\Throwable|null $value): void {
8379
$this->vars[$key] = $value;
84-
return true;
8580
}
8681

8782
/**

lib/private/Template/TemplateManager.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\EventDispatcher\IEventDispatcher;
1616
use OCP\IRequest;
1717
use OCP\Server;
18+
use OCP\Template\ITemplate;
1819
use Psr\Log\LoggerInterface;
1920

2021
class TemplateManager {
@@ -24,6 +25,9 @@ public function __construct(
2425
) {
2526
}
2627

28+
/**
29+
* @param TemplateResponse::RENDER_AS_* $renderAs
30+
*/
2731
public function getTemplate(string $app, string $name, string $renderAs = TemplateResponse::RENDER_AS_BLANK, bool $registerCall = true): ITemplate {
2832
return new Template($app, $name, $renderAs, $registerCall);
2933
}
@@ -105,7 +109,7 @@ public function printExceptionErrorPage(\Throwable $exception, int $statusCode =
105109
$debug = false;
106110
http_response_code($statusCode);
107111
try {
108-
$debug = Server::get(\OC\SystemConfig::class)->getValue('debug', false);
112+
$debug = (bool)Server::get(\OC\SystemConfig::class)->getValue('debug', false);
109113
$serverLogsDocumentation = Server::get(\OC\SystemConfig::class)->getValue('documentation_url.server_logs', '');
110114
$request = Server::get(IRequest::class);
111115
$content = new Template('', 'exception', 'error', false);
@@ -122,7 +126,7 @@ public function printExceptionErrorPage(\Throwable $exception, int $statusCode =
122126
$content->printPage();
123127
} catch (\Exception $e) {
124128
try {
125-
$logger = \OCP\Server::get(LoggerInterface::class);
129+
$logger = Server::get(LoggerInterface::class);
126130
$logger->error($exception->getMessage(), ['app' => 'core', 'exception' => $exception]);
127131
$logger->error($e->getMessage(), ['app' => 'core', 'exception' => $e]);
128132
} catch (\Throwable $e) {

lib/public/AppFramework/Http/TooManyRequestsResponse.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
namespace OCP\AppFramework\Http;
99

1010
use OCP\AppFramework\Http;
11-
use OCP\Template;
11+
use OCP\Server;
12+
use OCP\Template\ITemplateManager;
1213

1314
/**
1415
* A generic 429 response showing an 404 error page as well to the end-user
@@ -34,7 +35,7 @@ public function __construct(int $status = Http::STATUS_TOO_MANY_REQUESTS, array
3435
* @since 19.0.0
3536
*/
3637
public function render() {
37-
$template = new Template('core', '429', 'blank');
38+
$template = Server::get(ITemplateManager::class)->getTemplate('core', '429', TemplateResponse::RENDER_AS_BLANK);
3839
return $template->fetchPage();
3940
}
4041
}

lib/public/Template/ITemplate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ public function printPage(): void;
3434
* If the key existed before, it will be overwritten
3535
* @since 32.0.0
3636
*/
37-
public function assign(string $key, float|array|bool|int|string|\Throwable $value): void;
37+
public function assign(string $key, float|array|bool|int|string|\Throwable|null $value): void;
3838
}

lib/public/Template/ITemplateManager.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
use OCP\AppFramework\Http\TemplateResponse;
1313

14+
/**
15+
* @since 32.0.0
16+
*/
1417
interface ITemplateManager {
18+
/**
19+
* @param TemplateResponse::RENDER_AS_* $renderAs
20+
* @since 32.0.0
21+
*/
1522
public function getTemplate(string $app, string $name, string $renderAs = TemplateResponse::RENDER_AS_BLANK, bool $registerCall = true): ITemplate;
1623

1724
/**
@@ -29,7 +36,7 @@ public function printGuestPage(string $application, string $name, array $paramet
2936
public function printErrorPage(string $error_msg, string $hint = '', int $statusCode = 500): never;
3037

3138
/**
32-
* print error page using Exception details
39+
* Print error page using Exception details
3340
* @since 32.0.0
3441
*/
3542
public function printExceptionErrorPage(\Throwable $exception, int $statusCode = 503): never;

0 commit comments

Comments
 (0)