Skip to content

Commit d930db6

Browse files
axiAlexis Urien
andauthored
Remove symfony console $defaultName deprecation (#491)
* - Remove symfony console $defaultName deprecation and use AsCommand Annotation - Upgrade to PHP ^8.0 - Upgrade to symfony ^5.3 * Fix CI for PHP 8.0+ * Apply existing php-cs rules with php8+ * Fix CI --------- Co-authored-by: Alexis Urien <alexis@smiile.com>
1 parent be5558b commit d930db6

22 files changed

+63
-104
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ]
13+
php: ['8.0', '8.1', '8.2']
1414
strategy: [ 'highest' ]
1515
sf_version: ['']
1616
include:
17-
- php: 7.4
17+
- php: 8.0
1818
strategy: 'lowest'
19-
- php: 7.3
20-
sf_version: '4.*'
2119

2220
steps:
2321
- name: Checkout code

.github/workflows/static.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Setup PHP
2323
uses: shivammathur/setup-php@v2
2424
with:
25-
php-version: '7.4'
25+
php-version: '8.0'
2626
coverage: none
2727

2828
- name: Download dependencies
@@ -63,7 +63,7 @@ jobs:
6363
- name: Setup PHP
6464
uses: shivammathur/setup-php@v2
6565
with:
66-
php-version: '7.4'
66+
php-version: '8.0'
6767
coverage: none
6868

6969
- name: Download dependencies

Catalogue/CatalogueManager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public function getMessages(string $locale, string $domain): array
6767
/**
6868
* @param array $config {
6969
*
70-
* @var string $domain
71-
* @var string $locale
72-
* @var bool $isNew
73-
* @var bool $isObsolete
74-
* @var bool $isApproved
75-
* }
70+
* @var string $domain
71+
* @var string $locale
72+
* @var bool $isNew
73+
* @var bool $isObsolete
74+
* @var bool $isApproved
75+
* }
7676
*
7777
* @return CatalogueMessage[]
7878
*/

Catalogue/Operation/ReplaceOperation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ private function doMergeMetadata(array $source, array $target): array
150150
// If both arrays, do recursive call
151151
$source[$key] = $this->doMergeMetadata($source[$key], $value);
152152
}
153-
// Else, use value form $source
153+
// Else, use value form $source
154154
} else {
155155
// Add new value
156156
$source[$key] = $value;
157157
}
158-
// if sequential
158+
// if sequential
159159
} elseif (!\in_array($value, $source, true)) {
160160
$source[] = $value;
161161
}

Command/BundleTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait BundleTrait
2020
private function configureBundleDirs(InputInterface $input, Configuration $config): void
2121
{
2222
if ($bundleName = $input->getOption('bundle')) {
23-
if (0 === strpos($bundleName, '@')) {
23+
if (str_starts_with($bundleName, '@')) {
2424
if (false === $pos = strpos($bundleName, '/')) {
2525
$bundleName = substr($bundleName, 1);
2626
} else {

Command/CheckMissingCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Translation\Bundle\Command;
66

7+
use Symfony\Component\Console\Attribute\AsCommand;
78
use Symfony\Component\Console\Command\Command;
89
use Symfony\Component\Console\Input\InputArgument;
910
use Symfony\Component\Console\Input\InputInterface;
@@ -17,10 +18,11 @@
1718
use Translation\Bundle\Service\ConfigurationManager;
1819
use Translation\Bundle\Service\Importer;
1920

21+
#[AsCommand(
22+
name: 'translation:check-missing'
23+
)]
2024
final class CheckMissingCommand extends Command
2125
{
22-
protected static $defaultName = 'translation:check-missing';
23-
2426
/**
2527
* @var ConfigurationManager
2628
*/
@@ -58,7 +60,6 @@ public function __construct(
5860
protected function configure(): void
5961
{
6062
$this
61-
->setName(self::$defaultName)
6263
->setDescription('Check that all translations for a given locale are extracted.')
6364
->addArgument('locale', InputArgument::REQUIRED, 'The locale to check')
6465
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default');

Command/DeleteEmptyCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Bundle\Command;
1313

14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Helper\ProgressBar;
1617
use Symfony\Component\Console\Input\InputArgument;
@@ -26,13 +27,14 @@
2627
/**
2728
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2829
*/
30+
#[AsCommand(
31+
name: 'translation:delete-empty'
32+
)]
2933
class DeleteEmptyCommand extends Command
3034
{
3135
use BundleTrait;
3236
use StorageTrait;
3337

34-
protected static $defaultName = 'translation:delete-empty';
35-
3638
/**
3739
* @var ConfigurationManager
3840
*/
@@ -64,7 +66,6 @@ public function __construct(
6466
protected function configure(): void
6567
{
6668
$this
67-
->setName(self::$defaultName)
6869
->setDescription('Delete all translations currently empty.')
6970
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
7071
->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', null)

Command/DeleteObsoleteCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Bundle\Command;
1313

14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Helper\ProgressBar;
1617
use Symfony\Component\Console\Input\InputArgument;
@@ -26,13 +27,14 @@
2627
/**
2728
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2829
*/
30+
#[AsCommand(
31+
name: 'translation:delete-obsolete'
32+
)]
2933
class DeleteObsoleteCommand extends Command
3034
{
3135
use BundleTrait;
3236
use StorageTrait;
3337

34-
protected static $defaultName = 'translation:delete-obsolete';
35-
3638
/**
3739
* @var ConfigurationManager
3840
*/
@@ -64,7 +66,6 @@ public function __construct(
6466
protected function configure(): void
6567
{
6668
$this
67-
->setName(self::$defaultName)
6869
->setDescription('Delete all translations marked as obsolete.')
6970
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
7071
->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', null)

Command/DownloadCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Bundle\Command;
1313

14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
@@ -26,13 +27,14 @@
2627
/**
2728
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2829
*/
30+
#[AsCommand(
31+
name: 'translation:download'
32+
)]
2933
class DownloadCommand extends Command
3034
{
3135
use BundleTrait;
3236
use StorageTrait;
3337

34-
protected static $defaultName = 'translation:download';
35-
3638
private $configurationManager;
3739
private $cacheCleaner;
3840
private $catalogueWriter;
@@ -54,7 +56,6 @@ public function __construct(
5456
protected function configure(): void
5557
{
5658
$this
57-
->setName(self::$defaultName)
5859
->setDescription('Replace local messages with messages from remote')
5960
->setHelp(<<<EOT
6061
The <info>%command.name%</info> will erase all your local translations and replace them with translations downloaded from the remote.
@@ -138,7 +139,7 @@ public function cleanParameters(array $raw)
138139

139140
foreach ($raw as $string) {
140141
// Assert $string looks like "foo:bar"
141-
list($key, $value) = explode(':', $string, 2);
142+
[$key, $value] = explode(':', $string, 2);
142143
$config[$key][] = $value;
143144
}
144145

Command/ExtractCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Bundle\Command;
1313

14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
@@ -29,12 +30,13 @@
2930
/**
3031
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
3132
*/
33+
#[AsCommand(
34+
name: 'translation:extract'
35+
)]
3236
class ExtractCommand extends Command
3337
{
3438
use BundleTrait;
3539

36-
protected static $defaultName = 'translation:extract';
37-
3840
/**
3941
* @var CatalogueFetcher
4042
*/
@@ -79,7 +81,6 @@ public function __construct(
7981
protected function configure(): void
8082
{
8183
$this
82-
->setName(self::$defaultName)
8384
->setDescription('Extract translations from source code.')
8485
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
8586
->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', false)

Command/StatusCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Bundle\Command;
1313

14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
@@ -24,12 +25,13 @@
2425
/**
2526
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2627
*/
28+
#[AsCommand(
29+
name: 'translation:status'
30+
)]
2731
class StatusCommand extends Command
2832
{
2933
use BundleTrait;
3034

31-
protected static $defaultName = 'translation:status';
32-
3335
/**
3436
* @var CatalogueCounter
3537
*/
@@ -60,7 +62,6 @@ public function __construct(
6062
protected function configure(): void
6163
{
6264
$this
63-
->setName(self::$defaultName)
6465
->setDescription('Show status about your translations.')
6566
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
6667
->addArgument('locale', InputArgument::OPTIONAL, 'The locale to use. If omitted, we use all configured locales.', false)

Command/SyncCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Bundle\Command;
1313

14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
@@ -22,12 +23,13 @@
2223
/**
2324
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2425
*/
26+
#[AsCommand(
27+
name: 'translation:sync'
28+
)]
2529
class SyncCommand extends Command
2630
{
2731
use StorageTrait;
2832

29-
protected static $defaultName = 'translation:sync';
30-
3133
public function __construct(StorageManager $storageManager)
3234
{
3335
$this->storageManager = $storageManager;
@@ -38,7 +40,6 @@ public function __construct(StorageManager $storageManager)
3840
protected function configure(): void
3941
{
4042
$this
41-
->setName(self::$defaultName)
4243
->setDescription('Sync the translations with the remote storage')
4344
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
4445
->addArgument('direction', InputArgument::OPTIONAL, 'Use "down" if local changes should be overwritten, otherwise "up"', 'down')
@@ -78,7 +79,7 @@ public function cleanParameters(array $raw)
7879

7980
foreach ($raw as $string) {
8081
// Assert $string looks like "foo:bar"
81-
list($key, $value) = explode(':', $string, 2);
82+
[$key, $value] = explode(':', $string, 2);
8283
$config[$key][] = $value;
8384
}
8485

Controller/WebUIController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct(
7676
/**
7777
* Show a dashboard for the configuration.
7878
*/
79-
public function indexAction(?string $configName = null): Response
79+
public function indexAction(string $configName = null): Response
8080
{
8181
if (!$this->isWebUIEnabled) {
8282
return new Response('You are not allowed here. Check your config.', Response::HTTP_BAD_REQUEST);

DependencyInjection/Configuration.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public function __construct(ContainerBuilder $container)
2929
$this->container = $container;
3030
}
3131

32-
/**
33-
* {@inheritdoc}
34-
*/
3532
public function getConfigTreeBuilder(): TreeBuilder
3633
{
3734
$treeBuilder = new TreeBuilder('translation');

DependencyInjection/TranslationExtension.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
*/
3838
class TranslationExtension extends Extension
3939
{
40-
/**
41-
* {@inheritdoc}
42-
*/
4340
public function load(array $configs, ContainerBuilder $container): void
4441
{
4542
$container->setParameter('extractor_vendor_dir', $this->getExtractorVendorDirectory());
@@ -224,17 +221,11 @@ private function enableFallbackAutoTranslator(ContainerBuilder $container, array
224221
$container->setParameter('php_translation.translator_service.api_key', $config['fallback_translation']['api_key']);
225222
}
226223

227-
/**
228-
* {@inheritdoc}
229-
*/
230224
public function getAlias(): string
231225
{
232226
return 'translation';
233227
}
234228

235-
/**
236-
* {@inheritdoc}
237-
*/
238229
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
239230
{
240231
return new Configuration($container);

EditInPlace/Activator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class Activator implements ActivatorInterface
3232
/**
3333
* @var Session|null
3434
*/
35-
private $session = null;
35+
private $session;
3636

3737
public function __construct(RequestStack $requestStack)
3838
{
@@ -81,9 +81,6 @@ public function deactivate(): void
8181
}
8282
}
8383

84-
/**
85-
* {@inheritdoc}
86-
*/
8784
public function checkRequest(Request $request = null): bool
8885
{
8986
if (null === $this->getSession() || !$this->getSession()->has(self::KEY)) {

Service/CacheClearer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(string $kernelCacheDir, $translator, Filesystem $fil
5858
*
5959
* @param string|null $locale optional filter to clear only one locale
6060
*/
61-
public function clearAndWarmUp(?string $locale = null): void
61+
public function clearAndWarmUp(string $locale = null): void
6262
{
6363
$translationDir = sprintf('%s/translations', $this->kernelCacheDir);
6464

0 commit comments

Comments
 (0)