From 2044ddf2a0d02f9af0a1e5cebf7a6032838d0e6b Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 9 Feb 2022 22:21:20 +0200 Subject: [PATCH 1/8] Use a different image for PHP CS Fixer to get latest and upgrade config --- .github/workflows/static.yml | 32 ++++---------------------------- .php-cs-fixer.dist.php | 21 +++++++++++++++++++++ .php_cs | 22 ---------------------- 3 files changed, 25 insertions(+), 50 deletions(-) create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php_cs diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index a02e633e..85bebfb3 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -38,35 +38,11 @@ jobs: php-cs-fixer: name: PHP-CS-Fixer - runs-on: Ubuntu-20.04 - + runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Cache PhpCsFixer - uses: actions/cache@v2 - with: - path: .github/.cache/php-cs-fixer/ - key: php-cs-fixer-${{ github.sha }} - restore-keys: php-cs-fixer- - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - coverage: none - - - name: Download dependencies - uses: ramsey/composer-install@v1 - with: - composer-options: --no-interaction --prefer-dist --optimize-autoloader - - - name: Download PHP CS Fixer - run: composer bin php-cs-fixer update --no-interaction --no-progress - - - name: Execute PHP CS Fixer - run: vendor/bin/php-cs-fixer fix --diff-format udiff --dry-run + - uses: actions/checkout@v2 + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga psalm: name: Psalm diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..9d5191e9 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,21 @@ +exclude(__DIR__.'/vendor') + ->name('*.php') + ->in(__DIR__) +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => ['syntax' => 'short'], + 'native_function_invocation' => true, + 'ordered_imports' => true, + 'declare_strict_types' => false, + 'single_import_per_statement' => false, + ]) + ->setRiskyAllowed(true) + ->setFinder($finder) +; diff --git a/.php_cs b/.php_cs deleted file mode 100644 index f23ada12..00000000 --- a/.php_cs +++ /dev/null @@ -1,22 +0,0 @@ -setRiskyAllowed(true) - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - 'array_syntax' => array('syntax' => 'short'), - 'native_function_invocation' => true, - 'ordered_imports' => true, - 'declare_strict_types' => false, - 'single_import_per_statement' => false, - ]) - ->setFinder( - PhpCsFixer\Finder::create() - ->in(__DIR__) - ->exclude(__DIR__.'/vendor') - ->name('*.php') - ) -; - -return $config; From 7757118cd13f0d2cf5fde890113e07ae4a87bf11 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 9 Feb 2022 22:26:56 +0200 Subject: [PATCH 2/8] Add new cache file from PHP CS Fixer to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4d522194..7c0f5345 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /phpunit.xml /vendor/ .php_cs.cache +.php-cs-fixer.cache .phpunit.result.cache From 5285d20212e57695bff09f9b5e9b824ac6508b4a Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 9 Feb 2022 22:27:10 +0200 Subject: [PATCH 3/8] Brake styles --- Twig/TranslationExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Twig/TranslationExtension.php b/Twig/TranslationExtension.php index 0cfc97ac..bac98551 100644 --- a/Twig/TranslationExtension.php +++ b/Twig/TranslationExtension.php @@ -36,7 +36,7 @@ final class TranslationExtension extends AbstractExtension */ private $debug; - public function __construct($translator, bool $debug = false) + public function __construct($translator, bool $debug = false) { // The TranslatorInterface has been deprecated in favor of Symfony\Contracts\Translation\TranslatorInterface in sf4.2. // Use this class to type hint event & remove the following condition once sf ^4.2 become the minimum supported version. From ee773bf2ebc6cf4e30ac73007db6b70c9aecf930 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 9 Feb 2022 22:30:20 +0200 Subject: [PATCH 4/8] Add --dry-run and --diff --- .github/workflows/static.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 85bebfb3..b4b5d41e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -43,6 +43,8 @@ jobs: - uses: actions/checkout@v2 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --diff --dry-run psalm: name: Psalm From 6f54009f9450427470994ba0dc6299d1e3df2a69 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 9 Feb 2022 22:31:39 +0200 Subject: [PATCH 5/8] Revert "Brake styles" This reverts commit 5285d20212e57695bff09f9b5e9b824ac6508b4a. --- Twig/TranslationExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Twig/TranslationExtension.php b/Twig/TranslationExtension.php index bac98551..0cfc97ac 100644 --- a/Twig/TranslationExtension.php +++ b/Twig/TranslationExtension.php @@ -36,7 +36,7 @@ final class TranslationExtension extends AbstractExtension */ private $debug; - public function __construct($translator, bool $debug = false) + public function __construct($translator, bool $debug = false) { // The TranslatorInterface has been deprecated in favor of Symfony\Contracts\Translation\TranslatorInterface in sf4.2. // Use this class to type hint event & remove the following condition once sf ^4.2 become the minimum supported version. From 6710a78b8f56c0adedecf1b645e73380cde04b81 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 9 Feb 2022 22:33:25 +0200 Subject: [PATCH 6/8] Fix all code styles with the new version of PHP CS Fixer --- Catalogue/CatalogueFetcher.php | 2 +- Catalogue/CatalogueManager.php | 4 ++-- Catalogue/Operation/ReplaceOperation.php | 4 ++-- Command/BundleTrait.php | 8 ++++---- Command/CheckMissingCommand.php | 6 +++--- Command/DeleteEmptyCommand.php | 4 ++-- Command/DeleteObsoleteCommand.php | 4 ++-- Command/DownloadCommand.php | 12 ++++++------ Command/ExtractCommand.php | 2 +- Command/StatusCommand.php | 2 +- Command/StorageTrait.php | 2 +- Command/SyncCommand.php | 4 ++-- Controller/EditInPlaceController.php | 4 ++-- Controller/SymfonyProfilerController.php | 10 +++++----- Controller/WebUIController.php | 12 ++++++------ .../CompilerPass/ExternalTranslatorPass.php | 2 +- .../CompilerPass/StoragePass.php | 2 +- DependencyInjection/Configuration.php | 18 +++++++++--------- DependencyInjection/TranslationExtension.php | 4 ++-- EditInPlace/Activator.php | 2 +- EventListener/AutoAddMissingTranslations.php | 4 ++-- EventListener/EditInPlaceResponseListener.php | 14 +++++++------- Legacy/LegacyHelper.php | 2 +- Model/Configuration.php | 2 +- Model/Metadata.php | 4 ++-- Model/SfProfilerMessage.php | 2 +- Service/CacheClearer.php | 2 +- Service/ConfigurationManager.php | 4 ++-- Service/Importer.php | 4 ++-- Service/StorageManager.php | 2 +- Service/StorageService.php | 6 +++--- .../Catalogue/CatalogueFetcherTest.php | 2 +- .../Command/CheckMissingCommandTest.php | 4 ++-- .../Functional/Command/ExtractCommandTest.php | 4 ++-- Tests/Functional/Command/StatusCommandTest.php | 2 +- Tests/Functional/Command/SyncCommandTest.php | 2 +- .../Controller/EditInPlaceControllerTest.php | 6 +++--- .../Functional/Controller/EditInPlaceTest.php | 4 ++-- .../Controller/WebUIControllerTest.php | 14 +++++++------- Tests/Unit/Catalogue/CatalogueManagerTest.php | 8 ++++---- Tests/Unit/Model/ConfigurationTest.php | 2 +- .../Unit/Service/ConfigurationManagerTest.php | 2 +- .../Translator/EditInPlaceTranslatorTest.php | 2 +- .../Unit/Translator/FallbackTranslatorTest.php | 2 +- Tests/Unit/Twig/BaseTwigTestCase.php | 4 ++-- Tests/Unit/Twig/RemovingNodeVisitorTest.php | 2 +- Translator/EditInPlaceTranslator.php | 8 ++++---- Translator/FallbackTranslator.php | 6 +++--- Translator/TranslatorInterface.php | 2 +- Twig/Node/Transchoice.php | 2 +- Twig/TranslationExtension.php | 4 ++-- 51 files changed, 118 insertions(+), 118 deletions(-) diff --git a/Catalogue/CatalogueFetcher.php b/Catalogue/CatalogueFetcher.php index 0ee5cf00..504d305e 100644 --- a/Catalogue/CatalogueFetcher.php +++ b/Catalogue/CatalogueFetcher.php @@ -46,7 +46,7 @@ public function getCatalogues(Configuration $config, array $locales = []): array foreach ($locales as $locale) { $currentCatalogue = new MessageCatalogue($locale); foreach ($dirs as $path) { - if (\is_dir($path)) { + if (is_dir($path)) { $this->reader->read($path, $currentCatalogue); } } diff --git a/Catalogue/CatalogueManager.php b/Catalogue/CatalogueManager.php index cd8089d7..5d554c0e 100644 --- a/Catalogue/CatalogueManager.php +++ b/Catalogue/CatalogueManager.php @@ -42,7 +42,7 @@ public function load(array $catalogues): void public function getDomains(): array { /** @var MessageCatalogueInterface $c */ - $c = \reset($this->catalogues); + $c = reset($this->catalogues); return $c->getDomains(); } @@ -107,7 +107,7 @@ public function findMessages(array $config = []): array } } - $messages = \array_filter($messages, static function (CatalogueMessage $m) use ($isNew, $isObsolete, $isApproved, $isEmpty) { + $messages = array_filter($messages, static function (CatalogueMessage $m) use ($isNew, $isObsolete, $isApproved, $isEmpty) { if (null !== $isNew && $m->isNew() !== $isNew) { return false; } diff --git a/Catalogue/Operation/ReplaceOperation.php b/Catalogue/Operation/ReplaceOperation.php index 7b572103..bdf277e2 100644 --- a/Catalogue/Operation/ReplaceOperation.php +++ b/Catalogue/Operation/ReplaceOperation.php @@ -37,7 +37,7 @@ protected function processDomain($domain): void 'new' => [], 'obsolete' => [], ]; - if (\defined(\sprintf('%s::INTL_DOMAIN_SUFFIX', MessageCatalogueInterface::class))) { + if (\defined(sprintf('%s::INTL_DOMAIN_SUFFIX', MessageCatalogueInterface::class))) { $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX; } else { $intlDomain = $domain; @@ -160,6 +160,6 @@ public function isArrayAssociative(array $arr): bool return false; } - return \array_keys($arr) !== \range(0, \count($arr) - 1); + return array_keys($arr) !== range(0, \count($arr) - 1); } } diff --git a/Command/BundleTrait.php b/Command/BundleTrait.php index be4cd778..cf8af0c0 100644 --- a/Command/BundleTrait.php +++ b/Command/BundleTrait.php @@ -20,11 +20,11 @@ trait BundleTrait private function configureBundleDirs(InputInterface $input, Configuration $config): void { if ($bundleName = $input->getOption('bundle')) { - if (0 === \strpos($bundleName, '@')) { - if (false === $pos = \strpos($bundleName, '/')) { - $bundleName = \substr($bundleName, 1); + if (0 === strpos($bundleName, '@')) { + if (false === $pos = strpos($bundleName, '/')) { + $bundleName = substr($bundleName, 1); } else { - $bundleName = \substr($bundleName, 1, $pos - 2); + $bundleName = substr($bundleName, 1, $pos - 2); } } diff --git a/Command/CheckMissingCommand.php b/Command/CheckMissingCommand.php index 9618e105..46a09e09 100644 --- a/Command/CheckMissingCommand.php +++ b/Command/CheckMissingCommand.php @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io = new SymfonyStyle($input, $output); if ($newMessages > 0) { - $io->error(\sprintf('%d new message(s) have been found, run bin/console translation:extract', $newMessages)); + $io->error(sprintf('%d new message(s) have been found, run bin/console translation:extract', $newMessages)); return 1; } @@ -100,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($emptyTranslations > 0) { $io->error( - \sprintf('%d messages have empty translations, please provide translations for them', $emptyTranslations) + sprintf('%d messages have empty translations, please provide translations for them', $emptyTranslations) ); return 1; @@ -132,7 +132,7 @@ private function countEmptyTranslations(MessageCatalogueInterface $catalogue): i $total = 0; foreach ($catalogue->getDomains() as $domain) { - $emptyTranslations = \array_filter( + $emptyTranslations = array_filter( $catalogue->all($domain), function (string $message = null): bool { return null === $message || '' === $message; diff --git a/Command/DeleteEmptyCommand.php b/Command/DeleteEmptyCommand.php index 67c4e97a..3c40a997 100644 --- a/Command/DeleteEmptyCommand.php +++ b/Command/DeleteEmptyCommand.php @@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($input->isInteractive()) { $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion(\sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false); + $question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false); if (!$helper->ask($input, $output, $question)) { return 0; } @@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($messages as $message) { $storage->delete($message->getLocale(), $message->getDomain(), $message->getKey()); if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { - $output->writeln(\sprintf( + $output->writeln(sprintf( 'Deleted empty message "%s" from domain "%s" and locale "%s"', $message->getKey(), $message->getDomain(), diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index 67a9dfda..1132559c 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($input->isInteractive()) { $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion(\sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false); + $question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false); if (!$helper->ask($input, $output, $question)) { return 0; } @@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($messages as $message) { $storage->delete($message->getLocale(), $message->getDomain(), $message->getKey()); if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { - $output->writeln(\sprintf( + $output->writeln(sprintf( 'Deleted obsolete message "%s" from domain "%s" and locale "%s"', $message->getKey(), $message->getDomain(), diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index a64999d4..d877afa8 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $message = 'The --cache option is deprecated as it\'s now the default behaviour of this command.'; $io->note($message); - @\trigger_error($message, \E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); } $configName = $input->getArgument('configuration'); @@ -117,19 +117,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int */ private function hashDirectory(string $directory) { - if (!\is_dir($directory)) { + if (!is_dir($directory)) { return false; } $finder = new Finder(); $finder->files()->in($directory)->notName('/~$/')->sortByName(); - $hash = \hash_init('md5'); + $hash = hash_init('md5'); foreach ($finder as $file) { - \hash_update_file($hash, $file->getRealPath()); + hash_update_file($hash, $file->getRealPath()); } - return \hash_final($hash); + return hash_final($hash); } public function cleanParameters(array $raw) @@ -138,7 +138,7 @@ public function cleanParameters(array $raw) foreach ($raw as $string) { // Assert $string looks like "foo:bar" - list($key, $value) = \explode(':', $string, 2); + list($key, $value) = explode(':', $string, 2); $config[$key][] = $value; } diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 98dba731..065c6e43 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -128,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var Error $error */ foreach ($errors as $error) { $io->error( - \sprintf("%s\nLine: %s\nMessage: %s", $error->getPath(), $error->getLine(), $error->getMessage()) + sprintf("%s\nLine: %s\nMessage: %s", $error->getPath(), $error->getLine(), $error->getMessage()) ); } } diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 157cd480..73e21fa4 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($input->getOption('json')) { - $output->writeln(\json_encode($stats)); + $output->writeln(json_encode($stats)); return 0; } diff --git a/Command/StorageTrait.php b/Command/StorageTrait.php index ca6fe2ef..fef48bbf 100644 --- a/Command/StorageTrait.php +++ b/Command/StorageTrait.php @@ -31,7 +31,7 @@ private function getStorage($configName): StorageService if (null === $storage = $this->storageManager->getStorage($configName)) { $availableStorages = $this->storageManager->getNames(); - throw new \InvalidArgumentException(\sprintf('Unknown storage "%s". Available storages are "%s".', $configName, \implode('", "', $availableStorages))); + throw new \InvalidArgumentException(sprintf('Unknown storage "%s". Available storages are "%s".', $configName, implode('", "', $availableStorages))); } return $storage; diff --git a/Command/SyncCommand.php b/Command/SyncCommand.php index 345affb3..859872ff 100644 --- a/Command/SyncCommand.php +++ b/Command/SyncCommand.php @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int break; default: - $output->writeln(\sprintf('Direction must be either "up" or "down". Not "%s".', $input->getArgument('direction'))); + $output->writeln(sprintf('Direction must be either "up" or "down". Not "%s".', $input->getArgument('direction'))); return 0; } @@ -78,7 +78,7 @@ public function cleanParameters(array $raw) foreach ($raw as $string) { // Assert $string looks like "foo:bar" - list($key, $value) = \explode(':', $string, 2); + list($key, $value) = explode(':', $string, 2); $config[$key][] = $value; } diff --git a/Controller/EditInPlaceController.php b/Controller/EditInPlaceController.php index 32296ce8..66e2ca41 100644 --- a/Controller/EditInPlaceController.php +++ b/Controller/EditInPlaceController.php @@ -66,11 +66,11 @@ public function editAction(Request $request, string $configName, string $locale) private function getMessages(Request $request, string $locale, array $validationGroups = []): array { $json = $request->getContent(); - $data = \json_decode($json, true); + $data = json_decode($json, true); $messages = []; foreach ($data as $key => $value) { - [$domain, $translationKey] = \explode('|', $key); + [$domain, $translationKey] = explode('|', $key); $message = new Message($translationKey, $domain, $locale, $value); diff --git a/Controller/SymfonyProfilerController.php b/Controller/SymfonyProfilerController.php index cae0e5d9..58be70cf 100644 --- a/Controller/SymfonyProfilerController.php +++ b/Controller/SymfonyProfilerController.php @@ -130,7 +130,7 @@ public function createAssetsAction(Request $request, string $token): Response $uploaded[] = $message; } - return new Response(\sprintf('%s new assets created!', \count($uploaded))); + return new Response(sprintf('%s new assets created!', \count($uploaded))); } private function getMessage(Request $request, string $token): SfProfilerMessage @@ -142,7 +142,7 @@ private function getMessage(Request $request, string $token): SfProfilerMessage $collectorMessages = $this->getMessages($token); if (!isset($collectorMessages[$messageId])) { - throw new NotFoundHttpException(\sprintf('No message with key "%s" was found.', $messageId)); + throw new NotFoundHttpException(sprintf('No message with key "%s" was found.', $messageId)); } $message = SfProfilerMessage::create($collectorMessages[$messageId]); @@ -152,7 +152,7 @@ private function getMessage(Request $request, string $token): SfProfilerMessage $message ->setLocale($requestCollector->getLocale()) - ->setTranslation(\sprintf('[%s]', $message->getTranslation())) + ->setTranslation(sprintf('[%s]', $message->getTranslation())) ; } @@ -172,7 +172,7 @@ protected function getSelectedMessages(Request $request, string $token): array return []; } - $toSave = \array_intersect_key($this->getMessages($token), \array_flip($selected)); + $toSave = array_intersect_key($this->getMessages($token), array_flip($selected)); $messages = []; foreach ($toSave as $data) { @@ -195,7 +195,7 @@ private function getMessages(string $token, string $profileName = 'translation') $messages = $dataCollector->getMessages(); - if (\class_exists(Data::class) && $messages instanceof Data) { + if (class_exists(Data::class) && $messages instanceof Data) { return $messages->getValue(true); } diff --git a/Controller/WebUIController.php b/Controller/WebUIController.php index 32d3a2cd..2ce6de07 100644 --- a/Controller/WebUIController.php +++ b/Controller/WebUIController.php @@ -95,7 +95,7 @@ public function indexAction(?string $configName = null): Response foreach ($catalogues as $catalogue) { $locale = $catalogue->getLocale(); $domains = $catalogue->all(); - \ksort($domains); + ksort($domains); $catalogueSize[$locale] = 0; foreach ($domains as $domain => $messages) { $count = \count($messages); @@ -138,8 +138,8 @@ public function showAction(string $configName, string $locale, string $domain): /** @var CatalogueMessage[] $messages */ $messages = $this->catalogueManager->getMessages($locale, $domain); - \usort($messages, function (CatalogueMessage $a, CatalogueMessage $b) { - return \strcmp($a->getKey(), $b->getKey()); + usort($messages, function (CatalogueMessage $a, CatalogueMessage $b) { + return strcmp($a->getKey(), $b->getKey()); }); $content = $this->twig->render('@Translation/WebUI/show.html.twig', [ @@ -179,7 +179,7 @@ public function createAction(Request $request, string $configName, string $local try { $storage->create($message); } catch (StorageException $e) { - throw new BadRequestHttpException(\sprintf('Key "%s" does already exist for "%s" on domain "%s".', $message->getKey(), $locale, $domain), $e); + throw new BadRequestHttpException(sprintf('Key "%s" does already exist for "%s" on domain "%s".', $message->getKey(), $locale, $domain), $e); } catch (\Exception $e) { return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST); } @@ -246,7 +246,7 @@ public function deleteAction(Request $request, string $configName, string $local private function getMessageFromRequest(Request $request): Message { $json = $request->getContent(); - $data = \json_decode($json, true); + $data = json_decode($json, true); $message = new Message($data['key']); if (isset($data['message'])) { $message = $message->withTranslation($data['message']); @@ -262,7 +262,7 @@ private function getMessageFromRequest(Request $request): Message */ private function getLocale2LanguageMap(): array { - $names = \class_exists(Locales::class) + $names = class_exists(Locales::class) ? Locales::getNames('en') : Intl::getLocaleBundle()->getLocaleNames('en'); $map = []; diff --git a/DependencyInjection/CompilerPass/ExternalTranslatorPass.php b/DependencyInjection/CompilerPass/ExternalTranslatorPass.php index e078ae8f..fc01c227 100644 --- a/DependencyInjection/CompilerPass/ExternalTranslatorPass.php +++ b/DependencyInjection/CompilerPass/ExternalTranslatorPass.php @@ -38,7 +38,7 @@ public function process(ContainerBuilder $container): void } // Sort by priority - \asort($translators); + asort($translators); $def = $container->getDefinition('php_translation.translator_service.external_translator'); foreach ($translators as $id => $prio) { diff --git a/DependencyInjection/CompilerPass/StoragePass.php b/DependencyInjection/CompilerPass/StoragePass.php index ac448b6d..3e2b6034 100644 --- a/DependencyInjection/CompilerPass/StoragePass.php +++ b/DependencyInjection/CompilerPass/StoragePass.php @@ -51,7 +51,7 @@ public function process(ContainerBuilder $container): void break; default: - throw new \LogicException(\sprintf('The tag "php_translation.storage" must have a "type" of value "local" or "remote". Value "%s" was provided', $tag['type'])); + throw new \LogicException(sprintf('The tag "php_translation.storage" must have a "type" of value "local" or "remote". Value "%s" was provided', $tag['type'])); } } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index da7753b4..518eea73 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -36,7 +36,7 @@ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('translation'); // Keep compatibility with symfony/config < 4.2 - if (!\method_exists($treeBuilder, 'getRootNode')) { + if (!method_exists($treeBuilder, 'getRootNode')) { $root = $treeBuilder->root('translation'); } else { $root = $treeBuilder->getRootNode(); @@ -109,26 +109,26 @@ private function configsNode(ArrayNodeDefinition $root): void ->prototype('scalar') ->validate() ->always(function ($value) use ($container) { - $value = \str_replace(\DIRECTORY_SEPARATOR, '/', $value); + $value = str_replace(\DIRECTORY_SEPARATOR, '/', $value); if ('@' === $value[0]) { - if (false === $pos = \strpos($value, '/')) { - $bundleName = \substr($value, 1); + if (false === $pos = strpos($value, '/')) { + $bundleName = substr($value, 1); } else { - $bundleName = \substr($value, 1, $pos - 2); + $bundleName = substr($value, 1, $pos - 2); } $bundles = $container->getParameter('kernel.bundles'); if (!isset($bundles[$bundleName])) { - throw new \Exception(\sprintf('The bundle "%s" does not exist. Available bundles: %s', $bundleName, \array_keys($bundles))); + throw new \Exception(sprintf('The bundle "%s" does not exist. Available bundles: %s', $bundleName, array_keys($bundles))); } $ref = new \ReflectionClass($bundles[$bundleName]); - $value = false === $pos ? \dirname($ref->getFileName()) : \dirname($ref->getFileName()).\substr($value, $pos); + $value = false === $pos ? \dirname($ref->getFileName()) : \dirname($ref->getFileName()).substr($value, $pos); } - if (!\is_dir($value)) { - throw new \Exception(\sprintf('The directory "%s" does not exist.', $value)); + if (!is_dir($value)) { + throw new \Exception(sprintf('The directory "%s" does not exist.', $value)); } return $value; diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 7fdb0582..24424863 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -174,7 +174,7 @@ private function enableWebUi(ContainerBuilder $container, array $config): void $path = $container->getParameter('kernel.project_dir'); } - $container->setParameter('php_translation.webui.file_base_path', \rtrim($path, '/').'/'); + $container->setParameter('php_translation.webui.file_base_path', rtrim($path, '/').'/'); } /** @@ -185,7 +185,7 @@ private function enableEditInPlace(ContainerBuilder $container, array $config): $name = $config['edit_in_place']['config_name']; if ('default' !== $name && !isset($config['configs'][$name])) { - throw new InvalidArgumentException(\sprintf('There is no config named "%s".', $name)); + throw new InvalidArgumentException(sprintf('There is no config named "%s".', $name)); } $activatorRef = new Reference($config['edit_in_place']['activator']); diff --git a/EditInPlace/Activator.php b/EditInPlace/Activator.php index 16c2045c..3184f6c0 100644 --- a/EditInPlace/Activator.php +++ b/EditInPlace/Activator.php @@ -22,7 +22,7 @@ */ final class Activator implements ActivatorInterface { - const KEY = 'translation_bundle.edit_in_place.enabled'; + public const KEY = 'translation_bundle.edit_in_place.enabled'; /** * @var RequestStack diff --git a/EventListener/AutoAddMissingTranslations.php b/EventListener/AutoAddMissingTranslations.php index b30ab672..5cfcac66 100644 --- a/EventListener/AutoAddMissingTranslations.php +++ b/EventListener/AutoAddMissingTranslations.php @@ -60,6 +60,6 @@ public function onTerminate(TerminateEvent $event): void // PostResponseEvent have been renamed into ResponseEvent in sf 4.3 // @see https://github.com/symfony/symfony/blob/master/UPGRADE-4.3.md#httpkernel // To be removed once sf ^4.3 become the minimum supported version. -if (!\class_exists(TerminateEvent::class) && \class_exists(PostResponseEvent::class)) { - \class_alias(PostResponseEvent::class, TerminateEvent::class); +if (!class_exists(TerminateEvent::class) && class_exists(PostResponseEvent::class)) { + class_alias(PostResponseEvent::class, TerminateEvent::class); } diff --git a/EventListener/EditInPlaceResponseListener.php b/EventListener/EditInPlaceResponseListener.php index e61c1789..9c296e08 100644 --- a/EventListener/EditInPlaceResponseListener.php +++ b/EventListener/EditInPlaceResponseListener.php @@ -24,7 +24,7 @@ */ final class EditInPlaceResponseListener { - const HTML = <<<'HTML' + public const HTML = <<<'HTML' @@ -95,7 +95,7 @@ public function onKernelResponse(ResponseEvent $event): void if (!$this->showUntranslatable) { $replacement = '"$3"'; } - $content = \preg_replace($pattern, $replacement, $content); + $content = preg_replace($pattern, $replacement, $content); // Remove escaped content (e.g. Javascript) $pattern = '@<x-trans.+data-key="([^&]+)".+data-value="([^&]+)".+<\\/x-trans>@mi'; @@ -103,9 +103,9 @@ public function onKernelResponse(ResponseEvent $event): void if (!$this->showUntranslatable) { $replacement = '$2'; } - $content = \preg_replace($pattern, $replacement, $content); + $content = preg_replace($pattern, $replacement, $content); - $html = \sprintf( + $html = sprintf( self::HTML, $this->packages->getUrl('bundles/translation/css/content-tools.min.css'), $this->packages->getUrl('bundles/translation/js/content-tools.min.js'), @@ -116,7 +116,7 @@ public function onKernelResponse(ResponseEvent $event): void 'locale' => $event->getRequest()->getLocale(), ]) ); - $content = \str_replace('', $html."\n".'', $content); + $content = str_replace('', $html."\n".'', $content); $response = $event->getResponse(); @@ -132,6 +132,6 @@ public function onKernelResponse(ResponseEvent $event): void // FilterResponseEvent have been renamed into ResponseEvent in sf 4.3 // @see https://github.com/symfony/symfony/blob/master/UPGRADE-4.3.md#httpkernel // To be removed once sf ^4.3 become the minimum supported version. -if (!\class_exists(ResponseEvent::class) && \class_exists(FilterResponseEvent::class)) { - \class_alias(FilterResponseEvent::class, ResponseEvent::class); +if (!class_exists(ResponseEvent::class) && class_exists(FilterResponseEvent::class)) { + class_alias(FilterResponseEvent::class, ResponseEvent::class); } diff --git a/Legacy/LegacyHelper.php b/Legacy/LegacyHelper.php index c59cba6d..42d15a87 100644 --- a/Legacy/LegacyHelper.php +++ b/Legacy/LegacyHelper.php @@ -24,7 +24,7 @@ class LegacyHelper { public static function getMainRequest(RequestStack $requestStack) { - if (\method_exists($requestStack, 'getMainRequest')) { + if (method_exists($requestStack, 'getMainRequest')) { return $requestStack->getMainRequest(); } diff --git a/Model/Configuration.php b/Model/Configuration.php index 1945c7bd..e4f7bdac 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -169,7 +169,7 @@ public function getWhitelistDomains(): array */ public function getPathsToTranslationFiles(): array { - return \array_merge($this->externalTranslationsDirs, [$this->getOutputDir()]); + return array_merge($this->externalTranslationsDirs, [$this->getOutputDir()]); } public function getXliffVersion(): string diff --git a/Model/Metadata.php b/Model/Metadata.php index 194f7141..e5bbf019 100644 --- a/Model/Metadata.php +++ b/Model/Metadata.php @@ -114,7 +114,7 @@ public function getSourceLocations(): array if (!isset($note['content'])) { continue; } - list($path, $line) = \explode(':', $note['content'], 2); + list($path, $line) = explode(':', $note['content'], 2); $sources[] = ['path' => $path, 'line' => $line]; } @@ -155,7 +155,7 @@ public function getAllInCategory(string $category): array } } - \usort($data, static function (array $a, array $b) { + usort($data, static function (array $a, array $b) { return (int) $a['priority'] - (int) $b['priority']; }); diff --git a/Model/SfProfilerMessage.php b/Model/SfProfilerMessage.php index 078a29a2..e5c597ed 100644 --- a/Model/SfProfilerMessage.php +++ b/Model/SfProfilerMessage.php @@ -123,7 +123,7 @@ public function convertToMessage(): MessageInterface if ($this->hasParameters()) { // Reduce to only get one value of each parameter, not all the usages. - $meta['parameters'] = \array_reduce($this->getParameters(), 'array_merge', []); + $meta['parameters'] = array_reduce($this->getParameters(), 'array_merge', []); } if (!empty($this->getCount())) { diff --git a/Service/CacheClearer.php b/Service/CacheClearer.php index 9b5b44ef..869ad637 100644 --- a/Service/CacheClearer.php +++ b/Service/CacheClearer.php @@ -60,7 +60,7 @@ public function __construct(string $kernelCacheDir, $translator, Filesystem $fil */ public function clearAndWarmUp(?string $locale = null): void { - $translationDir = \sprintf('%s/translations', $this->kernelCacheDir); + $translationDir = sprintf('%s/translations', $this->kernelCacheDir); $finder = new Finder(); diff --git a/Service/ConfigurationManager.php b/Service/ConfigurationManager.php index c4b22386..5a689461 100644 --- a/Service/ConfigurationManager.php +++ b/Service/ConfigurationManager.php @@ -50,7 +50,7 @@ public function getConfiguration($name = null): Configuration } } - throw new \InvalidArgumentException(\sprintf('No configuration found for "%s"', $name)); + throw new \InvalidArgumentException(sprintf('No configuration found for "%s"', $name)); } public function getFirstName(): ?string @@ -64,6 +64,6 @@ public function getFirstName(): ?string public function getNames(): array { - return \array_keys($this->configuration); + return array_keys($this->configuration); } } diff --git a/Service/Importer.php b/Service/Importer.php index 3fb8677b..146add31 100644 --- a/Service/Importer.php +++ b/Service/Importer.php @@ -136,7 +136,7 @@ private function convertSourceLocationsToMessages(MessageCatalogue $catalogue, S $trimLength = 1 + \strlen($this->config['project_root']); $meta = $this->getMetadata($catalogue, $key, $domain); - $meta->addCategory('file-source', \sprintf('%s:%s', \substr($sourceLocation->getPath(), $trimLength), $sourceLocation->getLine())); + $meta->addCategory('file-source', sprintf('%s:%s', substr($sourceLocation->getPath(), $trimLength), $sourceLocation->getLine())); if (isset($sourceLocation->getContext()['desc'])) { $meta->addCategory('desc', $sourceLocation->getContext()['desc']); } @@ -180,7 +180,7 @@ private function processConfig(array $config): void 'whitelist_domains' => [], ]; - $config = \array_merge($default, $config); + $config = array_merge($default, $config); if (!empty($config['blacklist_domains']) && !empty($config['whitelist_domains'])) { throw new \InvalidArgumentException('Cannot use "blacklist_domains" and "whitelist_domains" at the same time'); diff --git a/Service/StorageManager.php b/Service/StorageManager.php index 77d6d5f8..b53eba6c 100644 --- a/Service/StorageManager.php +++ b/Service/StorageManager.php @@ -62,6 +62,6 @@ public function getFirstName(): ?string public function getNames(): array { - return \array_keys($this->storages); + return array_keys($this->storages); } } diff --git a/Service/StorageService.php b/Service/StorageService.php index 2442ae3c..3dfc1dd3 100644 --- a/Service/StorageService.php +++ b/Service/StorageService.php @@ -27,9 +27,9 @@ */ final class StorageService implements Storage { - const DIRECTION_UP = 'up'; + public const DIRECTION_UP = 'up'; - const DIRECTION_DOWN = 'down'; + public const DIRECTION_DOWN = 'down'; /** * @var Storage[] @@ -87,7 +87,7 @@ public function sync(string $direction = self::DIRECTION_DOWN, array $importOpti break; default: - throw new LogicException(\sprintf('Direction must be either "up" or "down". Value "%s" was provided', $direction)); + throw new LogicException(sprintf('Direction must be either "up" or "down". Value "%s" was provided', $direction)); } } diff --git a/Tests/Functional/Catalogue/CatalogueFetcherTest.php b/Tests/Functional/Catalogue/CatalogueFetcherTest.php index eb6034c7..2dcaf816 100644 --- a/Tests/Functional/Catalogue/CatalogueFetcherTest.php +++ b/Tests/Functional/Catalogue/CatalogueFetcherTest.php @@ -25,7 +25,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - \file_put_contents( + file_put_contents( __DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' diff --git a/Tests/Functional/Command/CheckMissingCommandTest.php b/Tests/Functional/Command/CheckMissingCommandTest.php index f64dfbc9..d957f8de 100644 --- a/Tests/Functional/Command/CheckMissingCommandTest.php +++ b/Tests/Functional/Command/CheckMissingCommandTest.php @@ -23,7 +23,7 @@ protected function setUp(): void $this->bootKernel(); $this->application = new Application($this->kernel); - \file_put_contents( + file_put_contents( __DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' @@ -93,7 +93,7 @@ public function testReportsEmptyTranslationMessages(): void public function testReportsNoNewTranslationMessages(): void { - \file_put_contents( + file_put_contents( __DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' diff --git a/Tests/Functional/Command/ExtractCommandTest.php b/Tests/Functional/Command/ExtractCommandTest.php index 1556b849..ff7a9915 100644 --- a/Tests/Functional/Command/ExtractCommandTest.php +++ b/Tests/Functional/Command/ExtractCommandTest.php @@ -27,7 +27,7 @@ protected function setUp(): void parent::setUp(); $this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yaml'); - \file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' + file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' @@ -75,7 +75,7 @@ public function testExecute(): void // transchoice tag have been definively removed in sf ^5.0 // Remove this condition & views_with_transchoice + associated config once sf ^5.0 is the minimum supported version. - if (\version_compare(Kernel::VERSION, 5.0, '<')) { + if (version_compare(Kernel::VERSION, 5.0, '<')) { $configuration = 'app_with_transchoice'; } else { $configuration = 'app'; diff --git a/Tests/Functional/Command/StatusCommandTest.php b/Tests/Functional/Command/StatusCommandTest.php index 2633fb8c..680f65f2 100644 --- a/Tests/Functional/Command/StatusCommandTest.php +++ b/Tests/Functional/Command/StatusCommandTest.php @@ -43,7 +43,7 @@ public function testExecute(): void // the output of the command in the console $output = $commandTester->getDisplay(); - $data = \json_decode($output, true); + $data = json_decode($output, true); $this->assertArrayHasKey('en', $data); $this->assertArrayHasKey('messages', $data['en']); diff --git a/Tests/Functional/Command/SyncCommandTest.php b/Tests/Functional/Command/SyncCommandTest.php index d758cbf0..72154d77 100644 --- a/Tests/Functional/Command/SyncCommandTest.php +++ b/Tests/Functional/Command/SyncCommandTest.php @@ -23,7 +23,7 @@ protected function setUp(): void parent::setUp(); $this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yaml'); - \file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' + file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' diff --git a/Tests/Functional/Controller/EditInPlaceControllerTest.php b/Tests/Functional/Controller/EditInPlaceControllerTest.php index c7d9290a..c2aa72c3 100644 --- a/Tests/Functional/Controller/EditInPlaceControllerTest.php +++ b/Tests/Functional/Controller/EditInPlaceControllerTest.php @@ -23,7 +23,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - \file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' + file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' @@ -54,7 +54,7 @@ protected function setUp(): void public function testEditAction(): void { - $request = Request::create('/admin/_trans_edit_in_place/app/sv', 'POST', [], [], [], [], \json_encode([ + $request = Request::create('/admin/_trans_edit_in_place/app/sv', 'POST', [], [], [], [], json_encode([ 'messages|key0' => 'trans0', 'messages|key1' => 'trans1', ])); @@ -64,7 +64,7 @@ public function testEditAction(): void public function testEditActionError(): void { - $request = Request::create('/admin/_trans_edit_in_place/app/sv', 'POST', [], [], [], [], \json_encode([ + $request = Request::create('/admin/_trans_edit_in_place/app/sv', 'POST', [], [], [], [], json_encode([ 'messages|key0' => 'trans0', 'messages|' => 'trans1', ])); diff --git a/Tests/Functional/Controller/EditInPlaceTest.php b/Tests/Functional/Controller/EditInPlaceTest.php index 924c8bfd..5564a9da 100644 --- a/Tests/Functional/Controller/EditInPlaceTest.php +++ b/Tests/Functional/Controller/EditInPlaceTest.php @@ -34,7 +34,7 @@ public function testActivatedTest(): void self::assertStringContainsString('', $response->getContent()); $dom = new \DOMDocument('1.0', 'utf-8'); - @$dom->loadHTML(\mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); + @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); $xpath = new \DomXpath($dom); // Check number of x-trans tags @@ -66,7 +66,7 @@ public function testIfUntranslatableLabelGetsDisabled(): void self::assertStringContainsString('', $response->getContent()); $dom = new \DOMDocument('1.0', 'utf-8'); - @$dom->loadHTML(\mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); + @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); $xpath = new \DomXpath($dom); // Check number of x-trans tags diff --git a/Tests/Functional/Controller/WebUIControllerTest.php b/Tests/Functional/Controller/WebUIControllerTest.php index 94838143..d8b31915 100644 --- a/Tests/Functional/Controller/WebUIControllerTest.php +++ b/Tests/Functional/Controller/WebUIControllerTest.php @@ -20,7 +20,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - \file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' + file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' @@ -69,13 +69,13 @@ public function testShowAction(): void public function testCreateAction(): void { - $request = Request::create('/_trans/app/sv/messages/new', 'POST', [], [], [], [], \json_encode([ + $request = Request::create('/_trans/app/sv/messages/new', 'POST', [], [], [], [], json_encode([ 'key' => 'foo', ])); $response = $this->kernel->handle($request); $this->assertEquals(400, $response->getStatusCode()); - $request = Request::create('/_trans/app/sv/messages/new', 'POST', [], [], [], [], \json_encode([ + $request = Request::create('/_trans/app/sv/messages/new', 'POST', [], [], [], [], json_encode([ 'key' => 'foo', 'message' => 'bar', ])); @@ -85,13 +85,13 @@ public function testCreateAction(): void public function testEditAction(): void { - $request = Request::create('/_trans/app/sv/messages', 'POST', [], [], [], [], \json_encode([ + $request = Request::create('/_trans/app/sv/messages', 'POST', [], [], [], [], json_encode([ 'key' => 'foo', ])); $response = $this->kernel->handle($request); $this->assertEquals(400, $response->getStatusCode()); - $request = Request::create('/_trans/app/sv/messages', 'POST', [], [], [], [], \json_encode([ + $request = Request::create('/_trans/app/sv/messages', 'POST', [], [], [], [], json_encode([ 'key' => 'key1', 'message' => 'bar', ])); @@ -102,13 +102,13 @@ public function testEditAction(): void public function testDeleteAction(): void { // Removing something that does not exists is okey. - $request = Request::create('/_trans/app/sv/messages', 'DELETE', [], [], [], [], \json_encode([ + $request = Request::create('/_trans/app/sv/messages', 'DELETE', [], [], [], [], json_encode([ 'key' => 'empty', ])); $response = $this->kernel->handle($request); $this->assertEquals(200, $response->getStatusCode()); - $request = Request::create('/_trans/app/sv/messages', 'DELETE', [], [], [], [], \json_encode([ + $request = Request::create('/_trans/app/sv/messages', 'DELETE', [], [], [], [], json_encode([ 'key' => 'foo', ])); $response = $this->kernel->handle($request); diff --git a/Tests/Unit/Catalogue/CatalogueManagerTest.php b/Tests/Unit/Catalogue/CatalogueManagerTest.php index bd856fd8..e2de8022 100644 --- a/Tests/Unit/Catalogue/CatalogueManagerTest.php +++ b/Tests/Unit/Catalogue/CatalogueManagerTest.php @@ -60,12 +60,12 @@ public function testFindMessages(): void // Only one approved en message $messages = $manager->findMessages(['locale' => 'en', 'isApproved' => true]); $this->assertCount(1, $messages); - $messages = \array_values($messages); + $messages = array_values($messages); $this->assertEquals('d', $messages[0]->getKey()); $messages = $manager->findMessages(['isApproved' => true]); $this->assertCount(3, $messages); - $keys = \array_map(function (CatalogueMessage $message) { + $keys = array_map(function (CatalogueMessage $message) { return $message->getKey(); }, $messages); $this->assertContains('c', $keys); @@ -74,12 +74,12 @@ public function testFindMessages(): void $messages = $manager->findMessages(['isNew' => true]); $this->assertCount(1, $messages); - $messages = \array_values($messages); + $messages = array_values($messages); $this->assertEquals('a', $messages[0]->getKey()); $messages = $manager->findMessages(['isObsolete' => true]); $this->assertCount(1, $messages); - $messages = \array_values($messages); + $messages = array_values($messages); $this->assertEquals('b', $messages[0]->getKey()); } } diff --git a/Tests/Unit/Model/ConfigurationTest.php b/Tests/Unit/Model/ConfigurationTest.php index 922cb156..7160b491 100644 --- a/Tests/Unit/Model/ConfigurationTest.php +++ b/Tests/Unit/Model/ConfigurationTest.php @@ -24,7 +24,7 @@ public function testAccessors(): void foreach ($key2Function as $key => $value) { $func = $value; if (\is_array($func)) { - $func = \reset($func); + $func = reset($func); } $this->assertEquals($value, $conf->$func()); } diff --git a/Tests/Unit/Service/ConfigurationManagerTest.php b/Tests/Unit/Service/ConfigurationManagerTest.php index d553e98b..0ea8d158 100644 --- a/Tests/Unit/Service/ConfigurationManagerTest.php +++ b/Tests/Unit/Service/ConfigurationManagerTest.php @@ -96,6 +96,6 @@ private function createConfiguration(array $data = []): Configuration { $default = ConfigurationTest::getDefaultData(); - return new Configuration(\array_merge($default, $data)); + return new Configuration(array_merge($default, $data)); } } diff --git a/Tests/Unit/Translator/EditInPlaceTranslatorTest.php b/Tests/Unit/Translator/EditInPlaceTranslatorTest.php index 4c77f46a..bc21d399 100644 --- a/Tests/Unit/Translator/EditInPlaceTranslatorTest.php +++ b/Tests/Unit/Translator/EditInPlaceTranslatorTest.php @@ -27,7 +27,7 @@ final class EditInPlaceTranslatorTest extends TestCase { public function testWithNotLocaleAwareTranslator() { - if (!\interface_exists(NewTranslatorInterface::class)) { + if (!interface_exists(NewTranslatorInterface::class)) { $this->markTestSkipped('Relevant only when NewTranslatorInterface is available.'); } diff --git a/Tests/Unit/Translator/FallbackTranslatorTest.php b/Tests/Unit/Translator/FallbackTranslatorTest.php index 2620c3a7..bafd6521 100644 --- a/Tests/Unit/Translator/FallbackTranslatorTest.php +++ b/Tests/Unit/Translator/FallbackTranslatorTest.php @@ -26,7 +26,7 @@ final class FallbackTranslatorTest extends TestCase { public function testWithNotLocaleAwareTranslator() { - if (!\interface_exists(NewTranslatorInterface::class)) { + if (!interface_exists(NewTranslatorInterface::class)) { $this->markTestSkipped('Relevant only when NewTranslatorInterface is available.'); } diff --git a/Tests/Unit/Twig/BaseTwigTestCase.php b/Tests/Unit/Twig/BaseTwigTestCase.php index f404a6d0..4467708e 100644 --- a/Tests/Unit/Twig/BaseTwigTestCase.php +++ b/Tests/Unit/Twig/BaseTwigTestCase.php @@ -26,9 +26,9 @@ abstract class BaseTwigTestCase extends TestCase { final protected function parse(string $file, bool $debug = false): string { - $content = \file_get_contents(__DIR__.'/Fixture/'.$file); + $content = file_get_contents(__DIR__.'/Fixture/'.$file); - $loader = \class_exists(ArrayLoader::class) + $loader = class_exists(ArrayLoader::class) ? new ArrayLoader() : new \Twig_Loader_Array([]); $env = new Environment($loader); diff --git a/Tests/Unit/Twig/RemovingNodeVisitorTest.php b/Tests/Unit/Twig/RemovingNodeVisitorTest.php index 818e6515..7c5fc5d7 100644 --- a/Tests/Unit/Twig/RemovingNodeVisitorTest.php +++ b/Tests/Unit/Twig/RemovingNodeVisitorTest.php @@ -22,7 +22,7 @@ public function testRemovalWithSimpleTemplate(): void { // transchoice tag have been definively removed in sf ^5.0 // Remove this condition & *with_transchoice templates once sf ^5.0 is the minimum supported version. - if (\version_compare(Kernel::VERSION, 5.0, '<')) { + if (version_compare(Kernel::VERSION, 5.0, '<')) { $expected = $this->parse('simple_template_compiled_with_transchoice.html.twig'); $actual = $this->parse('simple_template_with_transchoice.html.twig'); } else { diff --git a/Translator/EditInPlaceTranslator.php b/Translator/EditInPlaceTranslator.php index f2966af3..c1c2a464 100644 --- a/Translator/EditInPlaceTranslator.php +++ b/Translator/EditInPlaceTranslator.php @@ -91,11 +91,11 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul } // Render all data in the translation tag required to allow in-line translation - return \sprintf('%s', + return sprintf('%s', $domain, $id, - \htmlspecialchars($original), - \htmlspecialchars($plain), + htmlspecialchars($original), + htmlspecialchars($plain), $domain, $locale, $original @@ -112,7 +112,7 @@ public function transChoice($id, $number, array $parameters = [], $domain = null return $this->translator->transChoice($id, $number, $parameters, $domain, $locale); } - $parameters = \array_merge([ + $parameters = array_merge([ '%count%' => $number, ], $parameters); diff --git a/Translator/FallbackTranslator.php b/Translator/FallbackTranslator.php index 9b53a74f..fdd23136 100644 --- a/Translator/FallbackTranslator.php +++ b/Translator/FallbackTranslator.php @@ -154,10 +154,10 @@ private function translateWithSubstitutedParameters(string $orgString, string $l // Replace parameters $replacements = []; foreach ($parameters as $placeholder => $nonTranslatableValue) { - $replacements[(string) $nonTranslatableValue] = \sha1($placeholder); + $replacements[(string) $nonTranslatableValue] = sha1($placeholder); } - $replacedString = \str_replace(\array_keys($replacements), \array_values($replacements), $orgString); + $replacedString = str_replace(array_keys($replacements), array_values($replacements), $orgString); $translatedString = $this->externalTranslator->translate($replacedString, $this->defaultLocale, $locale); if (null === $translatedString) { @@ -165,6 +165,6 @@ private function translateWithSubstitutedParameters(string $orgString, string $l return $orgString; } - return \str_replace(\array_values($replacements), \array_keys($replacements), $translatedString); + return str_replace(array_values($replacements), array_keys($replacements), $translatedString); } } diff --git a/Translator/TranslatorInterface.php b/Translator/TranslatorInterface.php index e9bbdfd7..5b98dedb 100644 --- a/Translator/TranslatorInterface.php +++ b/Translator/TranslatorInterface.php @@ -24,7 +24,7 @@ * When sf 3.4 won't be supported anymore, this interface will become useless. */ -if (\interface_exists(NewTranslatorInterface::class)) { +if (interface_exists(NewTranslatorInterface::class)) { interface TranslatorInterface extends NewTranslatorInterface, LocaleAwareInterface, TranslatorBagInterface { } diff --git a/Twig/Node/Transchoice.php b/Twig/Node/Transchoice.php index d1e67753..1212a94d 100644 --- a/Twig/Node/Transchoice.php +++ b/Twig/Node/Transchoice.php @@ -25,7 +25,7 @@ public function __construct(ArrayExpression $arguments, $lineno) public function compile(Compiler $compiler): void { $compiler->raw( - \sprintf( + sprintf( '$this->env->getExtension(\'%s\')->%s(', 'Translation\Bundle\Twig\TranslationExtension', 'transchoiceWithDefault' diff --git a/Twig/TranslationExtension.php b/Twig/TranslationExtension.php index 0cfc97ac..cf039b13 100644 --- a/Twig/TranslationExtension.php +++ b/Twig/TranslationExtension.php @@ -78,10 +78,10 @@ public function transchoiceWithDefault(string $message, string $defaultMessage, } if (false === $this->translator->getCatalogue($locale)->defines($message, $domain)) { - return $this->translator->transChoice($defaultMessage, $count, \array_merge(['%count%' => $count], $arguments), $domain, $locale); + return $this->translator->transChoice($defaultMessage, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale); } - return $this->translator->transChoice($message, $count, \array_merge(['%count%' => $count], $arguments), $domain, $locale); + return $this->translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale); } /** From 25589875a3d5c7d67893f6d0eb8ad37ac9519bc4 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 9 Feb 2022 22:36:50 +0200 Subject: [PATCH 7/8] Fix missing: DomXpath -> DOMXPath --- Tests/Functional/Controller/EditInPlaceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Functional/Controller/EditInPlaceTest.php b/Tests/Functional/Controller/EditInPlaceTest.php index 5564a9da..aaec436d 100644 --- a/Tests/Functional/Controller/EditInPlaceTest.php +++ b/Tests/Functional/Controller/EditInPlaceTest.php @@ -35,7 +35,7 @@ public function testActivatedTest(): void $dom = new \DOMDocument('1.0', 'utf-8'); @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); - $xpath = new \DomXpath($dom); + $xpath = new \DOMXPath($dom); // Check number of x-trans tags $xtrans = $xpath->query('//x-trans'); @@ -67,7 +67,7 @@ public function testIfUntranslatableLabelGetsDisabled(): void $dom = new \DOMDocument('1.0', 'utf-8'); @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); - $xpath = new \DomXpath($dom); + $xpath = new \DOMXPath($dom); // Check number of x-trans tags $xtrans = $xpath->query('//x-trans'); From cc272adaa6c06c3d15a610740ba213d0c4107a6b Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Mon, 14 Feb 2022 13:43:29 +0200 Subject: [PATCH 8/8] Fix some code styles after master rebase --- Translator/EditInPlaceTranslator.php | 4 ++-- Translator/FallbackTranslator.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Translator/EditInPlaceTranslator.php b/Translator/EditInPlaceTranslator.php index 2b696966..5c2c1dd8 100644 --- a/Translator/EditInPlaceTranslator.php +++ b/Translator/EditInPlaceTranslator.php @@ -75,8 +75,8 @@ public function getCatalogue($locale = null): MessageCatalogueInterface */ public function getCatalogues(): array { - if (!\method_exists($this->translator, 'getCatalogues')) { - throw new \Exception(\sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__)); + if (!method_exists($this->translator, 'getCatalogues')) { + throw new \Exception(sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__)); } return $this->translator->getCatalogues(); diff --git a/Translator/FallbackTranslator.php b/Translator/FallbackTranslator.php index 243abd2a..f49222c2 100644 --- a/Translator/FallbackTranslator.php +++ b/Translator/FallbackTranslator.php @@ -139,8 +139,8 @@ public function getCatalogue($locale = null): MessageCatalogueInterface public function getCatalogues(): array { - if (!\method_exists($this->symfonyTranslator, 'getCatalogues')) { - throw new \Exception(\sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__)); + if (!method_exists($this->symfonyTranslator, 'getCatalogues')) { + throw new \Exception(sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__)); } return $this->symfonyTranslator->getCatalogues();