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

Apply Doctrine CS v5 #855

Merged
merged 1 commit into from Oct 29, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -63,7 +63,7 @@ jobs:
env: CODING_STANDARDS
php: 7.1
install:
- travis_retry composer require -n --prefer-dist --dev doctrine/coding-standard:^4.0
- travis_retry composer require -n --prefer-dist --dev doctrine/coding-standard:^5.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason why we don't require it in the composer.json itself?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is probably just old and can be updated to match other repos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that DoctrineBundle sadly still supports dead PHP versions.

script:
- ./vendor/bin/phpcs

Expand Down
6 changes: 4 additions & 2 deletions Command/CreateDatabaseDoctrineCommand.php
Expand Up @@ -3,6 +3,8 @@
namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\DBAL\DriverManager;
use Exception;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -75,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$hasPath = isset($params['path']);
$name = $hasPath ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
if (! $name) {
throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created.");
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 All @@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tmpConnection->getSchemaManager()->createDatabase($name);
$output->writeln(sprintf('<info>Created database <comment>%s</comment> for connection named <comment>%s</comment></info>', $name, $connectionName));
}
} catch (\Exception $e) {
} catch (Exception $e) {
$output->writeln(sprintf('<error>Could not create database <comment>%s</comment> for connection named <comment>%s</comment></error>', $name, $connectionName));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
$error = true;
Expand Down
5 changes: 3 additions & 2 deletions Command/DoctrineCommand.php
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\EntityGenerator;
use LogicException;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

/**
Expand Down Expand Up @@ -35,7 +36,7 @@ protected function getEntityGenerator()
* Get a doctrine entity manager by symfony name.
*
* @param string $name
* @param null|int $shardId
* @param int|null $shardId
*
* @return EntityManager
*/
Expand All @@ -45,7 +46,7 @@ protected function getEntityManager($name, $shardId = null)

if ($shardId) {
if (! $manager->getConnection() instanceof PoolingShardConnection) {
throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $name));
throw new LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $name));
}

$manager->getConnection()->connect($shardId);
Expand Down
6 changes: 4 additions & 2 deletions Command/DropDatabaseDoctrineCommand.php
Expand Up @@ -3,6 +3,8 @@
namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\DBAL\DriverManager;
use Exception;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -80,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
if (! $name) {
throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
}
unset($params['dbname'], $params['url']);

Expand Down Expand Up @@ -112,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$output->writeln(sprintf('<info>Database <comment>%s</comment> for connection named <comment>%s</comment> doesn\'t exist. Skipped.</info>', $name, $connectionName));
}
} catch (\Exception $e) {
} catch (Exception $e) {
$output->writeln(sprintf('<error>Could not drop database <comment>%s</comment> for connection named <comment>%s</comment></error>', $name, $connectionName));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));

Expand Down
6 changes: 4 additions & 2 deletions Command/GenerateEntitiesDoctrineCommand.php
Expand Up @@ -4,6 +4,8 @@

use Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory;
use Doctrine\ORM\Tools\EntityRepositoryGenerator;
use InvalidArgumentException;
use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -86,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
$metadata = $manager->getBundleMetadata($bundle);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
$name = strtr($input->getArgument('name'), '/', '\\');
$pos = strpos($name, ':');

Expand Down Expand Up @@ -117,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Getting the metadata for the entity class once more to get the correct path if the namespace has multiple occurrences
try {
$entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
// fall back to the bundle metadata when no entity class could be found
$entityMetadata = $metadata;
}
Expand Down
3 changes: 2 additions & 1 deletion Command/ImportMappingDoctrineCommand.php
Expand Up @@ -6,6 +6,7 @@
use Doctrine\ORM\Tools\Console\MetadataFilter;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$namespace = $namespaceOrBundle;
$destPath = $input->getOption('path');
if ($destPath === null) {
throw new \InvalidArgumentException('The --path option is required when passing a namespace (e.g. --path=src). If you intended to pass a bundle name, check your spelling.');
throw new InvalidArgumentException('The --path option is required when passing a namespace (e.g. --path=src). If you intended to pass a bundle name, check your spelling.');
}
}

Expand Down
3 changes: 2 additions & 1 deletion Command/Proxy/DelegateCommand.php
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;

use Doctrine\ORM\Version;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function isEnabled()
protected function wrapCommand($entityManagerName)
{
if (! $this->isVersionCompatible()) {
throw new \RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion()));
throw new RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion()));
}

DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $entityManagerName);
Expand Down
2 changes: 1 addition & 1 deletion ConnectionFactory.php
Expand Up @@ -74,8 +74,8 @@ public function createConnection(array $params, Configuration $config = null, Ev
* and the platform version is unknown.
* For details have a look at DoctrineBundle issue #673.
*
*
* @return AbstractPlatform
*
* @throws DBALException
*/
private function getDatabasePlatform(Connection $connection)
Expand Down
8 changes: 5 additions & 3 deletions Controller/ProfilerController.php
Expand Up @@ -4,6 +4,8 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Exception;
use PDO;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -61,7 +63,7 @@ public function explainAction($token, $connectionName, $query)
} else {
$results = $this->explainOtherPlatform($connection, $query);
}
} catch (\Exception $e) {
} catch (Exception $e) {
return new Response('This query cannot be explained.');
}

Expand All @@ -87,7 +89,7 @@ private function explainSQLServerPlatform(Connection $connection, $query)

$stmt = $connection->executeQuery($sql, $params, $query['types']);
$stmt->nextRowset();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}

private function explainOtherPlatform(Connection $connection, $query)
Expand All @@ -99,6 +101,6 @@ private function explainOtherPlatform(Connection $connection, $query)
}

return $connection->executeQuery('EXPLAIN ' . $query['sql'], $params, $query['types'])
->fetchAll(\PDO::FETCH_ASSOC);
->fetchAll(PDO::FETCH_ASSOC);
}
}
7 changes: 4 additions & 3 deletions DataCollector/DoctrineDataCollector.php
Expand Up @@ -11,6 +11,7 @@
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\ORM\Version;
use Exception;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector as BaseCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -39,7 +40,7 @@ public function __construct(ManagerRegistry $registry)
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, Exception $exception = null)
{
parent::collect($request, $response, $exception);

Expand Down Expand Up @@ -227,11 +228,11 @@ public function getGroupedQueries()
$connectionGroupedQueries[$key]['count']++;
$totalExecutionMS += $query['executionMS'];
}
usort($connectionGroupedQueries, function ($a, $b) {
usort($connectionGroupedQueries, static function ($a, $b) {
if ($a['executionMS'] === $b['executionMS']) {
return 0;
}
return ($a['executionMS'] < $b['executionMS']) ? 1 : -1;
return $a['executionMS'] < $b['executionMS'] ? 1 : -1;
});
$this->groupedQueries[$connection] = $connectionGroupedQueries;
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public function process(ContainerBuilder $container)
return;
}

$repoReferences = array_map(function ($id) {
$repoReferences = array_map(static function ($id) {
return new Reference($id);
}, $repoServiceIds);

Expand Down