8000 Remove symfony console $defaultName deprecation (#491) · php-translation/symfony-bundle@d930db6 · GitHub
[go: up one dir, main page]

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)

0 commit comments

Comments
 (0)
0