Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Symfony 7 by adding return types conditionally
Browse files Browse the repository at this point in the history
derrabus committed Aug 23, 2023
1 parent 0f3f92c commit e2c9790
Showing 3 changed files with 43 additions and 16 deletions.
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
@@ -34,6 +34,8 @@
/** @deprecated Use database documentation instead. */
class ReservedWordsCommand extends Command
{
use CommandCompatibility;

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

@@ -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>'
12 changes: 4 additions & 8 deletions src/Tools/Console/Command/RunSqlCommand.php
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@
*/
class RunSqlCommand extends Command
{
use CommandCompatibility;

private ConnectionProvider $connectionProvider;

public function __construct(ConnectionProvider $connectionProvider)
@@ -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);

0 comments on commit e2c9790

Please sign in to comment.