diff --git a/.travis.yml b/.travis.yml
index a6b4a6c30..51c642e80 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
script:
- ./vendor/bin/phpcs
diff --git a/Command/CreateDatabaseDoctrineCommand.php b/Command/CreateDatabaseDoctrineCommand.php
index b827a29ff..504e27e8e 100644
--- a/Command/CreateDatabaseDoctrineCommand.php
+++ b/Command/CreateDatabaseDoctrineCommand.php
@@ -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;
@@ -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']);
@@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tmpConnection->getSchemaManager()->createDatabase($name);
$output->writeln(sprintf('Created database %s for connection named %s', $name, $connectionName));
}
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$output->writeln(sprintf('Could not create database %s for connection named %s', $name, $connectionName));
$output->writeln(sprintf('%s', $e->getMessage()));
$error = true;
diff --git a/Command/DoctrineCommand.php b/Command/DoctrineCommand.php
index a8f0ef863..f136d52ff 100644
--- a/Command/DoctrineCommand.php
+++ b/Command/DoctrineCommand.php
@@ -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;
/**
@@ -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
*/
@@ -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);
diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php
index 42974d075..fee312495 100644
--- a/Command/DropDatabaseDoctrineCommand.php
+++ b/Command/DropDatabaseDoctrineCommand.php
@@ -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;
@@ -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']);
@@ -112,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$output->writeln(sprintf('Database %s for connection named %s doesn\'t exist. Skipped.', $name, $connectionName));
}
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$output->writeln(sprintf('Could not drop database %s for connection named %s', $name, $connectionName));
$output->writeln(sprintf('%s', $e->getMessage()));
diff --git a/Command/GenerateEntitiesDoctrineCommand.php b/Command/GenerateEntitiesDoctrineCommand.php
index 0c31fd484..80dc6898f 100644
--- a/Command/GenerateEntitiesDoctrineCommand.php
+++ b/Command/GenerateEntitiesDoctrineCommand.php
@@ -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;
@@ -86,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf('Generating entities for bundle "%s"', $bundle->getName()));
$metadata = $manager->getBundleMetadata($bundle);
- } catch (\InvalidArgumentException $e) {
+ } catch (InvalidArgumentException $e) {
$name = strtr($input->getArgument('name'), '/', '\\');
$pos = strpos($name, ':');
@@ -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;
}
diff --git a/Command/ImportMappingDoctrineCommand.php b/Command/ImportMappingDoctrineCommand.php
index 8b34380f6..39a42b6dc 100644
--- a/Command/ImportMappingDoctrineCommand.php
+++ b/Command/ImportMappingDoctrineCommand.php
@@ -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;
@@ -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.');
}
}
diff --git a/Command/Proxy/DelegateCommand.php b/Command/Proxy/DelegateCommand.php
index 32ae4e92d..500db6fd9 100644
--- a/Command/Proxy/DelegateCommand.php
+++ b/Command/Proxy/DelegateCommand.php
@@ -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;
@@ -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);
diff --git a/ConnectionFactory.php b/ConnectionFactory.php
index 08a776121..54c535347 100644
--- a/ConnectionFactory.php
+++ b/ConnectionFactory.php
@@ -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)
diff --git a/Controller/ProfilerController.php b/Controller/ProfilerController.php
index 5f7c89dd0..11afae312 100644
--- a/Controller/ProfilerController.php
+++ b/Controller/ProfilerController.php
@@ -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;
@@ -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.');
}
@@ -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)
@@ -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);
}
}
diff --git a/DataCollector/DoctrineDataCollector.php b/DataCollector/DoctrineDataCollector.php
index 88d567061..b1e2af663 100644
--- a/DataCollector/DoctrineDataCollector.php
+++ b/DataCollector/DoctrineDataCollector.php
@@ -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;
@@ -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);
@@ -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;
}
diff --git a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php
index 516badf09..7ccafb74e 100644
--- a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php
+++ b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php
@@ -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);
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 07fa3194b..5252cbc42 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -2,10 +2,12 @@
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection;
+use ReflectionClass;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
+use function method_exists;
/**
* This class contains the configuration information for the bundle
@@ -35,7 +37,7 @@ public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('doctrine');
- if (\method_exists($treeBuilder, 'getRootNode')) {
+ if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
@@ -57,10 +59,10 @@ private function addDbalSection(ArrayNodeDefinition $node)
->children()
->arrayNode('dbal')
->beforeNormalization()
- ->ifTrue(function ($v) {
+ ->ifTrue(static function ($v) {
return is_array($v) && ! array_key_exists('connections', $v) && ! array_key_exists('connection', $v);
})
- ->then(function ($v) {
+ ->then(static function ($v) {
// Key that should not be rewritten to the connection config
$excludedKeys = ['default_connection' => true, 'types' => true, 'type' => true];
$connection = [];
@@ -87,7 +89,7 @@ private function addDbalSection(ArrayNodeDefinition $node)
->prototype('array')
->beforeNormalization()
->ifString()
- ->then(function ($v) {
+ ->then(static function ($v) {
return ['class' => $v];
})
->end()
@@ -100,8 +102,7 @@ private function addDbalSection(ArrayNodeDefinition $node)
->end()
->fixXmlConfig('connection')
->append($this->getDbalConnectionsNode())
- ->end()
- ;
+ ->end();
}
/**
@@ -118,8 +119,7 @@ private function getDbalConnectionsNode()
$connectionNode = $node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
- ->prototype('array')
- ;
+ ->prototype('array');
$this->configureDbalDriverNode($connectionNode);
@@ -156,15 +156,13 @@ private function getDbalConnectionsNode()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
- ->end()
- ;
+ ->end();
$slaveNode = $connectionNode
->children()
->arrayNode('slaves')
->useAttributeAsKey('name')
- ->prototype('array')
- ;
+ ->prototype('array');
$this->configureDbalDriverNode($slaveNode);
$shardNode = $connectionNode
@@ -176,8 +174,7 @@ private function getDbalConnectionsNode()
->min(1)
->isRequired()
->end()
- ->end()
- ;
+ ->end();
$this->configureDbalDriverNode($shardNode);
return $node;
@@ -257,10 +254,10 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node)
->end()
->end()
->beforeNormalization()
- ->ifTrue(function ($v) {
+ ->ifTrue(static function ($v) {
return ! isset($v['sessionMode']) && isset($v['session_mode']);
})
- ->then(function ($v) {
+ ->then(static function ($v) {
$v['sessionMode'] = $v['session_mode'];
unset($v['session_mode']);
@@ -268,17 +265,16 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node)
})
->end()
->beforeNormalization()
- ->ifTrue(function ($v) {
+ ->ifTrue(static function ($v) {
return ! isset($v['MultipleActiveResultSets']) && isset($v['multiple_active_result_sets']);
})
- ->then(function ($v) {
+ ->then(static function ($v) {
$v['MultipleActiveResultSets'] = $v['multiple_active_result_sets'];
unset($v['multiple_active_result_sets']);
return $v;
})
- ->end()
- ;
+ ->end();
}
/**
@@ -292,18 +288,18 @@ private function addOrmSection(ArrayNodeDefinition $node)
->children()
->arrayNode('orm')
->beforeNormalization()
- ->ifTrue(function ($v) {
+ ->ifTrue(static function ($v) {
return $v === null || (is_array($v) && ! array_key_exists('entity_managers', $v) && ! array_key_exists('entity_manager', $v));
})
- ->then(function ($v) {
+ ->then(static function ($v) {
$v = (array) $v;
// Key that should not be rewritten to the connection config
$excludedKeys = [
'default_entity_manager' => true,
- 'auto_generate_proxy_classes' => true,
+ 'auto_generate_proxy_classes' => true,
'proxy_dir' => true,
- 'proxy_namespace' => true,
- 'resolve_target_entities' => true,
+ 'proxy_namespace' => true,
+ 'resolve_target_entities' => true,
'resolve_target_entity' => true,
];
$entityManager = [];
@@ -325,7 +321,7 @@ private function addOrmSection(ArrayNodeDefinition $node)
->scalarNode('auto_generate_proxy_classes')->defaultValue(false)
->info('Auto generate mode possible values are: "NEVER", "ALWAYS", "FILE_NOT_EXISTS", "EVAL"')
->validate()
- ->ifTrue(function ($v) use ($generationModes) {
+ ->ifTrue(static function ($v) use ($generationModes) {
if (is_int($v) && in_array($v, $generationModes['values']/*array(0, 1, 2, 3)*/)) {
return false;
}
@@ -344,7 +340,7 @@ private function addOrmSection(ArrayNodeDefinition $node)
->end()
->validate()
->ifString()
- ->then(function ($v) {
+ ->then(static function ($v) {
return constant('Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_' . strtoupper($v));
})
->end()
@@ -357,8 +353,7 @@ private function addOrmSection(ArrayNodeDefinition $node)
->fixXmlConfig('resolve_target_entity', 'resolve_target_entities')
->append($this->getOrmTargetEntityResolverNode())
->end()
- ->end()
- ;
+ ->end();
}
/**
@@ -375,8 +370,7 @@ private function getOrmTargetEntityResolverNode()
->useAttributeAsKey('interface')
->prototype('scalar')
->cannotBeEmpty()
- ->end()
- ;
+ ->end();
return $node;
}
@@ -390,7 +384,7 @@ private function getOrmEntityListenersNode()
{
$builder = new TreeBuilder();
$node = $builder->root('entity_listeners');
- $normalizer = function ($mappings) {
+ $normalizer = static function ($mappings) {
$entities = [];
foreach ($mappings as $entityClass => $mapping) {
@@ -406,8 +400,8 @@ private function getOrmEntityListenersNode()
foreach ($eventMapping as $method) {
$events[] = [
- 'type' => $eventType,
- 'method' => $method,
+ 'type' => $eventType,
+ 'method' => $method,
];
}
}
@@ -430,7 +424,7 @@ private function getOrmEntityListenersNode()
$node
->beforeNormalization()
// Yaml normalization
- ->ifTrue(function ($v) {
+ ->ifTrue(static function ($v) {
return is_array(reset($v)) && is_string(key(reset($v)));
})
->then($normalizer)
@@ -461,8 +455,7 @@ private function getOrmEntityListenersNode()
->end()
->end()
->end()
- ->end()
- ;
+ ->end();
return $node;
}
@@ -551,7 +544,7 @@ private function getOrmEntityManagersNode()
->prototype('array')
->beforeNormalization()
->ifString()
- ->then(function ($v) {
+ ->then(static function ($v) {
return ['type' => $v];
})
->end()
@@ -596,16 +589,16 @@ private function getOrmEntityManagersNode()
->prototype('array')
->beforeNormalization()
->ifString()
- ->then(function ($v) {
+ ->then(static function ($v) {
return ['class' => $v];
})
->end()
->beforeNormalization()
// The content of the XML node is returned as the "value" key so we need to rename it
- ->ifTrue(function ($v) {
+ ->ifTrue(static function ($v) {
return is_array($v) && isset($v['value']);
})
- ->then(function ($v) {
+ ->then(static function ($v) {
$v['class'] = $v['value'];
unset($v['value']);
@@ -624,8 +617,7 @@ private function getOrmEntityManagersNode()
->end()
->end()
->end()
- ->end()
- ;
+ ->end();
return $node;
}
@@ -646,7 +638,7 @@ private function getOrmCacheDriverNode($name)
->addDefaultsIfNotSet()
->beforeNormalization()
->ifString()
- ->then(function ($v) {
+ ->then(static function ($v) {
return ['type' => $v];
})
->end()
@@ -660,8 +652,7 @@ private function getOrmCacheDriverNode($name)
->scalarNode('id')->end()
->scalarNode('namespace')->defaultNull()->end()
->scalarNode('cache_provider')->defaultNull()->end()
- ->end()
- ;
+ ->end();
return $node;
}
@@ -675,7 +666,7 @@ private function getAutoGenerateModes()
{
$constPrefix = 'AUTOGENERATE_';
$prefixLen = strlen($constPrefix);
- $refClass = new \ReflectionClass('Doctrine\Common\Proxy\AbstractProxyFactory');
+ $refClass = new ReflectionClass('Doctrine\Common\Proxy\AbstractProxyFactory');
$constsArray = $refClass->getConstants();
$namesArray = [];
$valuesArray = [];
diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php
index 1959003f7..f352722a0 100644
--- a/DependencyInjection/DoctrineExtension.php
+++ b/DependencyInjection/DoctrineExtension.php
@@ -7,6 +7,7 @@
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\SymfonyBridgeAdapter;
use Doctrine\ORM\Version;
+use LogicException;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\Form\Type\DoctrineType;
use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory;
@@ -58,11 +59,11 @@ public function load(array $configs, ContainerBuilder $container)
}
if (empty($config['dbal'])) {
- throw new \LogicException('Configuring the ORM layer requires to configure the DBAL layer as well.');
+ throw new LogicException('Configuring the ORM layer requires to configure the DBAL layer as well.');
}
if (! class_exists('Doctrine\ORM\Version')) {
- throw new \LogicException('To configure the ORM layer, you must first install the doctrine/orm package.');
+ throw new LogicException('To configure the ORM layer, you must first install the doctrine/orm package.');
}
$this->ormLoad($config['orm'], $container);
@@ -177,8 +178,7 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)),
new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)),
$connection['mapping_types'],
- ])
- ;
+ ]);
// Set class in case "wrapper_class" option was used to assist IDEs
if (isset($options['wrapperClass'])) {
@@ -396,8 +396,7 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$loader->load('messenger.xml');
$container->getDefinition('messenger.middleware.doctrine_transaction_middleware')
- ->replaceArgument(0, $config['default_entity_manager'])
- ;
+ ->replaceArgument(0, $config['default_entity_manager']);
}
/*
@@ -519,8 +518,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
$container
->setDefinition($managerConfiguratorName, new $definitionClassname('doctrine.orm.manager_configurator.abstract'))
->replaceArgument(0, $enabledFilters)
- ->replaceArgument(1, $filtersParameters)
- ;
+ ->replaceArgument(1, $filtersParameters);
if (! isset($entityManager['connection'])) {
$entityManager['connection'] = $this->defaultConnection;
@@ -533,8 +531,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
new Reference(sprintf('doctrine.dbal.%s_connection', $entityManager['connection'])),
new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name'])),
])
- ->setConfigurator([new Reference($managerConfiguratorName), 'configure'])
- ;
+ ->setConfigurator([new Reference($managerConfiguratorName), 'configure']);
$container->setAlias(
sprintf('doctrine.orm.%s_entity_manager.event_manager', $entityManager['name']),
@@ -576,6 +573,10 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
* 1. Specify a bundle and optionally details where the entity and mapping information reside.
* 2. Specify an arbitrary mapping location.
*
+ * @param array $entityManager A configured ORM entity manager
+ * @param Definition $ormConfigDef A Definition instance
+ * @param ContainerBuilder $container A ContainerBuilder instance
+ *
* @example
*
* doctrine.orm:
@@ -596,10 +597,6 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
*
* In the case of bundles everything is really optional (which leads to autodetection for this bundle) but
* in the mappings key everything except alias is a required argument.
- *
- * @param array $entityManager A configured ORM entity manager
- * @param Definition $ormConfigDef A Definition instance
- * @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function loadOrmEntityManagerMappingInformation(array $entityManager, Definition $ormConfigDef, ContainerBuilder $container)
{
@@ -616,6 +613,10 @@ protected function loadOrmEntityManagerMappingInformation(array $entityManager,
/**
* Loads an ORM second level cache bundle mapping information.
*
+ * @param array $entityManager A configured ORM entity manager
+ * @param Definition $ormConfigDef A Definition instance
+ * @param ContainerBuilder $container A ContainerBuilder instance
+ *
* @example
* entity_managers:
* default:
@@ -636,10 +637,6 @@ protected function loadOrmEntityManagerMappingInformation(array $entityManager,
* lifetime: 600
* cache_driver:
* type: apc
- *
- * @param array $entityManager A configured ORM entity manager
- * @param Definition $ormConfigDef A Definition instance
- * @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function loadOrmSecondLevelCache(array $entityManager, Definition $ormConfigDef, ContainerBuilder $container)
{
diff --git a/DoctrineBundle.php b/DoctrineBundle.php
index 7f48c6004..95ccf47f7 100644
--- a/DoctrineBundle.php
+++ b/DoctrineBundle.php
@@ -62,7 +62,7 @@ public function boot()
// See https://github.com/symfony/symfony/pull/3419 for usage of references
$container = &$this->container;
- $proxyGenerator = function ($proxyDir, $proxyNamespace, $class) use (&$container) {
+ $proxyGenerator = static function ($proxyDir, $proxyNamespace, $class) use (&$container) {
$originalClassName = ClassUtils::getRealClass($class);
/** @var Registry $registry */
$registry = $container->get('doctrine');
diff --git a/ManagerConfigurator.php b/ManagerConfigurator.php
index eb12b3f23..6143890a8 100644
--- a/ManagerConfigurator.php
+++ b/ManagerConfigurator.php
@@ -28,7 +28,6 @@ public function __construct(array $enabledFilters, array $filtersParameters)
/**
* Create a connection by name.
- *
*/
public function configure(EntityManagerInterface $entityManager)
{
@@ -37,7 +36,6 @@ public function configure(EntityManagerInterface $entityManager)
/**
* Enables filters for a given entity manager
- *
*/
private function enableFilters(EntityManagerInterface $entityManager)
{
diff --git a/Mapping/ContainerAwareEntityListenerResolver.php b/Mapping/ContainerAwareEntityListenerResolver.php
index e52da4d9f..4345015b7 100644
--- a/Mapping/ContainerAwareEntityListenerResolver.php
+++ b/Mapping/ContainerAwareEntityListenerResolver.php
@@ -2,6 +2,8 @@
namespace Doctrine\Bundle\DoctrineBundle\Mapping;
+use InvalidArgumentException;
+use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ContainerAwareEntityListenerResolver implements EntityListenerServiceResolver
@@ -46,7 +48,7 @@ public function clear($className = null)
public function register($object)
{
if (! is_object($object)) {
- throw new \InvalidArgumentException(sprintf('An object was expected, but got "%s".', gettype($object)));
+ throw new InvalidArgumentException(sprintf('An object was expected, but got "%s".', gettype($object)));
}
$className = $this->normalizeClassName(get_class($object));
@@ -88,7 +90,7 @@ public function resolve($className)
private function resolveService($serviceId)
{
if (! $this->container->has($serviceId)) {
- throw new \RuntimeException(sprintf('There is no service named "%s"', $serviceId));
+ throw new RuntimeException(sprintf('There is no service named "%s"', $serviceId));
}
return $this->container->get($serviceId);
diff --git a/Mapping/DisconnectedMetadataFactory.php b/Mapping/DisconnectedMetadataFactory.php
index 24aaa9b51..199b5a699 100644
--- a/Mapping/DisconnectedMetadataFactory.php
+++ b/Mapping/DisconnectedMetadataFactory.php
@@ -6,6 +6,8 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
+use ReflectionClass;
+use RuntimeException;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
/**
@@ -32,14 +34,14 @@ public function __construct(ManagerRegistry $registry)
*
* @return ClassMetadataCollection A ClassMetadataCollection instance
*
- * @throws \RuntimeException When bundle does not contain mapped entities.
+ * @throws RuntimeException When bundle does not contain mapped entities.
*/
public function getBundleMetadata(BundleInterface $bundle)
{
$namespace = $bundle->getNamespace();
$metadata = $this->getMetadataForNamespace($namespace);
if (! $metadata->getMetadata()) {
- throw new \RuntimeException(sprintf('Bundle "%s" does not contain any mapped entities.', $bundle->getName()));
+ throw new RuntimeException(sprintf('Bundle "%s" does not contain any mapped entities.', $bundle->getName()));
}
$path = $this->getBasePathForClass($bundle->getName(), $bundle->getNamespace(), $bundle->getPath());
@@ -80,13 +82,13 @@ public function getClassMetadata($class, $path = null)
*
* @return ClassMetadataCollection A ClassMetadataCollection instance
*
- * @throws \RuntimeException When namespace not contain mapped entities.
+ * @throws RuntimeException When namespace not contain mapped entities.
*/
public function getNamespaceMetadata($namespace, $path = null)
{
$metadata = $this->getMetadataForNamespace($namespace);
if (! $metadata->getMetadata()) {
- throw new \RuntimeException(sprintf('Namespace "%s" does not contain any mapped entities.', $namespace));
+ throw new RuntimeException(sprintf('Namespace "%s" does not contain any mapped entities.', $namespace));
}
$this->findNamespaceAndPathForMetadata($metadata, $path);
@@ -99,13 +101,13 @@ public function getNamespaceMetadata($namespace, $path = null)
*
* @param string|null $path
*
- * @throws \RuntimeException When unable to determine the path.
+ * @throws RuntimeException When unable to determine the path.
*/
public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadata, $path = null)
{
$all = $metadata->getMetadata();
if (class_exists($all[0]->name)) {
- $r = new \ReflectionClass($all[0]->name);
+ $r = new ReflectionClass($all[0]->name);
$path = $this->getBasePathForClass($r->getName(), $r->getNamespaceName(), dirname($r->getFilename()));
$ns = $r->getNamespaceName();
} elseif ($path) {
@@ -114,7 +116,7 @@ public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadat
array_pop($nsParts);
$ns = implode('\\', $nsParts);
} else {
- throw new \RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $all[0]->name));
+ throw new RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $all[0]->name));
}
$metadata->setPath($path);
@@ -130,7 +132,7 @@ public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadat
*
* @return string
*
- * @throws \RuntimeException When base path not found.
+ * @throws RuntimeException When base path not found.
*/
private function getBasePathForClass($name, $namespace, $path)
{
@@ -139,7 +141,7 @@ private function getBasePathForClass($name, $namespace, $path)
$destination = str_replace('/' . $namespace, '', $search, $c);
if ($c !== 1) {
- throw new \RuntimeException(sprintf('Can\'t find base path for "%s" (path: "%s", destination: "%s").', $name, $path, $destination));
+ throw new RuntimeException(sprintf('Can\'t find base path for "%s" (path: "%s", destination: "%s").', $name, $path, $destination));
}
return $destination;
diff --git a/Registry.php b/Registry.php
index 0c376d68e..cf1cb5091 100644
--- a/Registry.php
+++ b/Registry.php
@@ -41,9 +41,9 @@ public function __construct(ContainerInterface $container, array $connections, a
/**
* Gets the default entity manager name.
*
- * @return string The default entity manager name
- *
* @deprecated
+ *
+ * @return string The default entity manager name
*/
public function getDefaultEntityManagerName()
{
@@ -55,11 +55,11 @@ public function getDefaultEntityManagerName()
/**
* Gets a named entity manager.
*
+ * @deprecated
+ *
* @param string $name The entity manager name (null for the default one)
*
* @return EntityManager
- *
- * @deprecated
*/
public function getEntityManager($name = null)
{
@@ -71,9 +71,9 @@ public function getEntityManager($name = null)
/**
* Gets an array of all registered entity managers
*
- * @return EntityManager[] an array of all EntityManager instances
- *
* @deprecated
+ *
+ * @return EntityManager[] an array of all EntityManager instances
*/
public function getEntityManagers()
{
@@ -95,10 +95,9 @@ public function getEntityManagers()
* hold an obsolete reference. You can inject the registry instead
* to avoid this problem.
*
- * @param string $name The entity manager name (null for the default one)
- *
- *
* @deprecated
+ *
+ * @param string $name The entity manager name (null for the default one)
*/
public function resetEntityManager($name = null)
{
@@ -112,11 +111,11 @@ public function resetEntityManager($name = null)
*
* This method looks for the alias in all registered entity managers.
*
+ * @deprecated
+ *
* @param string $alias The alias
*
* @return string The full namespace
- *
- * @deprecated
*/
public function getEntityNamespace($alias)
{
@@ -130,11 +129,11 @@ public function getEntityNamespace($alias)
*
* This method looks for the alias in all registered entity managers.
*
+ * @see Configuration::getEntityNamespace
+ *
* @param string $alias The alias
*
* @return string The full namespace
- *
- * @see Configuration::getEntityNamespace
*/
public function getAliasNamespace($alias)
{
@@ -151,9 +150,9 @@ public function getAliasNamespace($alias)
/**
* Gets all connection names.
*
- * @return string[] An array of connection names
- *
* @deprecated
+ *
+ * @return string[] An array of connection names
*/
public function getEntityManagerNames()
{
@@ -165,11 +164,11 @@ public function getEntityManagerNames()
/**
* Gets the entity manager associated with a given class.
*
+ * @deprecated
+ *
* @param string $class A Doctrine Entity class name
*
* @return EntityManager|null
- *
- * @deprecated
*/
public function getEntityManagerForClass($class)
{
diff --git a/Repository/ContainerRepositoryFactory.php b/Repository/ContainerRepositoryFactory.php
index 992a2b6c3..cd1b47202 100644
--- a/Repository/ContainerRepositoryFactory.php
+++ b/Repository/ContainerRepositoryFactory.php
@@ -5,10 +5,11 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
-use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Repository\RepositoryFactory;
+use InvalidArgumentException;
use Psr\Container\ContainerInterface;
+use RuntimeException;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
/**
@@ -30,7 +31,7 @@ public function __construct(ContainerInterface $container = null)
// When DoctrineBundle requires Symfony 3.3+, this can be removed
// and the $container argument can become required.
if ($container === null && class_exists(ServiceLocatorTagPass::class)) {
- throw new \InvalidArgumentException(sprintf('The first argument of %s::__construct() is required on Symfony 3.3 or higher.', self::class));
+ throw new InvalidArgumentException(sprintf('The first argument of %s::__construct() is required on Symfony 3.3 or higher.', self::class));
}
$this->container = $container;
@@ -51,7 +52,7 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName
$repository = $this->container->get($customRepositoryName);
if (! $repository instanceof ObjectRepository) {
- throw new \RuntimeException(sprintf('The service "%s" must implement ObjectRepository (or extend a base class, like ServiceEntityRepository).', $repositoryServiceId));
+ throw new RuntimeException(sprintf('The service "%s" must implement ObjectRepository (or extend a base class, like ServiceEntityRepository).', $repositoryServiceId));
}
return $repository;
@@ -61,14 +62,14 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName
if (is_a($customRepositoryName, ServiceEntityRepositoryInterface::class, true)) {
// can be removed when DoctrineBundle requires Symfony 3.3
if ($this->container === null) {
- throw new \RuntimeException(sprintf('Support for loading entities from the service container only works for Symfony 3.3 or higher. Upgrade your version of Symfony or make sure your "%s" class does not implement "%s"', $customRepositoryName, ServiceEntityRepositoryInterface::class));
+ throw new RuntimeException(sprintf('Support for loading entities from the service container only works for Symfony 3.3 or higher. Upgrade your version of Symfony or make sure your "%s" class does not implement "%s"', $customRepositoryName, ServiceEntityRepositoryInterface::class));
}
- throw new \RuntimeException(sprintf('The "%s" entity repository implements "%s", but its service could not be found. Make sure the service exists and is tagged with "%s".', $customRepositoryName, ServiceEntityRepositoryInterface::class, ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG));
+ throw new RuntimeException(sprintf('The "%s" entity repository implements "%s", but its service could not be found. Make sure the service exists and is tagged with "%s".', $customRepositoryName, ServiceEntityRepositoryInterface::class, ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG));
}
if (! class_exists($customRepositoryName)) {
- throw new \RuntimeException(sprintf('The "%s" entity has a repositoryClass set to "%s", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with "%s".', $metadata->name, $customRepositoryName, ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG));
+ throw new RuntimeException(sprintf('The "%s" entity has a repositoryClass set to "%s", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with "%s".', $metadata->name, $customRepositoryName, ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG));
}
// allow the repository to be created below
diff --git a/Tests/BundleTest.php b/Tests/BundleTest.php
index f5d7de6c1..03fb26ec5 100644
--- a/Tests/BundleTest.php
+++ b/Tests/BundleTest.php
@@ -1,6 +1,5 @@
createConnection($params, $config, $eventManager, $mappingTypes);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->assertTrue(strpos($e->getMessage(), 'can circumvent this by setting') > 0);
throw $e;
}
@@ -81,12 +82,12 @@ public function getDatabasePlatform()
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
- throw new \Exception('not implemented');
+ throw new Exception('not implemented');
}
public function getSchemaManager(Connection $conn)
{
- throw new \Exception('not implemented');
+ throw new Exception('not implemented');
}
public function getName()
diff --git a/Tests/DataCollector/DoctrineDataCollectorTest.php b/Tests/DataCollector/DoctrineDataCollectorTest.php
index 11715b19e..c6e121279 100644
--- a/Tests/DataCollector/DoctrineDataCollectorTest.php
+++ b/Tests/DataCollector/DoctrineDataCollectorTest.php
@@ -5,6 +5,7 @@
use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use PHPUnit\Framework\TestCase;
+use ReflectionClass;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -93,7 +94,7 @@ private function createEntityMetadata($entityFQCN)
{
$metadata = new ClassMetadataInfo($entityFQCN);
$metadata->name = $entityFQCN;
- $metadata->reflClass = new \ReflectionClass('stdClass');
+ $metadata->reflClass = new ReflectionClass('stdClass');
return $metadata;
}
@@ -119,8 +120,6 @@ private function createCollector(array $managers)
->method('getManagers')
->will($this->returnValue($managers));
- $collector = new DoctrineDataCollector($registry);
-
- return $collector;
+ return new DoctrineDataCollector($registry);
}
}
diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
index bed845c4b..822eac27b 100644
--- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
+++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
@@ -109,24 +109,24 @@ public function testDbalLoadSingleMasterSlaveConnection()
$this->assertTrue($param['keepSlave']);
$this->assertEquals(
[
- 'user' => 'mysql_user',
- 'password' => 'mysql_s3cr3t',
- 'port' => null,
- 'dbname' => 'mysql_db',
- 'host' => 'localhost',
- 'unix_socket' => '/path/to/mysqld.sock',
- 'defaultTableOptions' => [],
+ 'user' => 'mysql_user',
+ 'password' => 'mysql_s3cr3t',
+ 'port' => null,
+ 'dbname' => 'mysql_db',
+ 'host' => 'localhost',
+ 'unix_socket' => '/path/to/mysqld.sock',
+ 'defaultTableOptions' => [],
],
$param['master']
);
$this->assertEquals(
[
'user' => 'slave_user',
- 'password' => 'slave_s3cr3t',
- 'port' => null,
- 'dbname' => 'slave_db',
+ 'password' => 'slave_s3cr3t',
+ 'port' => null,
+ 'dbname' => 'slave_db',
'host' => 'localhost',
- 'unix_socket' => '/path/to/mysqld_slave.sock',
+ 'unix_socket' => '/path/to/mysqld_slave.sock',
],
$param['slaves']['slave1']
);
@@ -143,25 +143,25 @@ public function testDbalLoadPoolShardingConnection()
$this->assertEquals(new Reference('foo.shard_choser'), $param['shardChoser']);
$this->assertEquals(
[
- 'user' => 'mysql_user',
- 'password' => 'mysql_s3cr3t',
- 'port' => null,
- 'dbname' => 'mysql_db',
- 'host' => 'localhost',
- 'unix_socket' => '/path/to/mysqld.sock',
- 'defaultTableOptions' => [],
+ 'user' => 'mysql_user',
+ 'password' => 'mysql_s3cr3t',
+ 'port' => null,
+ 'dbname' => 'mysql_db',
+ 'host' => 'localhost',
+ 'unix_socket' => '/path/to/mysqld.sock',
+ 'defaultTableOptions' => [],
],
$param['global']
);
$this->assertEquals(
[
'user' => 'shard_user',
- 'password' => 'shard_s3cr3t',
- 'port' => null,
- 'dbname' => 'shard_db',
+ 'password' => 'shard_s3cr3t',
+ 'port' => null,
+ 'dbname' => 'shard_db',
'host' => 'localhost',
- 'unix_socket' => '/path/to/mysqld_shard.sock',
- 'id' => 1,
+ 'unix_socket' => '/path/to/mysqld_shard.sock',
+ 'id' => 1,
],
$param['shards'][0]
);
@@ -216,7 +216,7 @@ public function testLoadSimpleSingleConnection()
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
- new Reference('doctrine.orm.default_configuration'),
+ new Reference('doctrine.orm.default_configuration'),
]);
}
@@ -231,19 +231,19 @@ public function testLoadSimpleSingleConnectionWithoutDbName()
$definition = $container->getDefinition('doctrine.dbal.default_connection');
$this->assertDICConstructorArguments($definition, [
- [
- 'host' => 'localhost',
- 'port' => null,
- 'user' => 'root',
- 'password' => null,
- 'driver' => 'pdo_mysql',
- 'driverOptions' => [],
- 'defaultTableOptions' => [],
- ],
- new Reference('doctrine.dbal.default_connection.configuration'),
- new Reference('doctrine.dbal.default_connection.event_manager'),
- [],
- ]);
+ [
+ 'host' => 'localhost',
+ 'port' => null,
+ 'user' => 'root',
+ 'password' => null,
+ 'driver' => 'pdo_mysql',
+ 'driverOptions' => [],
+ 'defaultTableOptions' => [],
+ ],
+ new Reference('doctrine.dbal.default_connection.configuration'),
+ new Reference('doctrine.dbal.default_connection.event_manager'),
+ [],
+ ]);
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass());
@@ -258,9 +258,9 @@ public function testLoadSimpleSingleConnectionWithoutDbName()
$this->assertEquals('create', $factory[1]);
$this->assertDICConstructorArguments($definition, [
- new Reference('doctrine.dbal.default_connection'),
- new Reference('doctrine.orm.default_configuration'),
- ]);
+ new Reference('doctrine.dbal.default_connection'),
+ new Reference('doctrine.orm.default_configuration'),
+ ]);
}
public function testLoadSingleConnection()
@@ -297,7 +297,7 @@ public function testLoadSingleConnection()
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
- new Reference('doctrine.orm.default_configuration'),
+ new Reference('doctrine.orm.default_configuration'),
]);
$configDef = $container->getDefinition('doctrine.orm.default_configuration');
@@ -409,7 +409,7 @@ public function testEntityManagerMemcacheMetadataCacheDriverConfiguration()
$this->assertDICDefinitionClass($definition, '%doctrine_cache.memcache.connection.class%');
$this->assertDICDefinitionMethodCallOnce($definition, 'addServer', [
'localhost',
- '11211',
+ '11211',
]);
}
@@ -717,63 +717,63 @@ public function testAttachEntityListeners()
$this->assertEquals(['doctrine.event_listener' => [ ['event' => 'loadClassMetadata'] ] ], $definition->getTags());
$this->assertEquals($methodCalls[0], [
- 'addEntityListener',
- [
- 'ExternalBundles\Entities\FooEntity',
- 'MyBundles\Listeners\FooEntityListener',
- 'prePersist',
- null,
- ],
+ 'addEntityListener',
+ [
+ 'ExternalBundles\Entities\FooEntity',
+ 'MyBundles\Listeners\FooEntityListener',
+ 'prePersist',
+ null,
+ ],
]);
$this->assertEquals($methodCalls[1], [
- 'addEntityListener',
- [
- 'ExternalBundles\Entities\FooEntity',
- 'MyBundles\Listeners\FooEntityListener',
- 'postPersist',
- 'postPersist',
- ],
+ 'addEntityListener',
+ [
+ 'ExternalBundles\Entities\FooEntity',
+ 'MyBundles\Listeners\FooEntityListener',
+ 'postPersist',
+ 'postPersist',
+ ],
]);
$this->assertEquals($methodCalls[2], [
- 'addEntityListener',
- [
- 'ExternalBundles\Entities\FooEntity',
- 'MyBundles\Listeners\FooEntityListener',
- 'postLoad',
- 'postLoadHandler',
- ],
+ 'addEntityListener',
+ [
+ 'ExternalBundles\Entities\FooEntity',
+ 'MyBundles\Listeners\FooEntityListener',
+ 'postLoad',
+ 'postLoadHandler',
+ ],
]);
$this->assertEquals($methodCalls[3], [
- 'addEntityListener',
- [
- 'ExternalBundles\Entities\BarEntity',
- 'MyBundles\Listeners\BarEntityListener',
- 'prePersist',
- 'prePersist',
- ],
+ 'addEntityListener',
+ [
+ 'ExternalBundles\Entities\BarEntity',
+ 'MyBundles\Listeners\BarEntityListener',
+ 'prePersist',
+ 'prePersist',
+ ],
]);
$this->assertEquals($methodCalls[4], [
- 'addEntityListener',
- [
- 'ExternalBundles\Entities\BarEntity',
- 'MyBundles\Listeners\BarEntityListener',
- 'prePersist',
- 'prePersistHandler',
- ],
+ 'addEntityListener',
+ [
+ 'ExternalBundles\Entities\BarEntity',
+ 'MyBundles\Listeners\BarEntityListener',
+ 'prePersist',
+ 'prePersistHandler',
+ ],
]);
$this->assertEquals($methodCalls[5], [
- 'addEntityListener',
- [
- 'ExternalBundles\Entities\BarEntity',
- 'MyBundles\Listeners\LogDeleteEntityListener',
- 'postDelete',
- 'postDelete',
- ],
+ 'addEntityListener',
+ [
+ 'ExternalBundles\Entities\BarEntity',
+ 'MyBundles\Listeners\LogDeleteEntityListener',
+ 'postDelete',
+ 'postDelete',
+ ],
]);
}
diff --git a/Tests/DependencyInjection/Compiler/MessengerPassTest.php b/Tests/DependencyInjection/Compiler/MessengerPassTest.php
index 968a5e4ba..31b2114d4 100644
--- a/Tests/DependencyInjection/Compiler/MessengerPassTest.php
+++ b/Tests/DependencyInjection/Compiler/MessengerPassTest.php
@@ -4,6 +4,7 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\MessengerPass;
use PHPUnit\Framework\TestCase;
+use stdClass;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -41,7 +42,7 @@ public function testRemoveDefinitionsWhenHasAliasButNotMessengerComponent()
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
$loader->load('messenger.xml');
- $container->register('some_other_bus', \stdClass::class);
+ $container->register('some_other_bus', stdClass::class);
$container->setAlias('message_bus', 'some_other_bus');
$pass->process($container);
diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php
index 408dca345..5426f670b 100644
--- a/Tests/DependencyInjection/DoctrineExtensionTest.php
+++ b/Tests/DependencyInjection/DoctrineExtensionTest.php
@@ -222,12 +222,12 @@ public function testDbalWrapperClass()
$extension->load(
[
[
- 'dbal' => [
- 'connections' => [
- 'default' => ['password' => 'foo', 'wrapper_class' => TestWrapperClass::class],
- 'second' => ['password' => 'boo'],
- ],
- ],
+ 'dbal' => [
+ 'connections' => [
+ 'default' => ['password' => 'foo', 'wrapper_class' => TestWrapperClass::class],
+ 'second' => ['password' => 'boo'],
+ ],
+ ],
],
[],
['dbal' => ['default_connection' => 'foo']],
@@ -350,11 +350,11 @@ public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection()
$extension = new DoctrineExtension();
$extension->load([[
- 'dbal' => [
- 'connections' => [
- 'default' => ['password' => 'foo', 'use_savepoints' => true],
- ],
- ],
+ 'dbal' => [
+ 'connections' => [
+ 'default' => ['password' => 'foo', 'use_savepoints' => true],
+ ],
+ ],
],
], $container);
@@ -409,7 +409,7 @@ public function testSingleEntityManagerWithDefaultConfiguration()
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
- new Reference('doctrine.orm.default_configuration'),
+ new Reference('doctrine.orm.default_configuration'),
]);
}
@@ -439,7 +439,7 @@ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration(
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
- new Reference('doctrine.orm.default_configuration'),
+ new Reference('doctrine.orm.default_configuration'),
]);
$slcDefinition = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory');
@@ -478,7 +478,7 @@ public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration()
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
- new Reference('doctrine.orm.default_configuration'),
+ new Reference('doctrine.orm.default_configuration'),
]);
$slcDefinition = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory');
diff --git a/Tests/DependencyInjection/XMLSchemaTest.php b/Tests/DependencyInjection/XMLSchemaTest.php
index af6a92cb0..29b8fd979 100644
--- a/Tests/DependencyInjection/XMLSchemaTest.php
+++ b/Tests/DependencyInjection/XMLSchemaTest.php
@@ -2,6 +2,8 @@
namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection;
+use DirectoryIterator;
+use DOMDocument;
use PHPUnit\Framework\TestCase;
class XMLSchemaTest extends TestCase
@@ -9,7 +11,7 @@ class XMLSchemaTest extends TestCase
public static function dataValidateSchemaFiles()
{
$schemaFiles = [];
- $di = new \DirectoryIterator(__DIR__ . '/Fixtures/config/xml');
+ $di = new DirectoryIterator(__DIR__ . '/Fixtures/config/xml');
foreach ($di as $element) {
if (! $element->isFile() || substr($element->getFilename(), -4) !== '.xml') {
continue;
@@ -27,14 +29,14 @@ public static function dataValidateSchemaFiles()
public function testValidateSchema($file)
{
$found = false;
- $dom = new \DOMDocument('1.0', 'UTF-8');
+ $dom = new DOMDocument('1.0', 'UTF-8');
$dom->load($file);
$xmlns = 'http://symfony.com/schema/dic/doctrine';
$dbalElements = $dom->getElementsByTagNameNS($xmlns, 'dbal');
if ($dbalElements->length) {
- $dbalDom = new \DOMDocument('1.0', 'UTF-8');
+ $dbalDom = new DOMDocument('1.0', 'UTF-8');
$dbalNode = $dbalDom->importNode($dbalElements->item(0));
$configNode = $dbalDom->createElementNS($xmlns, 'config');
$configNode->appendChild($dbalNode);
@@ -47,7 +49,7 @@ public function testValidateSchema($file)
$ormElements = $dom->getElementsByTagNameNS($xmlns, 'orm');
if ($ormElements->length) {
- $ormDom = new \DOMDocument('1.0', 'UTF-8');
+ $ormDom = new DOMDocument('1.0', 'UTF-8');
$ormNode = $ormDom->importNode($ormElements->item(0));
$configNode = $ormDom->createElementNS($xmlns, 'config');
$configNode->appendChild($ormNode);
diff --git a/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php b/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php
index 8bccada1f..cbfad8b00 100644
--- a/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php
+++ b/Tests/Mapping/ContainerAwareEntityListenerResolverTest.php
@@ -4,6 +4,7 @@
use Doctrine\Bundle\DoctrineBundle\Mapping\ContainerAwareEntityListenerResolver;
use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_MockObject_MockObject;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ContainerAwareEntityListenerResolverTest extends TestCase
@@ -11,7 +12,7 @@ class ContainerAwareEntityListenerResolverTest extends TestCase
/** @var ContainerAwareEntityListenerResolver */
private $resolver;
- /** @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var ContainerInterface|PHPUnit_Framework_MockObject_MockObject */
private $container;
protected function setUp()
@@ -56,14 +57,12 @@ public function testRegisterServiceAndResolve()
->expects($this->any())
->method('has')
->with($serviceId)
- ->will($this->returnValue(true))
- ;
+ ->will($this->returnValue(true));
$this->container
->expects($this->any())
->method('get')
->with($serviceId)
- ->will($this->returnValue($object))
- ;
+ ->will($this->returnValue($object));
$this->assertInstanceOf($className, $this->resolver->resolve($className));
$this->assertSame($object, $this->resolver->resolve($className));
@@ -83,8 +82,7 @@ public function testRegisterMissingServiceAndResolve()
->expects($this->any())
->method('has')
->with($serviceId)
- ->will($this->returnValue(false))
- ;
+ ->will($this->returnValue(false));
$this->resolver->resolve($className);
}
diff --git a/Tests/Mapping/DisconnectedMetadataFactoryTest.php b/Tests/Mapping/DisconnectedMetadataFactoryTest.php
index 542b3778b..a1c18fc70 100644
--- a/Tests/Mapping/DisconnectedMetadataFactoryTest.php
+++ b/Tests/Mapping/DisconnectedMetadataFactoryTest.php
@@ -26,7 +26,7 @@ protected function setUp()
*/
public function testCannotFindNamespaceAndPathForMetadata()
{
- $class = new ClassMetadataInfo(__CLASS__);
+ $class = new ClassMetadataInfo(self::class);
$collection = new ClassMetadataCollection([$class]);
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
diff --git a/Tests/ProfilerTest.php b/Tests/ProfilerTest.php
index c35af11f4..89576eb22 100644
--- a/Tests/ProfilerTest.php
+++ b/Tests/ProfilerTest.php
@@ -18,13 +18,16 @@
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
+use Twig_Environment;
+use Twig_Loader_Filesystem;
+use Twig_RuntimeLoaderInterface;
class ProfilerTest extends BaseTestCase
{
/** @var DebugStack */
private $logger;
- /** @var \Twig_Environment */
+ /** @var Twig_Environment */
private $twig;
/** @var DoctrineDataCollector */
@@ -38,9 +41,9 @@ public function setUp()
$this->collector = new DoctrineDataCollector($registry);
$this->collector->addLogger('foo', $this->logger);
- $twigLoaderFilesystem = new \Twig_Loader_Filesystem(__DIR__ . '/../Resources/views/Collector');
+ $twigLoaderFilesystem = new Twig_Loader_Filesystem(__DIR__ . '/../Resources/views/Collector');
$twigLoaderFilesystem->addPath(__DIR__ . '/../vendor/symfony/web-profiler-bundle/Resources/views', 'WebProfiler');
- $this->twig = new \Twig_Environment($twigLoaderFilesystem, ['debug' => true, 'strict_variables' => true]);
+ $this->twig = new Twig_Environment($twigLoaderFilesystem, ['debug' => true, 'strict_variables' => true]);
$this->twig->addExtension(new CodeExtension('', '', ''));
$this->twig->addExtension(new RoutingExtension($this->getMockBuilder(UrlGeneratorInterface::class)->getMock()));
@@ -48,7 +51,7 @@ public function setUp()
$this->twig->addExtension(new WebProfilerExtension());
$this->twig->addExtension(new DoctrineExtension());
- $loader = $this->getMockBuilder(\Twig_RuntimeLoaderInterface::class)->getMock();
+ $loader = $this->getMockBuilder(Twig_RuntimeLoaderInterface::class)->getMock();
$loader->method('load')->willReturn($this->getMockBuilder(HttpKernelRuntime::class)->disableOriginalConstructor()->getMock());
$this->twig->addRuntimeLoader($loader);
}
diff --git a/Tests/RegistryTest.php b/Tests/RegistryTest.php
index c63f335ad..9693ab45d 100644
--- a/Tests/RegistryTest.php
+++ b/Tests/RegistryTest.php
@@ -3,6 +3,7 @@
namespace Doctrine\Bundle\DoctrineBundle\Tests;
use Doctrine\Bundle\DoctrineBundle\Registry;
+use stdClass;
class RegistryTest extends TestCase
{
@@ -72,7 +73,7 @@ public function testGetConnectionNames()
public function testGetDefaultEntityManager()
{
- $em = new \stdClass();
+ $em = new stdClass();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->once())
->method('get')
@@ -86,7 +87,7 @@ public function testGetDefaultEntityManager()
public function testGetEntityManager()
{
- $em = new \stdClass();
+ $em = new stdClass();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->once())
->method('get')
diff --git a/Tests/Repository/ContainerRepositoryFactoryTest.php b/Tests/Repository/ContainerRepositoryFactoryTest.php
index 2ff96dff5..a3a3b47b8 100644
--- a/Tests/Repository/ContainerRepositoryFactoryTest.php
+++ b/Tests/Repository/ContainerRepositoryFactoryTest.php
@@ -11,6 +11,7 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
+use stdClass;
class ContainerRepositoryFactoryTest extends TestCase
{
@@ -72,7 +73,7 @@ public function testServiceRepositoriesMustExtendObjectRepository()
$this->markTestSkipped('Symfony 3.3 is needed for this feature.');
}
- $repo = new \stdClass();
+ $repo = new stdClass();
$container = $this->createContainer(['my_repo' => $repo]);
@@ -145,12 +146,12 @@ private function createContainer(array $services)
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container->expects($this->any())
->method('has')
- ->willReturnCallback(function ($id) use ($services) {
+ ->willReturnCallback(static function ($id) use ($services) {
return isset($services[$id]);
});
$container->expects($this->any())
->method('get')
- ->willReturnCallback(function ($id) use ($services) {
+ ->willReturnCallback(static function ($id) use ($services) {
return $services[$id];
});
@@ -170,7 +171,7 @@ private function createEntityManager(array $entityRepositoryClasses)
$em = $this->getMockBuilder(EntityManagerInterface::class)->getMock();
$em->expects($this->any())
->method('getClassMetadata')
- ->willReturnCallback(function ($class) use ($classMetadatas) {
+ ->willReturnCallback(static function ($class) use ($classMetadatas) {
return $classMetadatas[$class];
});
diff --git a/Tests/ServiceRepositoryTest.php b/Tests/ServiceRepositoryTest.php
index 992903d8c..983c46d64 100644
--- a/Tests/ServiceRepositoryTest.php
+++ b/Tests/ServiceRepositoryTest.php
@@ -14,6 +14,7 @@
use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository;
use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoRepository;
use Fixtures\Bundles\RepositoryServiceBundle\RepositoryServiceBundle;
+use RuntimeException;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -55,11 +56,11 @@ public function testRepositoryServiceWiring()
],
'orm' => [
'mappings' => [
- 'RepositoryServiceBundle' => [
- 'type' => 'annotation',
- 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity',
- 'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity',
- ],
+ 'RepositoryServiceBundle' => [
+ 'type' => 'annotation',
+ 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity',
+ 'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity',
+ ],
],
],
],
@@ -104,11 +105,11 @@ public function testRepositoryServiceWiring()
if (! class_exists(ServiceLocatorTagPass::class)) {
$message = '/Support for loading entities from the service container only works for Symfony 3\.3/';
if (method_exists($this, 'expectException')) {
- $this->expectException(\RuntimeException::class);
+ $this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp($message);
} else {
// PHPUnit 4 compat
- $this->setExpectedExceptionRegExp(\RuntimeException::class, $message);
+ $this->setExpectedExceptionRegExp(RuntimeException::class, $message);
}
}
diff --git a/Tests/TestCase.php b/Tests/TestCase.php
index 1f038c09b..5a7c8375c 100644
--- a/Tests/TestCase.php
+++ b/Tests/TestCase.php
@@ -55,11 +55,11 @@ public function createYamlBundleTestContainer()
'entity_managers' => [
'default' => [
'mappings' => [
- 'YamlBundle' => [
- 'type' => 'yml',
- 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine',
- 'prefix' => 'Fixtures\Bundles\YamlBundle\Entity',
- ],
+ 'YamlBundle' => [
+ 'type' => 'yml',
+ 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine',
+ 'prefix' => 'Fixtures\Bundles\YamlBundle\Entity',
+ ],
],
],
],
diff --git a/Twig/DoctrineExtension.php b/Twig/DoctrineExtension.php
index 5a368db2e..6df74cdbe 100644
--- a/Twig/DoctrineExtension.php
+++ b/Twig/DoctrineExtension.php
@@ -2,12 +2,15 @@
namespace Doctrine\Bundle\DoctrineBundle\Twig;
+use SqlFormatter;
use Symfony\Component\VarDumper\Cloner\Data;
+use Twig_Extension;
+use Twig_SimpleFilter;
/**
* This class contains the needed functions in order to do the query highlighting
*/
-class DoctrineExtension extends \Twig_Extension
+class DoctrineExtension extends Twig_Extension
{
/**
* Number of maximum characters that one single line can hold in the interface
@@ -19,14 +22,14 @@ class DoctrineExtension extends \Twig_Extension
/**
* Define our functions
*
- * @return \Twig_SimpleFilter[]
+ * @return Twig_SimpleFilter[]
*/
public function getFilters()
{
return [
- new \Twig_SimpleFilter('doctrine_minify_query', [$this, 'minifyQuery'], ['deprecated' => true]),
- new \Twig_SimpleFilter('doctrine_pretty_query', [$this, 'formatQuery'], ['is_safe' => ['html']]),
- new \Twig_SimpleFilter('doctrine_replace_query_parameters', [$this, 'replaceQueryParameters']),
+ new Twig_SimpleFilter('doctrine_minify_query', [$this, 'minifyQuery'], ['deprecated' => true]),
+ new Twig_SimpleFilter('doctrine_pretty_query', [$this, 'formatQuery'], ['is_safe' => ['html']]),
+ new Twig_SimpleFilter('doctrine_replace_query_parameters', [$this, 'replaceQueryParameters']),
];
}
@@ -92,7 +95,7 @@ private function shrinkParameters(array $parameters, array $combination)
$maxLength = $this->maxCharWidth;
$maxLength -= count($parameters) * 5;
- $maxLength = $maxLength / count($parameters);
+ $maxLength /= count($parameters);
foreach ($parameters as $key => $value) {
$isLarger = false;
@@ -151,9 +154,7 @@ private function composeMiniQuery($query, array $keywords, $required)
$regexp = '/^' . $regexp . '/is';
if (preg_match($regexp, $query, $matches)) {
- $result = $this->shrinkParameters($matches, $combination);
-
- return $result;
+ return $this->shrinkParameters($matches, $combination);
}
}
@@ -162,15 +163,11 @@ private function composeMiniQuery($query, array $keywords, $required)
$regexp = '/^' . $regexp . '/is';
if (preg_match($regexp, $query, $matches)) {
- $result = $this->shrinkParameters($matches, $mandatoryKeywords);
-
- return $result;
+ return $this->shrinkParameters($matches, $mandatoryKeywords);
}
// Fallback in case we didn't managed to find any good match (can we actually have that happen?!)
- $result = substr($query, 0, $this->maxCharWidth);
-
- return $result;
+ return substr($query, 0, $this->maxCharWidth);
}
/**
@@ -290,9 +287,9 @@ public function replaceQueryParameters($query, $parameters)
$i = 1;
}
- $result = preg_replace_callback(
+ return preg_replace_callback(
'/\?|((?([^"]*+)<\/pre>/Us', '\1', $html);
} else {
- $html = \SqlFormatter::format($sql);
+ $html = SqlFormatter::format($sql);
$html = preg_replace('/
([^"]*+)<\/pre>/Us', '', $html);
}