From 3fade8af15b065970f5bcbf452e387423627853a Mon Sep 17 00:00:00 2001 From: Alexis Urien Date: Tue, 4 Jul 2023 20:03:03 -0700 Subject: [PATCH 1/4] - Remove symfony console $defaultName deprecation and use AsCommand Annotation - Upgrade to PHP ^8.0 - Upgrade to symfony ^5.3 --- Command/CheckMissingCommand.php | 7 ++++--- Command/DeleteEmptyCommand.php | 7 ++++--- Command/DeleteObsoleteCommand.php | 7 ++++--- Command/DownloadCommand.php | 9 +++++---- Command/ExtractCommand.php | 7 ++++--- Command/StatusCommand.php | 7 ++++--- Command/SyncCommand.php | 9 +++++---- composer.json | 24 ++++++++++++------------ 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Command/CheckMissingCommand.php b/Command/CheckMissingCommand.php index 58a6ac4..be95e47 100644 --- a/Command/CheckMissingCommand.php +++ b/Command/CheckMissingCommand.php @@ -4,6 +4,7 @@ namespace Translation\Bundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -17,10 +18,11 @@ use Translation\Bundle\Service\ConfigurationManager; use Translation\Bundle\Service\Importer; +#[AsCommand( + name: 'translation:check-missing' +)] final class CheckMissingCommand extends Command { - protected static $defaultName = 'translation:check-missing'; - /** * @var ConfigurationManager */ @@ -58,7 +60,6 @@ public function __construct( protected function configure(): void { $this - ->setName(self::$defaultName) ->setDescription('Check that all translations for a given locale are extracted.') ->addArgument('locale', InputArgument::REQUIRED, 'The locale to check') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default'); diff --git a/Command/DeleteEmptyCommand.php b/Command/DeleteEmptyCommand.php index 3c40a99..75f290c 100644 --- a/Command/DeleteEmptyCommand.php +++ b/Command/DeleteEmptyCommand.php @@ -11,6 +11,7 @@ namespace Translation\Bundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; @@ -26,13 +27,14 @@ /** * @author Tobias Nyholm */ +#[AsCommand( + name: 'translation:delete-empty' +)] class DeleteEmptyCommand extends Command { use BundleTrait; use StorageTrait; - protected static $defaultName = 'translation:delete-empty'; - /** * @var ConfigurationManager */ @@ -64,7 +66,6 @@ public function __construct( protected function configure(): void { $this - ->setName(self::$defaultName) ->setDescription('Delete all translations currently empty.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', null) diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index 1132559..74a04f7 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -11,6 +11,7 @@ namespace Translation\Bundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; @@ -26,13 +27,14 @@ /** * @author Tobias Nyholm */ +#[AsCommand( + name: 'translation:delete-obsolete' +)] class DeleteObsoleteCommand extends Command { use BundleTrait; use StorageTrait; - protected static $defaultName = 'translation:delete-obsolete'; - /** * @var ConfigurationManager */ @@ -64,7 +66,6 @@ public function __construct( protected function configure(): void { $this - ->setName(self::$defaultName) ->setDescription('Delete all translations marked as obsolete.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', null) diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index d877afa..f36d053 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -11,6 +11,7 @@ namespace Translation\Bundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -26,13 +27,14 @@ /** * @author Tobias Nyholm */ +#[AsCommand( + name: 'translation:download' +)] class DownloadCommand extends Command { use BundleTrait; use StorageTrait; - protected static $defaultName = 'translation:download'; - private $configurationManager; private $cacheCleaner; private $catalogueWriter; @@ -54,7 +56,6 @@ public function __construct( protected function configure(): void { $this - ->setName(self::$defaultName) ->setDescription('Replace local messages with messages from remote') ->setHelp(<<%command.name% will erase all your local translations and replace them with translations downloaded from the remote. @@ -138,7 +139,7 @@ public function cleanParameters(array $raw) foreach ($raw as $string) { // Assert $string looks like "foo:bar" - list($key, $value) = explode(':', $string, 2); + [$key, $value] = explode(':', $string, 2); $config[$key][] = $value; } diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index f61290d..488b58f 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -11,6 +11,7 @@ namespace Translation\Bundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -29,12 +30,13 @@ /** * @author Tobias Nyholm */ +#[AsCommand( + name: 'translation:extract' +)] class ExtractCommand extends Command { use BundleTrait; - protected static $defaultName = 'translation:extract'; - /** * @var CatalogueFetcher */ @@ -79,7 +81,6 @@ public function __construct( protected function configure(): void { $this - ->setName(self::$defaultName) ->setDescription('Extract translations from source code.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', false) diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 73e21fa..4c1a2bd 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -11,6 +11,7 @@ namespace Translation\Bundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -24,12 +25,13 @@ /** * @author Tobias Nyholm */ +#[AsCommand( + name: 'translation:status' +)] class StatusCommand extends Command { use BundleTrait; - protected static $defaultName = 'translation:status'; - /** * @var CatalogueCounter */ @@ -60,7 +62,6 @@ public function __construct( protected function configure(): void { $this - ->setName(self::$defaultName) ->setDescription('Show status about your translations.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', false) diff --git a/Command/SyncCommand.php b/Command/SyncCommand.php index 859872f..3da5af3 100644 --- a/Command/SyncCommand.php +++ b/Command/SyncCommand.php @@ -11,6 +11,7 @@ namespace Translation\Bundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -22,12 +23,13 @@ /** * @author Tobias Nyholm */ +#[AsCommand( + name: 'translation:sync' +)] class SyncCommand extends Command { use StorageTrait; - protected static $defaultName = 'translation:sync'; - public function __construct(StorageManager $storageManager) { $this->storageManager = $storageManager; @@ -38,7 +40,6 @@ public function __construct(StorageManager $storageManager) protected function configure(): void { $this - ->setName(self::$defaultName) ->setDescription('Sync the translations with the remote storage') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('direction', InputArgument::OPTIONAL, 'Use "down" if local changes should be overwritten, otherwise "up"', 'down') @@ -78,7 +79,7 @@ public function cleanParameters(array $raw) foreach ($raw as $string) { // Assert $string looks like "foo:bar" - list($key, $value) = explode(':', $string, 2); + [$key, $value] = explode(':', $string, 2); $config[$key][] = $value; } diff --git a/composer.json b/composer.json index 3041ebd..5cd088c 100644 --- a/composer.json +++ b/composer.json @@ -10,19 +10,20 @@ } ], "require": { - "php": "^7.2 || ^8.0", - "symfony/framework-bundle": "^4.4.20 || ^5.2.5 || ^6.0", - "symfony/validator": "^4.4.20 || ^5.2.5 || ^6.0", - "symfony/translation": "^4.4.20 || ^5.2.5 || ^6.0", - "symfony/twig-bundle": "^4.4.20 || ^5.2.4 || ^6.0", - "symfony/finder": "^4.4.20 || ^5.2.4 || ^6.0", - "symfony/intl": "^4.4.20 || ^5.2.4 || ^6.0", + "php": "^8.0", + "symfony/framework-bundle": "^5.3 || ^6.0", + "symfony/validator": "^5.3 || ^6.0", + "symfony/translation": "^5.3 || ^6.0", + "symfony/twig-bundle": "^5.3 || ^6.0", + "symfony/finder": "^5.3 || ^6.0", + "symfony/intl": "^5.3 || ^6.0", + "symfony/console": "^5.3 || ^6.0", "php-translation/symfony-storage": "^2.1", "php-translation/extractor": "^2.0", "nyholm/nsa": "^1.1", "twig/twig": "^2.14.4 || ^3.3", - "symfony/asset": "^4.4.20 || ^5.2.4 || ^6.0" + "symfony/asset": "^5.3 || ^6.0" }, "require-dev": { "symfony/phpunit-bridge": "^5.2 || ^6.0", @@ -31,10 +32,9 @@ "php-http/curl-client": "^1.7 || ^2.0", "php-http/message": "^1.11", "php-http/message-factory": "^1.0.2", - "symfony/console": "^4.4.20 || ^5.2.5 || ^6.0", - "symfony/twig-bridge": "^4.4.20 || ^5.2.5 || ^6.0", - "symfony/dependency-injection": "^4.4.20 || ^5.2.5 || ^6.0", - "symfony/web-profiler-bundle": "^4.4.20 || ^5.2.4 || ^6.0", + "symfony/twig-bridge": "^5.3 || ^6.0", + "symfony/dependency-injection": "^5.3 || ^6.0", + "symfony/web-profiler-bundle": "^5.3 || ^6.0", "matthiasnoback/symfony-dependency-injection-test": "^4.1", "matthiasnoback/symfony-config-test": "^4.1", "nyholm/psr7": "^1.1", From e9794fbb4e4ede399b7d9d07edf90610fa3e57fd Mon Sep 17 00:00:00 2001 From: Alexis Urien Date: Tue, 4 Jul 2023 20:09:52 -0700 Subject: [PATCH 2/4] Fix CI for PHP 8.0+ --- .github/workflows/ci.yml | 6 ++---- .github/workflows/static.yml | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10f239e..c2e6d19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,14 +10,12 @@ jobs: strategy: fail-fast: false matrix: - php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ] + php: ['8.0', '8.1' '8.2'] strategy: [ 'highest' ] sf_version: [''] include: - - php: 7.4 + - php: 8.0 strategy: 'lowest' - - php: 7.3 - sf_version: '4.*' steps: - name: Checkout code diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index b4b5d41..d5d853a 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -22,7 +22,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.0' coverage: none - name: Download dependencies @@ -63,7 +63,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.0' coverage: none - name: Download dependencies From 727ca75584cf5edef338126811ab28e7df1fbce9 Mon Sep 17 00:00:00 2001 From: Alexis Urien Date: Wed, 5 Jul 2023 11:51:01 -0700 Subject: [PATCH 3/4] Apply existing php-cs rules with php8+ --- Catalogue/CatalogueManager.php | 12 ++++++------ Catalogue/Operation/ReplaceOperation.php | 4 ++-- Command/BundleTrait.php | 2 +- Controller/WebUIController.php | 2 +- DependencyInjection/Configuration.php | 3 --- DependencyInjection/TranslationExtension.php | 9 --------- EditInPlace/Activator.php | 5 +---- Service/CacheClearer.php | 2 +- Service/Importer.php | 8 ++++---- Translator/FallbackTranslator.php | 15 --------------- Twig/EditInPlaceExtension.php | 6 ------ Twig/TranslationExtension.php | 12 +----------- 12 files changed, 17 insertions(+), 63 deletions(-) diff --git a/Catalogue/CatalogueManager.php b/Catalogue/CatalogueManager.php index 5d554c0..09a50d5 100644 --- a/Catalogue/CatalogueManager.php +++ b/Catalogue/CatalogueManager.php @@ -67,12 +67,12 @@ public function getMessages(string $locale, string $domain): array /** * @param array $config { * - * @var string $domain - * @var string $locale - * @var bool $isNew - * @var bool $isObsolete - * @var bool $isApproved - * } + * @var string $domain + * @var string $locale + * @var bool $isNew + * @var bool $isObsolete + * @var bool $isApproved + * } * * @return CatalogueMessage[] */ diff --git a/Catalogue/Operation/ReplaceOperation.php b/Catalogue/Operation/ReplaceOperation.php index 746a686..5b012e5 100644 --- a/Catalogue/Operation/ReplaceOperation.php +++ b/Catalogue/Operation/ReplaceOperation.php @@ -150,12 +150,12 @@ private function doMergeMetadata(array $source, array $target): array // If both arrays, do recursive call $source[$key] = $this->doMergeMetadata($source[$key], $value); } - // Else, use value form $source + // Else, use value form $source } else { // Add new value $source[$key] = $value; } - // if sequential + // if sequential } elseif (!\in_array($value, $source, true)) { $source[] = $value; } diff --git a/Command/BundleTrait.php b/Command/BundleTrait.php index cf8af0c..c2ec27f 100644 --- a/Command/BundleTrait.php +++ b/Command/BundleTrait.php @@ -20,7 +20,7 @@ trait BundleTrait private function configureBundleDirs(InputInterface $input, Configuration $config): void { if ($bundleName = $input->getOption('bundle')) { - if (0 === strpos($bundleName, '@')) { + if (str_starts_with($bundleName, '@')) { if (false === $pos = strpos($bundleName, '/')) { $bundleName = substr($bundleName, 1); } else { diff --git a/Controller/WebUIController.php b/Controller/WebUIController.php index 2ce6de0..0604ba2 100644 --- a/Controller/WebUIController.php +++ b/Controller/WebUIController.php @@ -76,7 +76,7 @@ public function __construct( /** * Show a dashboard for the configuration. */ - public function indexAction(?string $configName = null): Response + public function indexAction(string $configName = null): Response { if (!$this->isWebUIEnabled) { return new Response('You are not allowed here. Check your config.', Response::HTTP_BAD_REQUEST); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0de8fd2..95be8ca 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -29,9 +29,6 @@ public function __construct(ContainerBuilder $container) $this->container = $container; } - /** - * {@inheritdoc} - */ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('translation'); diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 2442486..2f1b177 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -37,9 +37,6 @@ */ class TranslationExtension extends Extension { - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container): void { $container->setParameter('extractor_vendor_dir', $this->getExtractorVendorDirectory()); @@ -224,17 +221,11 @@ private function enableFallbackAutoTranslator(ContainerBuilder $container, array $container->setParameter('php_translation.translator_service.api_key', $config['fallback_translation']['api_key']); } - /** - * {@inheritdoc} - */ public function getAlias(): string { return 'translation'; } - /** - * {@inheritdoc} - */ public function getConfiguration(array $config, ContainerBuilder $container): Configuration { return new Configuration($container); diff --git a/EditInPlace/Activator.php b/EditInPlace/Activator.php index 19fbc47..b5c3858 100644 --- a/EditInPlace/Activator.php +++ b/EditInPlace/Activator.php @@ -32,7 +32,7 @@ final class Activator implements ActivatorInterface /** * @var Session|null */ - private $session = null; + private $session; public function __construct(RequestStack $requestStack) { @@ -81,9 +81,6 @@ public function deactivate(): void } } - /** - * {@inheritdoc} - */ public function checkRequest(Request $request = null): bool { if (null === $this->getSession() || !$this->getSession()->has(self::KEY)) { diff --git a/Service/CacheClearer.php b/Service/CacheClearer.php index 869ad63..6273a84 100644 --- a/Service/CacheClearer.php +++ b/Service/CacheClearer.php @@ -58,7 +58,7 @@ public function __construct(string $kernelCacheDir, $translator, Filesystem $fil * * @param string|null $locale optional filter to clear only one locale */ - public function clearAndWarmUp(?string $locale = null): void + public function clearAndWarmUp(string $locale = null): void { $translationDir = sprintf('%s/translations', $this->kernelCacheDir); diff --git a/Service/Importer.php b/Service/Importer.php index 75ca10e..46436d3 100644 --- a/Service/Importer.php +++ b/Service/Importer.php @@ -62,10 +62,10 @@ public function __construct(Extractor $extractor, Environment $twig, string $def * @param MessageCatalogue[] $catalogues * @param array $config { * - * @var array $blacklist_domains Blacklist the domains we should exclude. Cannot be used with whitelist. - * @var array $whitelist_domains Whitelist the domains we should include. Cannot be used with blacklist. - * @var string $project_root The project root will be removed from the source location. - * } + * @var array $blacklist_domains Blacklist the domains we should exclude. Cannot be used with whitelist. + * @var array $whitelist_domains Whitelist the domains we should include. Cannot be used with blacklist. + * @var string $project_root The project root will be removed from the source location. + * } */ public function extractToCatalogues(Finder $finder, array $catalogues, array $config = []): ImportResult { diff --git a/Translator/FallbackTranslator.php b/Translator/FallbackTranslator.php index f49222c..cee1d93 100644 --- a/Translator/FallbackTranslator.php +++ b/Translator/FallbackTranslator.php @@ -61,9 +61,6 @@ public function __construct(string $defaultLocale, $symfonyTranslator, Translato $this->defaultLocale = $defaultLocale; } - /** - * {@inheritdoc} - */ public function trans($id, array $parameters = [], $domain = null, $locale = null): string { $id = (string) $id; @@ -87,9 +84,6 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul return $this->translateWithSubstitutedParameters($orgString, $locale, $parameters); } - /** - * {@inheritdoc} - */ public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null): string { $id = (string) $id; @@ -113,25 +107,16 @@ public function transChoice($id, $number, array $parameters = [], $domain = null return $this->translateWithSubstitutedParameters($orgString, $locale, $parameters); } - /** - * {@inheritdoc} - */ public function setLocale($locale): void { $this->symfonyTranslator->setLocale($locale); } - /** - * {@inheritdoc} - */ public function getLocale(): string { return $this->symfonyTranslator->getLocale(); } - /** - * {@inheritdoc} - */ public function getCatalogue($locale = null): MessageCatalogueInterface { return $this->symfonyTranslator->getCatalogue($locale); diff --git a/Twig/EditInPlaceExtension.php b/Twig/EditInPlaceExtension.php index 9a6ba66..950a533 100644 --- a/Twig/EditInPlaceExtension.php +++ b/Twig/EditInPlaceExtension.php @@ -37,9 +37,6 @@ public function __construct(TranslationExtension $extension, RequestStack $reque $this->activator = $activator; } - /** - * {@inheritdoc} - */ public function getFilters(): array { return [ @@ -58,9 +55,6 @@ public function isSafe($node): array return $this->activator->checkRequest($request) ? ['html'] : []; } - /** - * {@inheritdoc} - */ public function getName(): string { return self::class; diff --git a/Twig/TranslationExtension.php b/Twig/TranslationExtension.php index cf039b1..b97b0f0 100644 --- a/Twig/TranslationExtension.php +++ b/Twig/TranslationExtension.php @@ -71,7 +71,7 @@ public function getNodeVisitors(): array return $visitors; } - public function transchoiceWithDefault(string $message, string $defaultMessage, int $count, array $arguments = [], ?string $domain = null, ?string $locale = null): string + public function transchoiceWithDefault(string $message, string $defaultMessage, int $count, array $arguments = [], string $domain = null, string $locale = null): string { if (null === $domain) { $domain = 'messages'; @@ -84,21 +84,11 @@ public function transchoiceWithDefault(string $message, string $defaultMessage, return $this->translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale); } - /** - * @param mixed $v - * - * @return mixed - */ public function desc($v) { return $v; } - /** - * @param mixed $v - * - * @return mixed - */ public function meaning($v) { return $v; From ab624b91433a4b20446067ea150c4cfeb44f0607 Mon Sep 17 00:00:00 2001 From: Alexis Urien Date: Wed, 5 Jul 2023 11:53:39 -0700 Subject: [PATCH 4/4] Fix CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2e6d19..ba3cef4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.0', '8.1' '8.2'] + php: ['8.0', '8.1', '8.2'] strategy: [ 'highest' ] sf_version: [''] include: