Skip to content

Commit

Permalink
Support Symfony 7 by adding return types conditionally (#6136)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Aug 24, 2023
1 parent 0f3f92c commit e07f9b5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
5 changes: 5 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<exclude name="Squiz.NamingConventions.ValidVariableName.PublicHasUnderscore"/>
</rule>

<rule ref="Generic.Classes.DuplicateClassName.Found">
<exclude-pattern>*/src/Tools/Console/Command/CommandCompatibility.php</exclude-pattern>
</rule>

<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<exclude-pattern>*/src/Configuration.php</exclude-pattern>
<exclude-pattern>*/src/Connection.php</exclude-pattern>
Expand Down Expand Up @@ -70,6 +74,7 @@
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>*/src/Tools/Console/Command/CommandCompatibility.php</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

Expand Down
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@
<file name="tests/Functional/Schema/SchemaManagerFunctionalTestCase.php"/>
</errorLevel>
</DocblockTypeContradiction>
<DuplicateClass>
<errorLevel type="suppress">
<file name="src/Tools/Console/Command/CommandCompatibility.php"/>
</errorLevel>
</DuplicateClass>
<FalsableReturnStatement>
<errorLevel type="suppress">
<!--
Expand Down
35 changes: 35 additions & 0 deletions src/Tools/Console/Command/CommandCompatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tools\Console\Command;

use ReflectionMethod;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
/** @internal */
trait CommandCompatibility
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
return $this->doExecute($input, $output);
}
}
} else {
/** @internal */
trait CommandCompatibility
{
/**
* {@inheritDoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->doExecute($input, $output);
}
}
}
12 changes: 4 additions & 8 deletions src/Tools/Console/Command/ReservedWordsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
/** @deprecated Use database documentation instead. */
class ReservedWordsCommand extends Command
{
use CommandCompatibility;

/** @var array<string,KeywordList> */
private array $keywordLists;

Expand Down Expand Up @@ -136,14 +138,8 @@ protected function configure()
EOT);
}

/**
* {@inheritDoc}
*
* @return int
*
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
/** @throws Exception */
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(
'<comment>The <info>dbal:reserved-words</info> command is deprecated.</comment>'
Expand Down
12 changes: 4 additions & 8 deletions src/Tools/Console/Command/RunSqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
class RunSqlCommand extends Command
{
use CommandCompatibility;

private ConnectionProvider $connectionProvider;

public function __construct(ConnectionProvider $connectionProvider)
Expand Down Expand Up @@ -55,14 +57,8 @@ protected function configure()
EOT);
}

/**
* {@inheritDoc}
*
* @return int
*
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
/** @throws Exception */
private function doExecute(InputInterface $input, OutputInterface $output): int
{
$conn = $this->getConnection($input);
$io = new SymfonyStyle($input, $output);
Expand Down

0 comments on commit e07f9b5

Please sign in to comment.