Skip to content

Commit 8581aa2

Browse files
committed
Merge class argument with path option
1 parent 62053a9 commit 8581aa2

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/Symfony/Component/Validator/Command/DebugCommand.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public function __construct(ValidatorInterface $validator)
4545
protected function configure()
4646
{
4747
$this
48-
->addArgument('class', InputArgument::OPTIONAL, 'A class to debug')
49-
->addOption('path', null, InputOption::VALUE_OPTIONAL, 'A path for the classes to debug', 'src/Entity')
48+
->addArgument('class', InputArgument::REQUIRED, 'A fully qualified class name or a path')
5049
->addOption('show-all', null, InputOption::VALUE_NONE, 'Show all classes event if they have no validation constraints')
5150
->setDescription('Displays validation constraints for classes')
5251
->setHelp(<<<'EOF'
@@ -55,26 +54,24 @@ protected function configure()
5554
5655
The <info>%command.name% 'App\Entity\Dummy'</info> command dumps the validators for the dummy class.
5756
58-
The <info>%command.name% --path=src/</info> command dumps the validators for the `src` directory.
57+
The <info>%command.name% src/</info> command dumps the validators for the `src` directory.
5958
EOF
6059
)
6160
;
6261
}
6362

6463
protected function execute(InputInterface $input, OutputInterface $output): int
6564
{
66-
if (null !== $class = $input->getArgument('class')) {
65+
$class = $input->getArgument('class');
66+
67+
if (class_exists($class)) {
6768
$this->dumpValidatorsForClass($input, $output, $class);
6869

6970
return 0;
7071
}
7172

72-
if (null !== $path = $input->getOption('path')) {
73-
foreach ($this->getResourcesByPath($path) as $class) {
74-
$this->dumpValidatorsForClass($input, $output, $class);
75-
}
76-
77-
return 0;
73+
foreach ($this->getResourcesByPath($class) as $class) {
74+
$this->dumpValidatorsForClass($input, $output, $class);
7875
}
7976

8077
return 0;
@@ -170,7 +167,7 @@ private function getConstraintOptions(Constraint $constraint): array
170167
private function getResourcesByPath(string $path): array
171168
{
172169
$finder = new Finder();
173-
$finder->in($path)->name('*.php')->sortByName(true);
170+
$finder->files()->in($path)->name('*.php')->sortByName(true);
174171
$classes = [];
175172

176173
foreach ($finder as $file) {

src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function testOutputWithPathArgument(): void
122122
$command = new DebugCommand($validator);
123123

124124
$tester = new CommandTester($command);
125-
$tester->execute(['--path' => __DIR__.'/../Dummy'], ['decorated' => false]);
125+
$tester->execute(['class' => __DIR__.'/../Dummy'], ['decorated' => false]);
126126

127127
$this->assertSame(<<<TXT
128128

0 commit comments

Comments
 (0)