diff --git a/composer.json b/composer.json index 80c25442..1bb4ac25 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "mikehaertl/phpwkhtmltopdf": "^2.2", "monolog/monolog": "^1.21", "roave/security-advisories": "dev-master", - "symfony/console": "^4.0", + "symfony/console": "^4.0 <4.1.5", "symfony/filesystem": "^4.0", "symfony/process": "^4.0", "theorchard/monolog-cascade": "^0.4", diff --git a/module/CLI/src/Command/Api/DisableKeyCommand.php b/module/CLI/src/Command/Api/DisableKeyCommand.php index 386f838d..7d4c14c8 100644 --- a/module/CLI/src/Command/Api/DisableKeyCommand.php +++ b/module/CLI/src/Command/Api/DisableKeyCommand.php @@ -10,10 +10,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class DisableKeyCommand extends Command { - const NAME = 'api-key:disable'; + public const NAME = 'api-key:disable'; /** * @var ApiKeyServiceInterface @@ -31,14 +32,14 @@ class DisableKeyCommand extends Command parent::__construct(); } - public function configure() + protected function configure(): void { $this->setName(self::NAME) ->setDescription($this->translator->translate('Disables an API key.')) ->addArgument('apiKey', InputArgument::REQUIRED, $this->translator->translate('The API key to disable')); } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $apiKey = $input->getArgument('apiKey'); $io = new SymfonyStyle($input, $output); diff --git a/module/CLI/src/Command/Api/GenerateKeyCommand.php b/module/CLI/src/Command/Api/GenerateKeyCommand.php index 0b7fc476..0b6baafa 100644 --- a/module/CLI/src/Command/Api/GenerateKeyCommand.php +++ b/module/CLI/src/Command/Api/GenerateKeyCommand.php @@ -11,10 +11,11 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class GenerateKeyCommand extends Command { - const NAME = 'api-key:generate'; + public const NAME = 'api-key:generate'; /** * @var ApiKeyServiceInterface @@ -32,7 +33,7 @@ class GenerateKeyCommand extends Command parent::__construct(); } - public function configure() + protected function configure(): void { $this->setName(self::NAME) ->setDescription($this->translator->translate('Generates a new valid API key.')) @@ -44,7 +45,7 @@ class GenerateKeyCommand extends Command ); } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $expirationDate = $input->getOption('expirationDate'); $apiKey = $this->apiKeyService->create(isset($expirationDate) ? Chronos::parse($expirationDate) : null); diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index b67343d8..f3d4d30e 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -11,6 +11,8 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function array_filter; +use function sprintf; class ListKeysCommand extends Command { @@ -36,7 +38,7 @@ class ListKeysCommand extends Command parent::__construct(); } - public function configure() + protected function configure(): void { $this->setName(self::NAME) ->setDescription($this->translator->translate('Lists all the available API keys.')) @@ -48,7 +50,7 @@ class ListKeysCommand extends Command ); } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $enabledOnly = $input->getOption('enabledOnly'); @@ -62,16 +64,16 @@ class ListKeysCommand extends Command $messagePattern = $this->determineMessagePattern($row); // Set columns for this row - $rowData = [\sprintf($messagePattern, $key)]; + $rowData = [sprintf($messagePattern, $key)]; if (! $enabledOnly) { - $rowData[] = \sprintf($messagePattern, $this->getEnabledSymbol($row)); + $rowData[] = sprintf($messagePattern, $this->getEnabledSymbol($row)); } $rowData[] = $expiration !== null ? $expiration->toAtomString() : '-'; $rows[] = $rowData; } - $io->table(\array_filter([ + $io->table(array_filter([ $this->translator->translate('Key'), ! $enabledOnly ? $this->translator->translate('Is enabled') : null, $this->translator->translate('Expiration date'), diff --git a/module/CLI/src/Command/Config/GenerateCharsetCommand.php b/module/CLI/src/Command/Config/GenerateCharsetCommand.php index c7287f7f..93b48541 100644 --- a/module/CLI/src/Command/Config/GenerateCharsetCommand.php +++ b/module/CLI/src/Command/Config/GenerateCharsetCommand.php @@ -9,10 +9,12 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; +use function str_shuffle; class GenerateCharsetCommand extends Command { - const NAME = 'config:generate-charset'; + public const NAME = 'config:generate-charset'; /** * @var TranslatorInterface @@ -25,20 +27,20 @@ class GenerateCharsetCommand extends Command parent::__construct(); } - public function configure() + protected function configure(): void { $this->setName(self::NAME) - ->setDescription(\sprintf($this->translator->translate( + ->setDescription(sprintf($this->translator->translate( 'Generates a character set sample just by shuffling the default one, "%s". ' . 'Then it can be set in the SHORTCODE_CHARS environment variable' ), UrlShortener::DEFAULT_CHARS)); } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $charSet = str_shuffle(UrlShortener::DEFAULT_CHARS); (new SymfonyStyle($input, $output))->success( - \sprintf($this->translator->translate('Character set: "%s"'), $charSet) + sprintf($this->translator->translate('Character set: "%s"'), $charSet) ); } } diff --git a/module/CLI/src/Command/Config/GenerateSecretCommand.php b/module/CLI/src/Command/Config/GenerateSecretCommand.php index 684d6c8f..aaa7f2ef 100644 --- a/module/CLI/src/Command/Config/GenerateSecretCommand.php +++ b/module/CLI/src/Command/Config/GenerateSecretCommand.php @@ -9,12 +9,13 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class GenerateSecretCommand extends Command { use StringUtilsTrait; - const NAME = 'config:generate-secret'; + public const NAME = 'config:generate-secret'; /** * @var TranslatorInterface @@ -27,7 +28,7 @@ class GenerateSecretCommand extends Command parent::__construct(); } - public function configure() + protected function configure(): void { $this->setName(self::NAME) ->setDescription($this->translator->translate( @@ -35,7 +36,7 @@ class GenerateSecretCommand extends Command )); } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $secret = $this->generateRandomString(32); (new SymfonyStyle($input, $output))->success( diff --git a/module/CLI/src/Command/Tag/CreateTagCommand.php b/module/CLI/src/Command/Tag/CreateTagCommand.php index daf03d15..d50d2124 100644 --- a/module/CLI/src/Command/Tag/CreateTagCommand.php +++ b/module/CLI/src/Command/Tag/CreateTagCommand.php @@ -13,7 +13,7 @@ use Zend\I18n\Translator\TranslatorInterface; class CreateTagCommand extends Command { - const NAME = 'tag:create'; + public const NAME = 'tag:create'; /** * @var TagServiceInterface @@ -31,7 +31,7 @@ class CreateTagCommand extends Command parent::__construct(); } - protected function configure() + protected function configure(): void { $this ->setName(self::NAME) @@ -44,7 +44,7 @@ class CreateTagCommand extends Command ); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $tagNames = $input->getOption('name'); diff --git a/module/CLI/src/Command/Tag/DeleteTagsCommand.php b/module/CLI/src/Command/Tag/DeleteTagsCommand.php index 5da57ede..0ea36e3f 100644 --- a/module/CLI/src/Command/Tag/DeleteTagsCommand.php +++ b/module/CLI/src/Command/Tag/DeleteTagsCommand.php @@ -13,7 +13,7 @@ use Zend\I18n\Translator\TranslatorInterface; class DeleteTagsCommand extends Command { - const NAME = 'tag:delete'; + public const NAME = 'tag:delete'; /** * @var TagServiceInterface @@ -31,7 +31,7 @@ class DeleteTagsCommand extends Command parent::__construct(); } - protected function configure() + protected function configure(): void { $this ->setName(self::NAME) @@ -44,7 +44,7 @@ class DeleteTagsCommand extends Command ); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $tagNames = $input->getOption('name'); diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php index ea860900..e82617dd 100644 --- a/module/CLI/src/Command/Tag/ListTagsCommand.php +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -10,10 +10,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function array_map; class ListTagsCommand extends Command { - const NAME = 'tag:list'; + public const NAME = 'tag:list'; /** * @var TagServiceInterface @@ -31,14 +32,14 @@ class ListTagsCommand extends Command parent::__construct(); } - protected function configure() + protected function configure(): void { $this ->setName(self::NAME) ->setDescription($this->translator->translate('Lists existing tags.')); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $io->table([$this->translator->translate('Name')], $this->getTagsRows()); @@ -51,7 +52,7 @@ class ListTagsCommand extends Command return [[$this->translator->translate('No tags yet')]]; } - return \array_map(function (Tag $tag) { + return array_map(function (Tag $tag) { return [$tag->getName()]; }, $tags); } diff --git a/module/CLI/src/Command/Tag/RenameTagCommand.php b/module/CLI/src/Command/Tag/RenameTagCommand.php index f76c05f2..e95affed 100644 --- a/module/CLI/src/Command/Tag/RenameTagCommand.php +++ b/module/CLI/src/Command/Tag/RenameTagCommand.php @@ -11,10 +11,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class RenameTagCommand extends Command { - const NAME = 'tag:rename'; + public const NAME = 'tag:rename'; /** * @var TagServiceInterface @@ -32,7 +33,7 @@ class RenameTagCommand extends Command parent::__construct(); } - protected function configure() + protected function configure(): void { $this ->setName(self::NAME) @@ -41,7 +42,7 @@ class RenameTagCommand extends Command ->addArgument('newName', InputArgument::REQUIRED, $this->translator->translate('New name of the tag.')); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $oldName = $input->getArgument('oldName'); @@ -51,7 +52,7 @@ class RenameTagCommand extends Command $this->tagService->renameTag($oldName, $newName); $io->success($this->translator->translate('Tag properly renamed.')); } catch (EntityDoesNotExistException $e) { - $io->error(\sprintf($this->translator->translate('A tag with name "%s" was not found'), $oldName)); + $io->error(sprintf($this->translator->translate('A tag with name "%s" was not found'), $oldName)); } } } diff --git a/module/CLI/src/Command/Visit/ProcessVisitsCommand.php b/module/CLI/src/Command/Visit/ProcessVisitsCommand.php index 2ae4e432..2a6980c9 100644 --- a/module/CLI/src/Command/Visit/ProcessVisitsCommand.php +++ b/module/CLI/src/Command/Visit/ProcessVisitsCommand.php @@ -13,6 +13,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sleep; +use function sprintf; class ProcessVisitsCommand extends Command { @@ -42,7 +44,7 @@ class ProcessVisitsCommand extends Command parent::__construct(null); } - public function configure() + protected function configure(): void { $this->setName(self::NAME) ->setDescription( @@ -50,7 +52,7 @@ class ProcessVisitsCommand extends Command ); } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $visits = $this->visitService->getUnlocatedVisits(); @@ -58,10 +60,10 @@ class ProcessVisitsCommand extends Command $count = 0; foreach ($visits as $visit) { $ipAddr = $visit->getRemoteAddr(); - $io->write(\sprintf('%s %s', $this->translator->translate('Processing IP'), $ipAddr)); + $io->write(sprintf('%s %s', $this->translator->translate('Processing IP'), $ipAddr)); if ($ipAddr === IpAddress::LOCALHOST) { $io->writeln( - \sprintf(' (%s)', $this->translator->translate('Ignored localhost address')) + sprintf(' (%s)', $this->translator->translate('Ignored localhost address')) ); continue; } @@ -75,13 +77,13 @@ class ProcessVisitsCommand extends Command $visit->setVisitLocation($location); $this->visitService->saveVisit($visit); - $io->writeln(\sprintf( + $io->writeln(sprintf( ' (' . $this->translator->translate('Address located at "%s"') . ')', $location->getCityName() )); } catch (WrongIpException $e) { $io->writeln( - \sprintf(' %s', $this->translator->translate('An error occurred while locating IP')) + sprintf(' %s', $this->translator->translate('An error occurred while locating IP')) ); if ($io->isVerbose()) { $this->getApplication()->renderException($e, $output); @@ -91,11 +93,11 @@ class ProcessVisitsCommand extends Command if ($count === $this->ipLocationResolver->getApiLimit()) { $count = 0; $seconds = $this->ipLocationResolver->getApiInterval(); - $io->note(\sprintf( + $io->note(sprintf( $this->translator->translate('IP location resolver limit reached. Waiting %s seconds...'), $seconds )); - \sleep($seconds); + sleep($seconds); } }