Skip to content

Commit

Permalink
Update doctrine/coding-standard
Browse files Browse the repository at this point in the history
This fixes the build, as coding-standard requires package that uses dependency incompatible with composer 2.0
  • Loading branch information
ostrolucky committed Oct 25, 2020
1 parent fb5b10e commit 50c53be
Show file tree
Hide file tree
Showing 67 changed files with 452 additions and 382 deletions.
2 changes: 2 additions & 0 deletions Command/CreateDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (empty($connectionName)) {
$connectionName = $this->getDoctrine()->getDefaultConnectionName();
}

$connection = $this->getDoctrineConnection($connectionName);

$ifNotExists = $input->getOption('if-not-exists');
Expand Down Expand Up @@ -86,6 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (! $name) {
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created.");
}

// Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url
unset($params['dbname'], $params['path'], $params['url']);

Expand Down
2 changes: 2 additions & 0 deletions Command/DropDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (empty($connectionName)) {
$connectionName = $this->getDoctrine()->getDefaultConnectionName();
}

$connection = $this->getDoctrineConnection($connectionName);

$ifExists = $input->getOption('if-exists');
Expand Down Expand Up @@ -91,6 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (! $name) {
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
}

unset($params['dbname'], $params['url']);

if (! $input->getOption('force')) {
Expand Down
2 changes: 2 additions & 0 deletions Command/ImportMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$path = $destPath . '/' . str_replace('\\', '.', $className) . '.orm.' . $type;
}

$output->writeln(sprintf(' > writing <comment>%s</comment>', $path));
$code = $exporter->exportClassMetadata($class);
$dir = dirname($path);
if (! is_dir($dir)) {
mkdir($dir, 0775, true);
}

file_put_contents($path, $code);
chmod($path, 0664);
}
Expand Down
3 changes: 3 additions & 0 deletions Command/Proxy/CollectionRegionDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ protected function configure()
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
Expand Down
4 changes: 3 additions & 1 deletion Command/Proxy/ConvertMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function assert;

/**
* Convert Doctrine ORM metadata mapping information between the various supported
* formats.
Expand Down Expand Up @@ -45,8 +47,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function getExporter($toType, $destPath)
{
/** @var AbstractExporter $exporter */
$exporter = parent::getExporter($toType, $destPath);
assert($exporter instanceof AbstractExporter);
if ($exporter instanceof XmlExporter) {
$exporter->setExtension('.orm.xml');
} elseif ($exporter instanceof YamlExporter) {
Expand Down
6 changes: 4 additions & 2 deletions Command/Proxy/DoctrineCommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Symfony\Bundle\FrameworkBundle\Console\Application;

use function assert;

/**
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles
* and multiple connections/entity managers.
Expand All @@ -20,8 +22,8 @@ abstract class DoctrineCommandHelper
*/
public static function setApplicationEntityManager(Application $application, $emName)
{
/** @var EntityManager $em */
$em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
$em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
assert($em instanceof EntityManager);
$helperSet = $application->getHelperSet();
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
Expand Down
3 changes: 3 additions & 0 deletions Command/Proxy/EntityRegionCacheDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ protected function configure()
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
Expand Down
3 changes: 3 additions & 0 deletions Command/Proxy/QueryRegionCacheDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ protected function configure()
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
Expand Down
9 changes: 6 additions & 3 deletions ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

use function is_subclass_of;

class ConnectionFactory
Expand Down Expand Up @@ -51,6 +52,7 @@ public function createConnection(array $params, Configuration $config = null, Ev
if (class_exists(DBALException::class)) {
throw DBALException::invalidWrapperClass($params['wrapperClass']);
}

throw Exception::invalidWrapperClass($params['wrapperClass']);
}

Expand Down Expand Up @@ -103,12 +105,13 @@ public function createConnection(array $params, Configuration $config = null, Ev
* @throws DBALException
* @throws Exception
*/
private function getDatabasePlatform(Connection $connection) : AbstractPlatform
private function getDatabasePlatform(Connection $connection): AbstractPlatform
{
try {
return $connection->getDatabasePlatform();
} catch (DriverException $driverException) {
$exceptionClass = class_exists(DBALException::class)? DBALException::class : Exception::class;
$exceptionClass = class_exists(DBALException::class) ? DBALException::class : Exception::class;

throw new $exceptionClass(
'An exception occurred while establishing a connection to figure out your platform version.' . PHP_EOL .
"You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL .
Expand All @@ -123,7 +126,7 @@ private function getDatabasePlatform(Connection $connection) : AbstractPlatform
/**
* initialize the types
*/
private function initializeTypes() : void
private function initializeTypes(): void
{
foreach ($this->typesConfig as $typeName => $typeConfig) {
if (Type::hasType($typeName)) {
Expand Down
20 changes: 15 additions & 5 deletions Controller/ProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\VarDumper\Cloner\Data;

use function assert;

class ProfilerController implements ContainerAwareInterface
{
/** @var ContainerInterface */
Expand All @@ -37,8 +39,8 @@ public function setContainer(ContainerInterface $container = null)
*/
public function explainAction($token, $connectionName, $query)
{
/** @var Profiler $profiler */
$profiler = $this->container->get('profiler');
assert($profiler instanceof Profiler);
$profiler->disable();

$profile = $profiler->loadProfile($token);
Expand All @@ -53,8 +55,8 @@ public function explainAction($token, $connectionName, $query)
return new Response('This query cannot be explained.');
}

/** @var Connection $connection */
$connection = $this->container->get('doctrine')->getConnection($connectionName);
assert($connection instanceof Connection);
try {
$platform = $connection->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
Expand All @@ -76,8 +78,10 @@ public function explainAction($token, $connectionName, $query)

/**
* @param mixed[] $query
*
* @return mixed[]
*/
private function explainSQLitePlatform(Connection $connection, array $query)
private function explainSQLitePlatform(Connection $connection, array $query): array
{
$params = $query['params'];

Expand All @@ -89,7 +93,10 @@ private function explainSQLitePlatform(Connection $connection, array $query)
->fetchAll(PDO::FETCH_ASSOC);
}

private function explainSQLServerPlatform(Connection $connection, $query)
/**
* @return mixed[]
*/
private function explainSQLServerPlatform(Connection $connection, string $query): array
{
if (stripos($query['sql'], 'SELECT') === 0) {
$sql = 'SET STATISTICS PROFILE ON; ' . $query['sql'] . '; SET STATISTICS PROFILE OFF;';
Expand All @@ -109,7 +116,10 @@ private function explainSQLServerPlatform(Connection $connection, $query)
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}

private function explainOtherPlatform(Connection $connection, $query)
/**
* @return mixed[]
*/
private function explainOtherPlatform(Connection $connection, string $query): array
{
$params = $query['params'];

Expand Down
Loading

0 comments on commit 50c53be

Please sign in to comment.