diff --git a/composer.json b/composer.json index 5ba5ecc6..9263034f 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,9 @@ "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", - "psalm": "psalm.phar --threads=1", - "psalm:dev": "psalm.phar --no-cache --threads=$(nproc)", + "psalm": "psalm.phar --no-cache --threads=$(nproc)", + "psalm:dev": "@psalm", "psalm:update-baseline": "psalm.phar --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml", - "psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache", - "psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType", "test:unit": "echo 'Only testing installation of the app'" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 272453f9..fe54dbfc 100644 --- a/composer.lock +++ b/composer.lock @@ -231,12 +231,12 @@ "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "1abf593d27ecd373a9fcbbe87cfdd899ad3fee8b" + "reference": "dc5473e3895d859535de45eab15d2095cb8eafe4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/1abf593d27ecd373a9fcbbe87cfdd899ad3fee8b", - "reference": "1abf593d27ecd373a9fcbbe87cfdd899ad3fee8b", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/dc5473e3895d859535de45eab15d2095cb8eafe4", + "reference": "dc5473e3895d859535de45eab15d2095cb8eafe4", "shasum": "" }, "require": { @@ -272,7 +272,7 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/master" }, - "time": "2025-03-08T00:36:29+00:00" + "time": "2025-03-11T00:46:19+00:00" }, { "name": "nikic/php-parser", diff --git a/lib/Provider/NotificationProvider.php b/lib/Provider/NotificationProvider.php index 06965ae0..4fe8c709 100644 --- a/lib/Provider/NotificationProvider.php +++ b/lib/Provider/NotificationProvider.php @@ -24,7 +24,8 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; -use OCP\Template; +use OCP\Template\ITemplate; +use OCP\Template\ITemplateManager; class NotificationProvider implements IProvider, IProvidesIcons, IProvidesPersonalSettings, IActivatableByAdmin, IDeactivatableByAdmin { public function __construct( @@ -33,6 +34,7 @@ public function __construct( private StateManager $stateManager, private IInitialState $initialStateService, private IURLGenerator $url, + private ITemplateManager $templateManager, ) { } @@ -75,15 +77,15 @@ public function getDarkIcon(): string { * Get the template for rending the 2FA provider view * * @param IUser $user - * @return Template + * @return ITemplate */ - public function getTemplate(IUser $user): Template { + public function getTemplate(IUser $user): ITemplate { $token = $this->tokenManager->generate($user->getUID()); - $tmpl = new Template(Application::APP_ID, 'challenge'); - $tmpl->assign('token', $token->getToken()); + $template = $this->templateManager->getTemplate(Application::APP_ID, 'challenge'); + $template->assign('token', $token->getToken()); - return $tmpl; + return $template; } public function verifyChallenge(IUser $user, string $challenge): bool { @@ -104,7 +106,11 @@ public function isTwoFactorAuthEnabledForUser(IUser $user): bool { } public function getPersonalSettings(IUser $user): IPersonalProviderSettings { - return new Personal($this->initialStateService, $this->stateManager->getState($user)); + return new Personal( + $this->initialStateService, + $this->templateManager, + $this->stateManager->getState($user), + ); } public function enableFor(IUser $user): void { diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 4fa5a7f4..660a9ff2 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -11,17 +11,19 @@ use OCA\TwoFactorNextcloudNotification\AppInfo\Application; use OCP\AppFramework\Services\IInitialState; use OCP\Authentication\TwoFactorAuth\IPersonalProviderSettings; -use OCP\Template; +use OCP\Template\ITemplate; +use OCP\Template\ITemplateManager; class Personal implements IPersonalProviderSettings { public function __construct( private IInitialState $initialStateService, + private ITemplateManager $templateManager, private bool $enabled, ) { } - public function getBody(): Template { + public function getBody(): ITemplate { $this->initialStateService->provideInitialState('state', $this->enabled); - return new Template(Application::APP_ID, 'personal'); + return $this->templateManager->getTemplate(Application::APP_ID, 'personal'); } } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 7568404f..f3a97940 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,14 +1,2 @@ - - - - Template - - - - - Template - Template - - - +