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

refactor: rector core #22

Merged
merged 16 commits into from
Nov 24, 2022
  •  
  •  
  •  
23 changes: 16 additions & 7 deletions EMS/core-bundle/src/Command/ActivateContentTypeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ class ActivateContentTypeCommand extends Command

/** @var ContentTypeService */
protected $contentTypeService;
/** @var SymfonyStyle */
private $io;
/** @var LoggerInterface */
private $logger;
/** @var bool */
private $deactivate;
private ?SymfonyStyle $io = null;
private LoggerInterface $logger;
private ?bool $deactivate = null;

public const ARGUMENT_CONTENTTYPES = 'contenttypes';
public const OPTION_ALL = 'all';
Expand Down Expand Up @@ -73,6 +70,9 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
/** @var string[] $types */
$types = $input->getArgument(self::ARGUMENT_CONTENTTYPES);
$force = $input->getOption(self::FORCE);
Expand Down Expand Up @@ -108,6 +108,9 @@ protected function initialize(InputInterface $input, OutputInterface $output): v

protected function interact(InputInterface $input, OutputInterface $output): void
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
$this->deactivate = true === $input->getOption(self::DEACTIVATE);
$this->io->title($this->deactivate ? 'Deactivate contenttypes' : 'Activate contenttypes');
$this->io->section('Checking input');
Expand All @@ -117,7 +120,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
throw new \RuntimeException('Unexpected content type names');
}

if (!$input->getOption(self::OPTION_ALL) && 0 == \count($types)) {
if (!$input->getOption(self::OPTION_ALL) && 0 == (\is_countable($types) ? \count($types) : 0)) {
$this->chooseTypes($input, $output);
}

Expand All @@ -128,6 +131,9 @@ protected function interact(InputInterface $input, OutputInterface $output): voi

private function chooseTypes(InputInterface $input, OutputInterface $output): void
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
Expand All @@ -148,6 +154,9 @@ private function chooseTypes(InputInterface $input, OutputInterface $output): vo

private function optionAll(InputInterface $input): void
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
$types = $this->contentTypeService->getAllNames();
$input->setArgument(self::ARGUMENT_CONTENTTYPES, $types);
$this->io->note(['Continuing with contenttypes:', \implode(', ', $types)]);
Expand Down
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/AlignManagedAliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class AlignManagedAliases extends Command
{
protected static $defaultName = 'ems:managedalias:align';
/** @var LoggerInterface */
protected $logger;
/** @var AliasService */
Expand All @@ -25,9 +26,7 @@ public function __construct(LoggerInterface $logger, AliasService $aliasService)

protected function configure(): void
{
$this
->setName('ems:managedalias:align')
->setDescription('Align a managed alias to another')
$this->setDescription('Align a managed alias to another')
->addArgument(
'source',
InputArgument::REQUIRED,
Expand Down
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/Check/AliasesCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

final class AliasesCheckCommand extends Command
{
protected static $defaultName = self::COMMAND;
public const COMMAND = 'ems:check:aliases';
private const OPTION_REPAIR = 'repair';
private EnvironmentService $environmentService;
Expand All @@ -35,9 +36,7 @@ public function __construct(EnvironmentService $environmentService, AliasService

protected function configure(): void
{
$this
->setName(self::COMMAND)
->setDescription('Checks that all managed environments have their corresponding alias and index present in the cluster.')
$this->setDescription('Checks that all managed environments have their corresponding alias and index present in the cluster.')
->addOption(self::OPTION_REPAIR, null, InputOption::VALUE_NONE, 'If an environment does not have its alias present and if they are no pending job a rebuild job is queued.');
}

Expand Down
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/CleanAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class CleanAssetCommand extends EmsCommand
{
protected static $defaultName = 'ems:asset:clean';
/** @var Registry */
protected $doctrine;
/** @var FileService */
Expand All @@ -33,9 +34,7 @@ public function __construct(LoggerInterface $logger, Registry $doctrine, FileSer

protected function configure(): void
{
$this
->setName('ems:asset:clean')
->setDescription('Unreference useless assets (no files are deleted from storages)');
$this->setDescription('Unreference useless assets (no files are deleted from storages)');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

class CleanDeletedContentTypeCommand extends Command
{
protected static $defaultName = 'ems:contenttype:clean';
/** @var Mapping */
protected $mapping;
/** @var Registry */
Expand All @@ -43,9 +44,7 @@ public function __construct(Registry $doctrine, LoggerInterface $logger, Mapping

protected function configure(): void
{
$this
->setName('ems:contenttype:clean')
->setDescription('Clean all deleted content types');
$this->setDescription('Clean all deleted content types');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
17 changes: 11 additions & 6 deletions EMS/core-bundle/src/Command/CreateEnvironmentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ class CreateEnvironmentCommand extends Command
{
protected static $defaultName = 'ems:environment:create';

/** @var LoggerInterface */
private $logger;
private LoggerInterface $logger;

/** @var EnvironmentService */
protected $environmentService;

/** @var DataService */
protected $dataService;

/** @var SymfonyStyle */
private $io;
private ?SymfonyStyle $io = null;

public const ARGUMENT_ENV_NAME = 'name';
public const OPTION_STRICT = 'strict';
Expand Down Expand Up @@ -72,6 +70,9 @@ protected function initialize(InputInterface $input, OutputInterface $output): v

protected function interact(InputInterface $input, OutputInterface $output): void
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
$this->logger->info('Interact with the CreateEnvironment command');

$this->io->section('Check environment name argument');
Expand All @@ -80,6 +81,9 @@ protected function interact(InputInterface $input, OutputInterface $output): voi

protected function execute(InputInterface $input, OutputInterface $output): int
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
$this->logger->info('Execute the CreateEnvironment command');

$this->io->section('Execute');
Expand Down Expand Up @@ -138,13 +142,14 @@ private function checkEnvironmentNameArgument(InputInterface $input): void
$message = \sprintf('The environment "%s" already exist', $environmentName);
$this->setEnvironmentNameArgument($input, $message);
$this->checkEnvironmentNameArgument($input);

return;
}
}

private function setEnvironmentNameArgument(InputInterface $input, string $message): string
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
if ($input->getOption(self::OPTION_STRICT)) {
$this->logger->error($message);
throw new \Exception($message);
Expand Down
36 changes: 20 additions & 16 deletions EMS/core-bundle/src/Command/DocumentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,12 @@ class DocumentCommand extends Command

/** @var string */
protected static $defaultName = self::COMMAND;
/** @var DocumentService */
private $documentService;
/** @var ContentTypeService */
private $contentTypeService;
/** @var DataService */
private $dataService;
/** @var SymfonyStyle */
private $io;
/** @var ContentType */
private $contentType;
/** @var string */
private $archiveFilename;
private DocumentService $documentService;
private ContentTypeService $contentTypeService;
private DataService $dataService;
private ?SymfonyStyle $io = null;
private ?ContentType $contentType = null;
private ?string $archiveFilename = null;
private string $defaultBulkSize;

public function __construct(ContentTypeService $contentTypeService, DocumentService $documentService, DataService $dataService, string $defaultBulkSize)
Expand Down Expand Up @@ -115,6 +109,9 @@ protected function initialize(InputInterface $input, OutputInterface $output): v

protected function interact(InputInterface $input, OutputInterface $output): void
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
$contentTypeName = $input->getArgument(self::ARGUMENT_CONTENT_TYPE);
$archiveFilename = $input->getArgument(self::ARGUMENT_ARCHIVE);
if (!\is_string($contentTypeName)) {
Expand Down Expand Up @@ -145,6 +142,15 @@ protected function interact(InputInterface $input, OutputInterface $output): voi

protected function execute(InputInterface $input, OutputInterface $output): int
{
if (null === $this->io) {
throw new \RuntimeException('Unexpected null SymfonyStyle');
}
if (null === $this->contentType) {
throw new \RuntimeException('Unexpected null contentType');
}
if (null === $this->archiveFilename) {
throw new \RuntimeException('Unexpected null archiveFilename');
}
$bulkSize = \intval($input->getOption(self::OPTION_BULK_SIZE));
if ($bulkSize <= 0) {
throw new \RuntimeException('Invalid bulk size');
Expand Down Expand Up @@ -191,7 +197,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$progress->advance();
continue;
}
$rawData = \json_decode($content, true);
$rawData = \json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$ouuid = \basename($file->getFilename(), '.json');
if ($replaceBusinessKey) {
$dataLink = $this->dataService->getDataLink($this->contentType->getName(), $ouuid);
Expand All @@ -210,9 +216,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
$this->documentService->importDocument($importerContext, $document->getOuuid(), $document->getSource());
} catch (NotLockedException $e) {
$this->io->error($e);
} catch (CantBeFinalizedException $e) {
} catch (NotLockedException|CantBeFinalizedException $e) {
$this->io->error($e);
}

Expand Down
8 changes: 3 additions & 5 deletions EMS/core-bundle/src/Command/EnvironmentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

class EnvironmentCommand extends Command
{
/** @var EnvironmentService */
private $environmentService;
protected static $defaultName = 'ems:environment:list';
private EnvironmentService $environmentService;

public function __construct(EnvironmentService $environmentService)
{
Expand All @@ -22,9 +22,7 @@ public function __construct(EnvironmentService $environmentService)

protected function configure(): void
{
$this
->setName('ems:environment:list')
->setDescription('List the environments defined')
$this->setDescription('List the environments defined')
->addOption(
'all',
null,
Expand Down
8 changes: 3 additions & 5 deletions EMS/core-bundle/src/Command/ExportDocumentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

class ExportDocumentsCommand extends EmsCommand
{
protected static $defaultName = 'ems:contenttype:export';
public const OUTPUT_FILE_ARGUMENT = 'outputFile';
/** @var LoggerInterface */
protected $logger;
Expand All @@ -38,8 +39,7 @@ class ExportDocumentsCommand extends EmsCommand
protected $runtime;
/** @var string */
protected $instanceId;
/** @var ElasticaService */
private $elasticaService;
private ElasticaService $elasticaService;

public function __construct(LoggerInterface $logger, TemplateService $templateService, DataService $dataService, ContentTypeService $contentTypeService, EnvironmentService $environmentService, AssetRuntime $runtime, ElasticaService $elasticaService, string $instanceId)
{
Expand All @@ -56,9 +56,7 @@ public function __construct(LoggerInterface $logger, TemplateService $templateSe

protected function configure(): void
{
$this
->setName('ems:contenttype:export')
->setDescription('Export a search result of a content type to a specific format')
$this->setDescription('Export a search result of a content type to a specific format')
->addArgument(
'contentTypeName',
InputArgument::REQUIRED,
Expand Down
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/ExtractAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class ExtractAssetCommand extends EmsCommand
{
protected static $defaultName = 'ems:asset:extract';
/** @var AssetExtractorService */
protected $extractorService;
/** @var StorageManager */
Expand All @@ -31,9 +32,7 @@ public function __construct(LoggerInterface $logger, AssetExtractorService $extr

protected function configure(): void
{
$this
->setName('ems:asset:extract')
->setDescription('Will extract data from all files found and load it in cache of the asset extractor service')
$this->setDescription('Will extract data from all files found and load it in cache of the asset extractor service')
->addArgument(
'path',
InputArgument::REQUIRED,
Expand Down
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/IndexFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class IndexFileCommand extends EmsCommand
{
protected static $defaultName = 'ems:revisions:index-file-fields';
/** @var string */
private const SYSTEM_USERNAME = 'SYSTEM_FILE_INDEXER';
/** @var Registry */
Expand Down Expand Up @@ -51,9 +52,7 @@ public function __construct(LoggerInterface $logger, Registry $doctrine, Content

protected function configure(): void
{
$this
->setName('ems:revisions:index-file-fields')
->setDescription('Migrate an ingested file field from an elasticsearch index')
$this->setDescription('Migrate an ingested file field from an elasticsearch index')
->addArgument(
'contentType',
InputArgument::REQUIRED,
Expand Down
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/JobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class JobCommand extends AbstractCommand
{
protected static $defaultName = 'ems:job:run';
private const USER_JOB_COMMAND = 'User-Job-Command';
private JobService $jobService;
private string $dateFormat;
Expand All @@ -31,9 +32,7 @@ public function __construct(JobService $jobService, ScheduleManager $scheduleMan

protected function configure(): void
{
$this
->setName('ems:job:run')
->setDescription('Execute the next pending job if exist. If not execute the oldest due scheduled job if exist.')
$this->setDescription('Execute the next pending job if exist. If not execute the oldest due scheduled job if exist.')
->addOption(
'dump',
null,
Expand Down
4 changes: 2 additions & 2 deletions EMS/core-bundle/src/Command/LockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

$query = \json_decode($this->query, true);
if (\count($query) > 0) {
$query = \json_decode($this->query, true, 512, JSON_THROW_ON_ERROR);
if ((\is_countable($query) ? \count($query) : 0) > 0) {
$search = $this->elasticaService->convertElasticsearchSearch([
'index' => (null !== $this->contentType->getEnvironment()) ? $this->contentType->getEnvironment()->getAlias() : '',
'_source' => false,
Expand Down
Loading