Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Qualifier -> Imports #125

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/AppAPIAuthBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
) {
}

public function check(RequestInterface $request, ResponseInterface $response) {
public function check(RequestInterface $request, ResponseInterface $response): array {
if ($this->request->getHeader('AUTHORIZATION-APP-API')) {
$davAuthenticated = $this->session->get(Auth::DAV_AUTHENTICATED);
$userIdHeader = explode(':', base64_decode($this->request->getHeader('AUTHORIZATION-APP-API')), 2)[0];
Expand Down
3 changes: 2 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\User\Events\UserDeletedEvent;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Throwable;

class Application extends App implements IBootstrap {
public const APP_ID = 'app_api';
Expand Down Expand Up @@ -66,7 +67,7 @@ public function boot(IBootContext $context): void {
$profiler->add(new AppAPIDataCollector());
}
$context->injectFn($this->registerExAppsManagementNavigation(...));
} catch (NotFoundExceptionInterface|ContainerExceptionInterface|\Throwable) {
} catch (NotFoundExceptionInterface|ContainerExceptionInterface|Throwable) {
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Command/ExApp/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 2;
}

$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', '');
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
$daemonConfigName = $input->getArgument('daemon-config-name');
if (!isset($daemonConfigName) && $defaultDaemonConfigName !== '') {
$daemonConfigName = $defaultDaemonConfigName;
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/ExApp/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 2;
}

$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', '');
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
$daemonConfigName = $input->getArgument('daemon-config-name');
if (!isset($daemonConfigName) && $defaultDaemonConfigName !== '') {
$daemonConfigName = $defaultDaemonConfigName;
Expand Down
18 changes: 10 additions & 8 deletions lib/Controller/ExAppsPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OCA\AppAPI\Controller;

use Exception;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\App\AppStore\Version\VersionParser;
use OC\App\DependencyAnalyzer;
Expand Down Expand Up @@ -34,6 +35,7 @@
use OCP\IRequest;
use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;
use SimpleXMLElement;

/**
* ExApps actions controller similar to default one with project-specific changes and additions
Expand Down Expand Up @@ -96,7 +98,7 @@ public function __construct(
*/
#[NoCSRFRequired]
public function viewApps(): TemplateResponse {
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', '');
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');

$appInitialData = [
'appstoreEnabled' => $this->config->getSystemValueBool('appstoreenabled', true),
Expand Down Expand Up @@ -142,7 +144,7 @@ private function getExAppsWithUpdates(): array {
* @param string $requestedCategory
* @return array
*
* @throws \Exception
* @throws Exception
*/
private function getAppsForCategory(string $requestedCategory = ''): array {
$versionParser = new VersionParser();
Expand Down Expand Up @@ -498,13 +500,13 @@ public function enableApps(array $appIds, array $groups = []): JSONResponse {
}

return new JSONResponse(['data' => ['update_required' => $updateRequired]]);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->error('Could not enable ExApps', ['exception' => $e]);
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}

private function deployExApp(string $appId, \SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool {
private function deployExApp(string $appId, SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool {
$deployParams = $this->dockerActions->buildDeployParams($daemonConfig, $infoXml);
[$pullResult, $createResult, $startResult] = $this->dockerActions->deployExApp($daemonConfig, $deployParams);

Expand All @@ -527,7 +529,7 @@ private function deployExApp(string $appId, \SimpleXMLElement $infoXml, DaemonCo
return true;
}

private function registerExApp(string $appId, \SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool {
private function registerExApp(string $appId, SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool {
$exAppInfo = $this->dockerActions->loadExAppInfo($appId, $daemonConfig);

$exApp = $this->service->registerExApp($appId, [
Expand Down Expand Up @@ -603,7 +605,7 @@ public function disableApps(array $appIds): JSONResponse {
}
}
return new JSONResponse([]);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->error('Could not disable ExApp', ['exception' => $e]);
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
}
Expand Down Expand Up @@ -695,11 +697,11 @@ public function enableExApp(string $appId): JSONResponse {

/**
* @param ExApp $exApp
* @param \SimpleXMLElement $infoXml
* @param SimpleXMLElement $infoXml
*
* @return void
*/
private function upgradeExAppScopes(ExApp $exApp, \SimpleXMLElement $infoXml): void {
private function upgradeExAppScopes(ExApp $exApp, SimpleXMLElement $infoXml): void {
$newExAppScopes = $this->service->getExAppRequestedScopes($exApp, $infoXml);

$newExAppScopes = array_merge(
Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/OCSApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;

class OCSApiController extends OCSController {
Expand Down Expand Up @@ -63,7 +64,7 @@ public function log(int $level, string $message): DataResponse {
'app' => $appId,
]);
return new DataResponse();
} catch (\Psr\Log\InvalidArgumentException) {
} catch (InvalidArgumentException) {
$this->logger->error('Invalid log level');
throw new OCSBadRequestException('Invalid log level');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/DeployActions/AIODockerActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function isAIO(): bool {
* @return DaemonConfig|null
*/
public function registerAIODaemonConfig(): ?DaemonConfig {
$defaultDaemonConfig = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', '');
$defaultDaemonConfig = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
if ($defaultDaemonConfig !== '') {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName(self::AIO_DAEMON_CONFIG_NAME);
if ($daemonConfig !== null) {
Expand Down
3 changes: 2 additions & 1 deletion lib/DeployActions/DockerActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
use SimpleXMLElement;

class DockerActions implements IDeployActions {
public const DOCKER_API_VERSION = 'v1.41';
Expand Down Expand Up @@ -327,7 +328,7 @@ public function removePrevExAppContainer(string $dockerUrl, string $containerId)
return [$stopResult, $removeResult];
}

public function buildDeployParams(DaemonConfig $daemonConfig, \SimpleXMLElement $infoXml, array $params = []): array {
public function buildDeployParams(DaemonConfig $daemonConfig, SimpleXMLElement $infoXml, array $params = []): array {
$appId = (string) $infoXml->id;
$deployConfig = $daemonConfig->getDeployConfig();

Expand Down
3 changes: 2 additions & 1 deletion lib/Exceptions/AppAPIAuthNotValidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace OCA\AppAPI\Exceptions;

use Exception;
use OCP\AppFramework\Http;

/**
* @package OCA\AppAPI\Exceptions
*/
class AppAPIAuthNotValidException extends \Exception {
class AppAPIAuthNotValidException extends Exception {
public function __construct($message = 'AppAPIAuth failed', $code = Http::STATUS_UNAUTHORIZED) {
parent::__construct($message, $code);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Fetcher/AppAPIFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OCA\AppAPI\Fetcher;

use Exception;
use GuzzleHttp\Exception\ConnectException;
use OC\Files\AppData\Factory;
use OCA\AppAPI\AppInfo\Application;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function __construct(
* @param string $ETag
* @param string $content
*
* @throws \Exception
* @throws Exception
* @return array
*/
protected function fetch(string $ETag, string $content): array {
Expand Down Expand Up @@ -160,7 +161,7 @@ public function get(bool $allowUnstable = false): array {
} catch (ConnectException $e) {
$this->logger->warning('Could not connect to appstore: ' . $e->getMessage(), ['app' => 'appstoreFetcher']);
return [];
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->warning($e->getMessage(), [
'exception' => $e,
'app' => 'appstoreFetcher',
Expand Down
16 changes: 9 additions & 7 deletions lib/Fetcher/ExAppArchiveFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace OCA\AppAPI\Fetcher;

use Exception;
use OC\Archive\TAR;
use OCP\Http\Client\IClientService;
use OCP\ITempManager;
use phpseclib\File\X509;
use SimpleXMLElement;

/**
* ExApps release archive fetcher with the same logic as for default (signature check).
Expand All @@ -26,9 +28,9 @@ public function __construct(
*
* @param array $exAppAppstoreData
*
* @return \SimpleXMLElement|null
* @return SimpleXMLElement|null
*/
public function downloadInfoXml(array $exAppAppstoreData): ?\SimpleXMLElement {
public function downloadInfoXml(array $exAppAppstoreData): ?SimpleXMLElement {
// 1. Signature check
if (!$this->checkExAppSignature($exAppAppstoreData)) {
return null;
Expand Down Expand Up @@ -99,12 +101,12 @@ private function checkExAppSignature(array $exAppAppstoreData): bool {
}
$crl->loadCRL(file_get_contents(\OC::$SERVERROOT . '/resources/codesigning/root.crl'));
if ($crl->validateSignature() !== true) {
throw new \Exception('Could not validate CRL signature');
throw new Exception('Could not validate CRL signature');
}
$csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString();
$revoked = $crl->getRevoked($csn);
if ($revoked !== false) {
throw new \Exception(
throw new Exception(
sprintf(
'Certificate "%s" has been revoked',
$csn
Expand All @@ -114,7 +116,7 @@ private function checkExAppSignature(array $exAppAppstoreData): bool {

// Verify if the certificate has been issued by the Nextcloud Code Authority CA
if ($certificate->validateSignature() !== true) {
throw new \Exception(
throw new Exception(
sprintf(
'App with id %s has a certificate not issued by a trusted Code Signing Authority',
$appId
Expand All @@ -125,15 +127,15 @@ private function checkExAppSignature(array $exAppAppstoreData): bool {
// Verify if the certificate is issued for the requested app id
$certInfo = openssl_x509_parse($exAppAppstoreData['certificate']);
if (!isset($certInfo['subject']['CN'])) {
throw new \Exception(
throw new Exception(
sprintf(
'App with id %s has a cert with no CN',
$appId
)
);
}
if ($certInfo['subject']['CN'] !== $appId) {
throw new \Exception(
throw new Exception(
sprintf(
'App with id %s has a cert issued to %s',
$appId,
Expand Down
6 changes: 4 additions & 2 deletions lib/Fetcher/ExAppFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace OCA\AppAPI\Fetcher;

use Exception;
use InvalidArgumentException;
use OC\App\AppStore\Version\VersionParser;
use OC\App\CompareVersion;
use OC\Files\AppData\Factory;
Expand Down Expand Up @@ -49,7 +51,7 @@ public function __construct(
* @param string $content
* @param bool $allowUnstable [$allowUnstable] Allow unstable releases
*
* @throws \Exception
* @throws Exception
* @return array
*/
protected function fetch(string $ETag, string $content, bool $allowUnstable = false): array {
Expand Down Expand Up @@ -102,7 +104,7 @@ protected function fetch(string $ETag, string $content, bool $allowUnstable = fa
if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) {
$releases[] = $release;
}
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
$this->logger->warning($e->getMessage(), [
'exception' => $e,
]);
Expand Down
3 changes: 2 additions & 1 deletion lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OCA\AppAPI\Listener;

use Exception;
use OCA\AppAPI\Service\ExAppUsersService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -30,7 +31,7 @@ public function handle(Event $event): void {
// Delete ExApp user record on user deletion
try {
$this->exAppUsersService->removeDeletedUser($event->getUser()->getUID());
} catch (\Exception $e) {
} catch (Exception $e) {
// Ignore exceptions
$this->logger->info('Could not delete ExApp user ' . $event->getUser()->getUID(), [
'exception' => $e,
Expand Down
7 changes: 4 additions & 3 deletions lib/Middleware/AppAPIAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OCA\AppAPI\Middleware;

use Exception;
use OCA\AppAPI\Attribute\AppAPIAuth;
use OCA\AppAPI\Exceptions\AppAPIAuthNotValidException;
use OCA\AppAPI\Service\AppAPIService;
Expand Down Expand Up @@ -46,11 +47,11 @@ public function beforeController($controller, $methodName) {
* @param Controller $controller the controller that is being called
* @param string $methodName the name of the method that will be called on
* the controller
* @param \Exception $exception the thrown exception
* @param Exception $exception the thrown exception
* @return Response a Response object or null in case that the exception could not be handled
* @throws \Exception the passed in exception if it can't handle it
* @throws Exception the passed in exception if it can't handle it
*/
public function afterException($controller, $methodName, \Exception $exception): Response {
public function afterException($controller, $methodName, Exception $exception): Response {
if ($exception instanceof AppAPIAuth) {
$response = new JSONResponse([
'message' => $exception->getMessage(),
Expand Down
5 changes: 3 additions & 2 deletions lib/Notifications/ExAppAdminNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OCA\AppAPI\Notifications;

use InvalidArgumentException;
use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Service\AppAPIService;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -33,10 +34,10 @@ public function prepare(INotification $notification, string $languageCode): INot
// TODO: Think about another possible admin ExApp notifications, make them unified
// TODO: Think about ExApp rich objects
if ($exApp === null || $notification->getSubject() !== 'ex_app_version_update') {
throw new \InvalidArgumentException();
throw new InvalidArgumentException();
}
if ($exApp->getEnabled()) {
throw new \InvalidArgumentException('ExApp is probably already re-enabled');
throw new InvalidArgumentException('ExApp is probably already re-enabled');
}

$parameters = $notification->getSubjectParameters();
Expand Down
7 changes: 4 additions & 3 deletions lib/Notifications/ExAppNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OCA\AppAPI\Notifications;

use InvalidArgumentException;
use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Service\AppAPIService;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -31,12 +32,12 @@ public function getName(): string {
public function prepare(INotification $notification, string $languageCode): INotification {
$exApp = $this->service->getExApp($notification->getApp());
if ($exApp === null) {
throw new \InvalidArgumentException();
throw new InvalidArgumentException();
}
if ($notification->getSubject() === 'ex_app_version_update' && $exApp->getEnabled()) {
throw new \InvalidArgumentException('ExApp is probably already re-enabled');
throw new InvalidArgumentException('ExApp is probably already re-enabled');
} elseif (!$exApp->getEnabled()) { // Only enabled ExApps can render notifications
throw new \InvalidArgumentException('ExApp is disabled');
throw new InvalidArgumentException('ExApp is disabled');
}

$parameters = $notification->getSubjectParameters();
Expand Down
Loading