Skip to content

Commit

Permalink
work in progress: fixed errors found by psalm
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Jan 21, 2024
1 parent 379954c commit a4c5952
Show file tree
Hide file tree
Showing 30 changed files with 190 additions and 160 deletions.
4 changes: 2 additions & 2 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Db\ExAppScope;
use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppScopesService;
use OCA\AppAPI\Service\ExAppService;
use OCA\AppAPI\Service\ProvidersAI\TextProcessingService;
use OCP\App\IAppManager;
use OCP\Capabilities\ICapability;
Expand All @@ -19,7 +19,7 @@ class Capabilities implements ICapability {
public function __construct(
private IConfig $config,
private IAppManager $appManager,
private AppAPIService $service,
private ExAppService $service,
private ExAppScopesService $exAppScopesService,
private IRequest $request,
) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Command/ExApp/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\DaemonConfigService;

use OCA\AppAPI\Service\ExAppService;
use OCP\IConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -20,6 +21,7 @@ class Deploy extends Command {

public function __construct(
private readonly AppAPIService $service,
private readonly ExAppService $exAppService,
private readonly DaemonConfigService $daemonConfigService,
private readonly DockerActions $dockerActions,
private readonly IConfig $config,
Expand All @@ -41,7 +43,7 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$appId = $input->getArgument('appid');

$exApp = $this->service->getExApp($appId);
$exApp = $this->exAppService->getExApp($appId);
if ($exApp !== null) {
$output->writeln(sprintf('ExApp %s already registered.', $appId));
return 2;
Expand All @@ -51,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($pathToInfoXml !== null) {
$infoXml = simplexml_load_string(file_get_contents($pathToInfoXml));
} else {
$infoXml = $this->service->getLatestExAppInfoFromAppstore($appId);
$infoXml = $this->exAppService->getLatestExAppInfoFromAppstore($appId);
// TODO: Add default release signature check and use of release archive download and info.xml file extraction
}

Expand Down
8 changes: 6 additions & 2 deletions lib/Command/ExApp/Disable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

use OCA\AppAPI\Service\AppAPIService;

use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Disable extends Command {
public function __construct(private AppAPIService $service) {
public function __construct(
private readonly AppAPIService $service,
private readonly ExAppService $exAppService,
) {
parent::__construct();
}

Expand All @@ -24,7 +28,7 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$appId = $input->getArgument('appid');
$exApp = $this->service->getExApp($appId);
$exApp = $this->exAppService->getExApp($appId);

if ($exApp === null) {
$output->writeln(sprintf('ExApp %s not found. Failed to disable.', $appId));
Expand Down
5 changes: 3 additions & 2 deletions lib/Command/ExApp/DispatchInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace OCA\AppAPI\Command\ExApp;

use OCA\AppAPI\DeployActions\DockerActions;
use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,6 +15,7 @@ class DispatchInit extends Command {

public function __construct(
private readonly AppAPIService $service,
private readonly ExAppService $exAppService,
) {
parent::__construct();
}
Expand All @@ -29,7 +30,7 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$appId = $input->getArgument('appid');
$exApp = $this->service->getExApp($appId);
$exApp = $this->exAppService->getExApp($appId);
if ($exApp === null) {
$output->writeln(sprintf('ExApp %s not found. Failed to dispatch init.', $appId));
return 1;
Expand Down
8 changes: 6 additions & 2 deletions lib/Command/ExApp/Enable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

use OCA\AppAPI\Service\AppAPIService;

use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Enable extends Command {

public function __construct(private AppAPIService $service) {
public function __construct(
private readonly AppAPIService $service,
private readonly ExAppService $exAppService,
) {
parent::__construct();
}

Expand All @@ -26,7 +30,7 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$appId = $input->getArgument('appid');
$exApp = $this->service->getExApp($appId);
$exApp = $this->exAppService->getExApp($appId);

if ($exApp === null) {
$output->writeln(sprintf('ExApp %s not found. Failed to enable.', $appId));
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/ExApp/ListExApps.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Symfony\Component\Console\Output\OutputInterface;

class ListExApps extends Command {
public function __construct(private ExAppMapper $mapper) {
public function __construct(private readonly ExAppMapper $mapper) {
parent::__construct();
}

Expand Down
16 changes: 9 additions & 7 deletions lib/Command/ExApp/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\AppAPI\Service\DaemonConfigService;
use OCA\AppAPI\Service\ExAppApiScopeService;
use OCA\AppAPI\Service\ExAppScopesService;
use OCA\AppAPI\Service\ExAppService;
use OCA\AppAPI\Service\ExAppUsersService;

use OCP\DB\Exception;
Expand All @@ -35,6 +36,7 @@ public function __construct(
private readonly DockerActions $dockerActions,
private readonly ManualActions $manualActions,
private readonly IConfig $config,
private readonly ExAppService $exAppService,
) {
parent::__construct();
}
Expand All @@ -55,7 +57,7 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$appId = $input->getArgument('appid');

if ($this->service->getExApp($appId) !== null) {
if ($this->exAppService->getExApp($appId) !== null) {
$output->writeln(sprintf('ExApp %s already registered.', $appId));
return 2;
}
Expand Down Expand Up @@ -112,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$port = (int) $exAppInfo['port'];
$secret = $exAppInfo['secret'];

$exApp = $this->service->registerExApp($appId, [
$exApp = $this->exAppService->registerExApp($appId, [
'version' => $version,
'name' => $name,
'daemon_config_name' => $daemonConfigName,
Expand Down Expand Up @@ -143,10 +145,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$requestedExAppScopeGroups = $this->service->getExAppRequestedScopes($exApp, $infoXml, $exAppInfo);
$requestedExAppScopeGroups = $this->exAppService->getExAppRequestedScopes($exApp, $infoXml, $exAppInfo);
if (isset($requestedExAppScopeGroups['error'])) {
$output->writeln($requestedExAppScopeGroups['error']);
$this->service->unregisterExApp($exApp->getAppid());
$this->exAppService->unregisterExApp($exApp->getAppid());
return 2;
}

Expand Down Expand Up @@ -177,7 +179,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (!$confirmRequiredScopes && count($requestedExAppScopeGroups['required']) > 0) {
$output->writeln(sprintf('ExApp %s required scopes not approved.', $appId));
$this->service->unregisterExApp($exApp->getAppid());
$this->exAppService->unregisterExApp($exApp->getAppid());
return 1;
}

Expand All @@ -190,13 +192,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (!$this->service->dispatchExAppInit($exApp)) {
$output->writeln(sprintf('Dispatching init for ExApp %s fails.', $appId));
$this->service->unregisterExApp($exApp->getAppid());
$this->exAppService->unregisterExApp($exApp->getAppid());
return 1;
}
$waitFinish = (bool) $input->getOption('wait-finish');
if ($waitFinish) {
do {
$exApp = $this->service->getExApp($appId);
$exApp = $this->exAppService->getExApp($appId);
$status = $exApp->getStatus();
if (isset($status['error'])) {
$output->writeln(sprintf('ExApp %s initialization step failed. Error: %s', $appId, $status['error']));
Expand Down
7 changes: 4 additions & 3 deletions lib/Command/ExApp/Scopes/ListScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OCA\AppAPI\Service\ExAppApiScopeService;
use OCA\AppAPI\Service\ExAppScopesService;

use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,9 +18,9 @@
class ListScopes extends Command {

public function __construct(
private AppAPIService $service,
private ExAppScopesService $exAppScopeService,
private ExAppApiScopeService $exAppApiScopeService,
private readonly ExAppService $service,
private readonly ExAppScopesService $exAppScopeService,
private readonly ExAppApiScopeService $exAppApiScopeService,
) {
parent::__construct();
}
Expand Down
12 changes: 7 additions & 5 deletions lib/Command/ExApp/Unregister.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use OCA\AppAPI\Service\AppAPIService;

use OCA\AppAPI\Service\DaemonConfigService;
use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,9 +18,10 @@
class Unregister extends Command {

public function __construct(
private AppAPIService $service,
private DaemonConfigService $daemonConfigService,
private DockerActions $dockerActions,
private readonly AppAPIService $service,
private readonly DaemonConfigService $daemonConfigService,
private readonly DockerActions $dockerActions,
private readonly ExAppService $exAppService,
) {
parent::__construct();
}
Expand Down Expand Up @@ -54,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$force = $input->getOption('force');
$keep_data = $input->getOption('keep-data');

$exApp = $this->service->getExApp($appId);
$exApp = $this->exAppService->getExApp($appId);
if ($exApp === null) {
if ($silent) {
return 0;
Expand Down Expand Up @@ -117,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

if ($this->service->unregisterExApp($appId) === null) {
if ($this->exAppService->unregisterExApp($appId) === null) {
if (!$silent) {
$output->writeln(sprintf('Failed to unregister ExApp %s.', $appId));
}
Expand Down
10 changes: 6 additions & 4 deletions lib/Command/ExApp/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\AppAPI\Service\ExAppApiScopeService;
use OCA\AppAPI\Service\ExAppScopesService;

use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -23,6 +24,7 @@ class Update extends Command {

public function __construct(
private readonly AppAPIService $service,
private readonly ExAppService $exAppService,
private readonly ExAppScopesService $exAppScopeService,
private readonly ExAppApiScopeService $exAppApiScopeService,
private readonly DaemonConfigService $daemonConfigService,
Expand All @@ -49,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($pathToInfoXml !== null) {
$infoXml = simplexml_load_string(file_get_contents($pathToInfoXml));
} else {
$infoXml = $this->service->getLatestExAppInfoFromAppstore($appId);
$infoXml = $this->exAppService->getLatestExAppInfoFromAppstore($appId);
}

if ($infoXml === false) {
Expand All @@ -61,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 2;
}

$exApp = $this->service->getExApp($appId);
$exApp = $this->exAppService->getExApp($appId);
if ($exApp === null) {
$output->writeln(sprintf('ExApp %s not found.', $appId));
return 1;
Expand Down Expand Up @@ -153,7 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$exAppInfo = $this->dockerActions->loadExAppInfo($appId, $daemonConfig);
if (!$this->service->updateExAppInfo($exApp, $exAppInfo)) {
if (!$this->exAppService->updateExAppInfo($exApp, $exAppInfo)) {
$output->writeln(sprintf('Failed to update ExApp %s info', $appId));
return 1;
}
Expand All @@ -162,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$currentExAppScopes = array_map(function (ExAppScope $exAppScope) {
return $exAppScope->getScopeGroup();
}, $this->exAppScopeService->getExAppScopes($exApp));
$newExAppScopes = $this->service->getExAppRequestedScopes($exApp, $infoXml);
$newExAppScopes = $this->exAppService->getExAppRequestedScopes($exApp, $infoXml);
if (isset($newExAppScopes['error'])) {
$output->writeln($newExAppScopes['error']);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Command/ExApp/Users/ListUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OCA\AppAPI\Command\ExApp\Users;

use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppService;
use OCA\AppAPI\Service\ExAppUsersService;

use Symfony\Component\Console\Command\Command;
Expand All @@ -15,8 +15,8 @@
class ListUsers extends Command {

public function __construct(
private AppAPIService $service,
private ExAppUsersService $exAppUserService,
private readonly ExAppService $service,
private readonly ExAppUsersService $exAppUserService,
) {
parent::__construct();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Command/ExAppConfig/DeleteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace OCA\AppAPI\Command\ExAppConfig;

use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppConfigService;

use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,8 +15,8 @@
class DeleteConfig extends Command {

public function __construct(
private AppAPIService $service,
private ExAppConfigService $exAppConfigService) {
private readonly ExAppService $service,
private readonly ExAppConfigService $exAppConfigService) {
parent::__construct();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Command/ExAppConfig/GetConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace OCA\AppAPI\Command\ExAppConfig;

use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppConfigService;

use OCA\AppAPI\Service\ExAppService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -16,8 +16,8 @@
class GetConfig extends Command {

public function __construct(
private AppAPIService $service,
private ExAppConfigService $exAppConfigService) {
private readonly ExAppService $service,
private readonly ExAppConfigService $exAppConfigService) {
parent::__construct();
}

Expand Down
Loading

0 comments on commit a4c5952

Please sign in to comment.