-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com> | ||
* | ||
* @author Côme Chilliet <come.chilliet@nextcloud.com> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Settings\AccountWarnings; | ||
|
||
use OCP\Settings\IAccountWarningsProvider; | ||
use OC\AppFramework\Bootstrap\Coordinator; | ||
|
||
class AccountWarningsManager { | ||
public function __construct( | ||
private Coordinator $coordinator, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array<class-string, array{name:string,warnings:array<string,string>}> | ||
Check failure on line 38 in apps/settings/lib/AccountWarnings/AccountWarningsManager.php GitHub Actions / static-code-analysisInvalidReturnType
Check failure Code scanning / Psalm InvalidReturnType Error
The declared return type 'array<class-string, array{name: string, warnings: array<string, string>}>' for OCA\Settings\AccountWarnings\AccountWarningsManager::getAll is incorrect, got 'array<class-string<OCP\Settings\IAccountWarningsProvider>, array{name: string, warnings: array<'error'|'info'|'warning', non-empty-list>}>'
|
||
*/ | ||
public function getAll(): array { | ||
$results = []; | ||
$providerRegistrations = $this->coordinator->getRegistrationContext()->getAccountWarningsProviders(); | ||
Check notice Code scanning / Psalm PossiblyNullReference Note
Cannot call method getAccountWarningsProviders on possibly null value
|
||
foreach ($providerRegistrations as $providerRegistration) { | ||
/** @var IAccountWarningsProvider $provider */ | ||
$provider = \OCP\Server::get($providerRegistration->getService()); | ||
$warnings = $provider->getAccountWarnings(); | ||
$results[$provider::class] = ['name' => $provider->getName(),'warnings' => []]; | ||
foreach ($warnings as $warning) { | ||
$category = $warning->getSeverity(); | ||
if (!isset($results[$provider::class]['warnings'][$category])) { | ||
$results[$provider::class]['warnings'][$category] = []; | ||
} | ||
$results[$provider::class]['warnings'][$category][] = $warning->getText(); | ||
} | ||
} | ||
return $results; | ||
Check failure on line 56 in apps/settings/lib/AccountWarnings/AccountWarningsManager.php GitHub Actions / static-code-analysisInvalidReturnStatement
Check failure Code scanning / Psalm InvalidReturnStatement Error
The inferred type 'array<class-string<OCP\Settings\IAccountWarningsProvider>, array{name: string, warnings: array<'error'|'info'|'warning', non-empty-list>}>' does not match the declared return type 'array<class-string, array{name: string, warnings: array<string, string>}>' for OCA\Settings\AccountWarnings\AccountWarningsManager::getAll
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com> | ||
* | ||
* @author Côme Chilliet <come.chilliet@nextcloud.com> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Settings\Controller; | ||
|
||
use OCA\Settings\AccountWarnings\AccountWarningsManager; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\IRequest; | ||
|
||
class AccountWarningsController extends Controller { | ||
public function __construct( | ||
string $appName, | ||
IRequest $request, | ||
private AccountWarningsManager $manager, | ||
) { | ||
parent::__construct($appName, $request); | ||
} | ||
|
||
public function getAll(): DataResponse { | ||
return new DataResponse($this->manager->getAll()); | ||
} | ||
} |