Skip to content

Commit 5781c4a

Browse files
committed
Implement conditional trait for Command::configure return type
1 parent 82231fe commit 5781c4a

15 files changed

+72
-15
lines changed

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/ClearCache/MetadataCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MetadataCommand extends Command
2222
{
2323
use CommandCompatibility;
2424

25-
protected function configure(): void
25+
private function doConfigure(): void
2626
{
2727
$this
2828
->setName('odm:clear-cache:metadata')

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/CommandCompatibility.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,32 @@
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Output\OutputInterface;
1111

12-
if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
12+
// Symfony 8
13+
if ((new ReflectionMethod(Command::class, 'configure'))->hasReturnType()) {
1314
/** @internal */
1415
trait CommandCompatibility
1516
{
17+
protected function configure(): void
18+
{
19+
$this->doConfigure();
20+
}
21+
22+
protected function execute(InputInterface $input, OutputInterface $output): int
23+
{
24+
return $this->doExecute($input, $output);
25+
}
26+
}
27+
// Symfony 7
28+
} elseif ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
29+
/** @internal */
30+
trait CommandCompatibility
31+
{
32+
/** @return void */
33+
protected function configure()
34+
{
35+
$this->doConfigure();
36+
}
37+
1638
protected function execute(InputInterface $input, OutputInterface $output): int
1739
{
1840
return $this->doExecute($input, $output);
@@ -22,6 +44,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
2244
/** @internal */
2345
trait CommandCompatibility
2446
{
47+
/** @return void */
48+
protected function configure()
49+
{
50+
$this->doConfigure();
51+
}
52+
2553
/**
2654
* {@inheritDoc}
2755
*

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateHydratorsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GenerateHydratorsCommand extends Command
3131
{
3232
use CommandCompatibility;
3333

34-
protected function configure(): void
34+
private function doConfigure(): void
3535
{
3636
$this
3737
->setName('odm:generate:hydrators')

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GeneratePersistentCollectionsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GeneratePersistentCollectionsCommand extends Command
3131
{
3232
use CommandCompatibility;
3333

34-
protected function configure(): void
34+
private function doConfigure(): void
3535
{
3636
$this
3737
->setName('odm:generate:persistent-collections')

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateProxiesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GenerateProxiesCommand extends Command
3535
{
3636
use CommandCompatibility;
3737

38-
protected function configure(): void
38+
private function doConfigure(): void
3939
{
4040
$this
4141
->setName('odm:generate:proxies')

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QueryCommand extends Command
2727
{
2828
use CommandCompatibility;
2929

30-
protected function configure(): void
30+
private function doConfigure(): void
3131
{
3232
$this
3333
->setName('odm:query')

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/AbstractCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
abstract class AbstractCommand extends Command
2121
{
22+
use AbstractCommandCompatibility;
23+
2224
public const DB = 'db';
2325
public const COLLECTION = 'collection';
2426
public const INDEX = 'index';
2527
public const SEARCH_INDEX = 'search-index';
2628

27-
protected function configure(): void
29+
private function configureCommonOptions(): void
2830
{
29-
parent::configure();
30-
3131
$this
3232
->addOption('maxTimeMs', null, InputOption::VALUE_REQUIRED, 'An optional maxTimeMs that will be used for all schema operations.')
3333
->addOption('w', null, InputOption::VALUE_REQUIRED, 'An optional w option for the write concern that will be used for all schema operations.')
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\Schema;
6+
7+
use ReflectionMethod;
8+
use Symfony\Component\Console\Command\Command;
9+
10+
// Symfony 8
11+
if ((new ReflectionMethod(Command::class, 'configure'))->hasReturnType()) {
12+
/** @internal */
13+
trait AbstractCommandCompatibility
14+
{
15+
protected function configure(): void
16+
{
17+
$this->configureCommonOptions();
18+
}
19+
}
20+
} else {
21+
/** @internal */
22+
trait AbstractCommandCompatibility
23+
{
24+
/** @return void */
25+
protected function configure()
26+
{
27+
$this->configureCommonOptions();
28+
}
29+
}
30+
}

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CreateCommand extends AbstractCommand
3030
self::SEARCH_INDEX => ['search index(es)', 'search indexes'],
3131
];
3232

33-
protected function configure(): void
33+
private function doConfigure(): void
3434
{
3535
parent::configure();
3636

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/DropCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class DropCommand extends AbstractCommand
3333

3434
protected function configure(): void
3535
{
36-
parent::configure();
37-
3836
$this
3937
->setName('odm:schema:drop')
4038
->addOption('class', 'c', InputOption::VALUE_REQUIRED, 'Document class to process (default: all classes)')

0 commit comments

Comments
 (0)