Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Symfony 7 by adding return types conditionally #6136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

Check warning on line 18 in src/Tools/Console/Command/CommandCompatibility.php

View check run for this annotation

Codecov / codecov/patch

src/Tools/Console/Command/CommandCompatibility.php#L18

Added line #L18 was not covered by tests
}
}
} 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 @@
EOT);
}

/**
* {@inheritDoc}
*
* @return int
*
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
/** @throws Exception */
private function doExecute(InputInterface $input, OutputInterface $output): int

Check warning on line 142 in src/Tools/Console/Command/ReservedWordsCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Tools/Console/Command/ReservedWordsCommand.php#L142

Added line #L142 was not covered by tests
{
$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