Skip to content

Commit 40704ee

Browse files
committed
Use AsCommand instead of old command declarations
1 parent a38d748 commit 40704ee

6 files changed

Lines changed: 12 additions & 53 deletions

File tree

src/Console/Command/ConfigureCommand.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GrumPHP\Configuration\Resolver\TaskConfigResolver;
99
use GrumPHP\Util\Filesystem;
1010
use GrumPHP\Util\Paths;
11+
use Symfony\Component\Console\Attribute\AsCommand;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Helper\QuestionHelper;
1314
use Symfony\Component\Console\Input\InputInterface;
@@ -17,10 +18,9 @@
1718
use Symfony\Component\Console\Question\ConfirmationQuestion;
1819
use Symfony\Component\Yaml\Yaml;
1920

21+
#[AsCommand(name: 'configure', description: 'Create a grumphp configuration file')]
2022
class ConfigureCommand extends Command
2123
{
22-
const COMMAND_NAME = 'configure';
23-
2424
/**
2525
* @var TaskConfigResolver
2626
*/
@@ -51,11 +51,6 @@ public function __construct(TaskConfigResolver $taskConfigResolver, Filesystem $
5151
$this->paths = $paths;
5252
}
5353

54-
public static function getDefaultName(): string
55-
{
56-
return self::COMMAND_NAME;
57-
}
58-
5954
protected function configure(): void
6055
{
6156
$this->addOption(

src/Console/Command/Git/CommitMsgCommand.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use GrumPHP\Collection\FilesCollection;
88
use GrumPHP\Collection\TestSuiteCollection;
9-
use GrumPHP\IO\IOFactory;
109
use GrumPHP\IO\IOInterface;
1110
use GrumPHP\Locator\ChangedFiles;
1211
use GrumPHP\Locator\StdInFiles;
@@ -16,6 +15,7 @@
1615
use GrumPHP\Util\Filesystem;
1716
use GrumPHP\Util\Paths;
1817
use SplFileInfo;
18+
use Symfony\Component\Console\Attribute\AsCommand;
1919
use Symfony\Component\Console\Command\Command;
2020
use Symfony\Component\Console\Input\InputArgument;
2121
use Symfony\Component\Console\Input\InputInterface;
@@ -25,9 +25,9 @@
2525
/**
2626
* This command runs the git commit-msg hook.
2727
*/
28+
#[AsCommand(name: 'git:commit-msg', description: 'Executed by the commit-msg commit hook')]
2829
class CommitMsgCommand extends Command
2930
{
30-
const COMMAND_NAME = 'git:commit-msg';
3131
const EXIT_CODE_OK = 0;
3232
const EXIT_CODE_NOK = 1;
3333

@@ -83,14 +83,8 @@ public function __construct(
8383
$this->io = $io;
8484
}
8585

86-
public static function getDefaultName(): string
87-
{
88-
return self::COMMAND_NAME;
89-
}
90-
9186
protected function configure(): void
9287
{
93-
$this->setDescription('Executed by the commit-msg commit hook');
9488
$this->addOption('git-user', null, InputOption::VALUE_REQUIRED, 'The configured git user name.', '');
9589
$this->addOption('git-email', null, InputOption::VALUE_REQUIRED, 'The configured git email.', '');
9690
$this->addArgument('commit-msg-file', InputArgument::REQUIRED, 'The configured commit message file.');

src/Console/Command/Git/DeInitCommand.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
use GrumPHP\Util\Filesystem;
88
use GrumPHP\Util\Paths;
9+
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Output\OutputInterface;
1213

1314
/**
1415
* This command is responsible for removing all the configured hooks.
1516
*/
17+
#[AsCommand(name: 'git:deinit', description: 'Removes the commit hooks')]
1618
class DeInitCommand extends Command
1719
{
18-
const COMMAND_NAME = 'git:deinit';
19-
2020
/**
2121
* @var array
2222
*/
@@ -35,11 +35,6 @@ class DeInitCommand extends Command
3535
*/
3636
private $paths;
3737

38-
public static function getDefaultName(): string
39-
{
40-
return self::COMMAND_NAME;
41-
}
42-
4338
public function __construct(
4439
Filesystem $filesystem,
4540
Paths $paths
@@ -50,10 +45,6 @@ public function __construct(
5045
$this->paths = $paths;
5146
}
5247

53-
protected function configure(): void
54-
{
55-
$this->setDescription('Removes the commit hooks');
56-
}
5748

5849
public function execute(InputInterface $input, OutputInterface $output): int
5950
{

src/Console/Command/Git/InitCommand.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
use GrumPHP\Util\Filesystem;
1212
use GrumPHP\Util\Paths;
1313
use RuntimeException;
14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Output\OutputInterface;
1718

1819
/**
1920
* This command is responsible for enabling all the configured hooks.
2021
*/
22+
#[AsCommand(name: 'git:init', description: 'Registers the Git hooks')]
2123
class InitCommand extends Command
2224
{
23-
const COMMAND_NAME = 'git:init';
24-
2525
/**
2626
* @var array
2727
*/
@@ -70,16 +70,6 @@ public function __construct(
7070
$this->paths = $paths;
7171
}
7272

73-
public static function getDefaultName(): string
74-
{
75-
return self::COMMAND_NAME;
76-
}
77-
78-
protected function configure(): void
79-
{
80-
$this->setDescription('Registers the Git hooks');
81-
}
82-
8373
public function execute(InputInterface $input, OutputInterface $output): int
8474
{
8575
$this->input = $input;

src/Console/Command/Git/PreCommitCommand.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
use GrumPHP\Collection\FilesCollection;
88
use GrumPHP\Collection\TestSuiteCollection;
9-
use GrumPHP\IO\IOFactory;
109
use GrumPHP\IO\IOInterface;
1110
use GrumPHP\Locator\ChangedFiles;
1211
use GrumPHP\Locator\StdInFiles;
1312
use GrumPHP\Runner\TaskRunner;
1413
use GrumPHP\Runner\TaskRunnerContext;
1514
use GrumPHP\Task\Context\GitPreCommitContext;
15+
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Input\InputOption;
@@ -21,9 +21,9 @@
2121
/**
2222
* This command runs the git pre-commit hook.
2323
*/
24+
#[AsCommand(name: 'git:pre-commit', description: 'Executed by the pre-commit hook')]
2425
class PreCommitCommand extends Command
2526
{
26-
const COMMAND_NAME = 'git:pre-commit';
2727
const EXIT_CODE_OK = 0;
2828
const EXIT_CODE_NOK = 1;
2929

@@ -65,14 +65,8 @@ public function __construct(
6565
$this->io = $io;
6666
}
6767

68-
public static function getDefaultName(): string
69-
{
70-
return self::COMMAND_NAME;
71-
}
72-
7368
protected function configure(): void
7469
{
75-
$this->setDescription('Executed by the pre-commit hook');
7670
$this->addOption(
7771
'skip-success-output',
7872
null,

src/Console/Command/RunCommand.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
use GrumPHP\Collection\FilesCollection;
88
use GrumPHP\Collection\TestSuiteCollection;
9-
use GrumPHP\IO\IOFactory;
109
use GrumPHP\IO\IOInterface;
1110
use GrumPHP\Locator\RegisteredFiles;
1211
use GrumPHP\Locator\StdInFiles;
1312
use GrumPHP\Runner\TaskRunner;
1413
use GrumPHP\Runner\TaskRunnerContext;
1514
use GrumPHP\Task\Context\RunContext;
1615
use GrumPHP\Util\Str;
16+
use Symfony\Component\Console\Attribute\AsCommand;
1717
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\Console\Input\InputInterface;
1919
use Symfony\Component\Console\Input\InputOption;
2020
use Symfony\Component\Console\Output\OutputInterface;
2121

22+
#[AsCommand(name: 'run', description: 'Run configured tasks')]
2223
class RunCommand extends Command
2324
{
24-
const COMMAND_NAME = 'run';
2525
const EXIT_CODE_OK = 0;
2626
const EXIT_CODE_NOK = 1;
2727

@@ -63,11 +63,6 @@ public function __construct(
6363
$this->io = $io;
6464
}
6565

66-
public static function getDefaultName(): string
67-
{
68-
return self::COMMAND_NAME;
69-
}
70-
7166
protected function configure(): void
7267
{
7368
$this->addOption(

0 commit comments

Comments
 (0)