Skip to content

Commit

Permalink
Add native types to command classes (#9359)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Jan 11, 2022
1 parent cf62f93 commit 9f85e27
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@

abstract class AbstractEntityManagerCommand extends Command
{
/** @var EntityManagerProvider|null */
private $entityManagerProvider;

public function __construct(?EntityManagerProvider $entityManagerProvider = null)
public function __construct(private ?EntityManagerProvider $entityManagerProvider = null)
{
parent::__construct();

$this->entityManagerProvider = $entityManagerProvider;
}

final protected function getEntityManager(InputInterface $input): EntityManagerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
class CollectionRegionCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:clear-cache:region:collection')
->setDescription('Clear a second-level cache collection region')
Expand Down Expand Up @@ -60,12 +57,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
class EntityRegionCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:clear-cache:region:entity')
->setDescription('Clear a second-level cache entity region')
Expand Down Expand Up @@ -59,12 +56,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
*/
class MetadataCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:clear-cache:metadata')
->setDescription('Clear all metadata cache of the various cache drivers')
Expand All @@ -33,12 +30,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
12 changes: 2 additions & 10 deletions lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
*/
class QueryCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:clear-cache:query')
->setDescription('Clear all query cache of the various cache drivers')
Expand All @@ -56,12 +53,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
class QueryRegionCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:clear-cache:region:query')
->setDescription('Clear a second-level cache query region')
Expand Down Expand Up @@ -58,12 +55,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
*/
class ResultCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:clear-cache:result')
->setDescription('Clear all result cache of the various cache drivers')
Expand All @@ -58,12 +55,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
12 changes: 2 additions & 10 deletions lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
*/
class GenerateProxiesCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:generate-proxies')
->setAliases(['orm:generate:proxies'])
Expand All @@ -40,12 +37,7 @@ protected function configure()
->setHelp('Generates proxy classes for entity classes.');
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
12 changes: 2 additions & 10 deletions lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
class InfoCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:info')
->setDescription('Show basic information about all mapped entities')
Expand All @@ -36,12 +33,7 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ static function ($mappedEntity) use ($entityName) {

/**
* Format the given value for console output
*
* @param mixed $value
*/
private function formatValue($value): string
private function formatValue(mixed $value): string
{
if ($value === '') {
return '';
Expand Down Expand Up @@ -233,7 +231,7 @@ private function formatValue($value): string
* @return string[]
* @psalm-return array{0: string, 1: string}
*/
private function formatField(string $label, $value): array
private function formatField(string $label, mixed $value): array
{
if ($value === null) {
$value = '<comment>None</comment>';
Expand Down
12 changes: 2 additions & 10 deletions lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
*/
class RunDqlCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:run-dql')
->setDescription('Executes arbitrary DQL directly from the command line')
Expand All @@ -44,12 +41,7 @@ protected function configure()
->setHelp('Executes arbitrary DQL directly from the command line.');
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ abstract class AbstractCommand extends AbstractEntityManagerCommand
{
/**
* @param mixed[] $metadatas
*
* @return int|null Null or 0 if everything went fine, or an error code.
*/
abstract protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui);
abstract protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui): int;

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
*/
class CreateCommand extends AbstractCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:schema-tool:create')
->setDescription('Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output')
Expand All @@ -43,7 +40,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui): int
{
$dumpSql = $input->getOption('dump-sql') === true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
class DropCommand extends AbstractCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:schema-tool:drop')
->setDescription('Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output')
Expand All @@ -47,7 +44,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui): int
{
$isFullDatabaseDrop = $input->getOption('full-database');
$dumpSql = $input->getOption('dump-sql') === true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class UpdateCommand extends AbstractCommand
/** @var string */
protected $name = 'orm:schema-tool:update';

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName($this->name)
->setDescription('Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata')
Expand Down Expand Up @@ -71,7 +68,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui): int
{
// Defining if update is complete or not (--complete not defined means $saveMode = true)
$saveMode = ! $input->getOption('complete');
Expand Down
12 changes: 2 additions & 10 deletions lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
*/
class ValidateSchemaCommand extends AbstractEntityManagerCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('orm:validate-schema')
->setDescription('Validate the mapping files')
Expand All @@ -32,12 +29,7 @@ protected function configure()
->setHelp('Validate that the mapping files are correct and in sync with the database.');
}

/**
* {@inheritdoc}
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);

Expand Down
Loading

0 comments on commit 9f85e27

Please sign in to comment.