From f7f2f7a66d248f0ee3089e7e2aedd49284649524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 6 Jan 2020 22:44:36 +0100 Subject: [PATCH] Add type declarations where backwards compatible That means: - methods in final classes - final methods (none of those found) - private methods - methods in Tests (that excludes setUp(), tearDown() and test*, which are handled with an automated tool in a separate commit) --- ConnectionFactory.php | 6 +-- Controller/ProfilerController.php | 5 +- .../Compiler/EntityListenerPass.php | 2 +- .../ServiceRepositoryCompilerPass.php | 2 +- DependencyInjection/Configuration.php | 32 ++++------- DependencyInjection/DoctrineExtension.php | 4 +- ManagerConfigurator.php | 13 ++--- Mapping/DisconnectedMetadataFactory.php | 24 ++------- Repository/ContainerRepositoryFactory.php | 8 +-- Tests/Builder/BundleConfigurationBuilder.php | 14 ++--- Tests/Command/CreateDatabaseDoctrineTest.php | 9 ++-- Tests/Command/DropDatabaseDoctrineTest.php | 9 ++-- Tests/ConnectionFactoryTest.php | 6 +-- .../DoctrineDataCollectorTest.php | 14 +---- .../AbstractDoctrineExtensionTest.php | 53 +++++++++++-------- .../DoctrineExtensionTest.php | 11 ++-- .../TestDatetimeFunction.php | 6 +-- .../TestNumericFunction.php | 6 +-- .../TestStringFunction.php | 6 +-- Tests/DependencyInjection/TestType.php | 4 +- .../XmlDoctrineExtensionTest.php | 2 +- .../YamlDoctrineExtensionTest.php | 2 +- .../ContainerRepositoryFactoryTest.php | 5 +- Tests/TestCase.php | 2 +- Tests/Twig/DoctrineExtensionTest.php | 4 +- Twig/DoctrineExtension.php | 7 +-- 26 files changed, 105 insertions(+), 151 deletions(-) diff --git a/ConnectionFactory.php b/ConnectionFactory.php index fdceb7438..76cdb03e2 100644 --- a/ConnectionFactory.php +++ b/ConnectionFactory.php @@ -96,11 +96,9 @@ 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) + private function getDatabasePlatform(Connection $connection) : AbstractPlatform { try { return $connection->getDatabasePlatform(); @@ -119,7 +117,7 @@ private function getDatabasePlatform(Connection $connection) /** * initialize the types */ - private function initializeTypes() + private function initializeTypes() : void { foreach ($this->typesConfig as $typeName => $typeConfig) { if (Type::hasType($typeName)) { diff --git a/Controller/ProfilerController.php b/Controller/ProfilerController.php index 1549d8a3d..ab8a49ea7 100644 --- a/Controller/ProfilerController.php +++ b/Controller/ProfilerController.php @@ -74,7 +74,10 @@ public function explainAction($token, $connectionName, $query) ])); } - private function explainSQLitePlatform(Connection $connection, $query) + /** + * @param mixed[] $query + */ + private function explainSQLitePlatform(Connection $connection, array $query) { $params = $query['params']; diff --git a/DependencyInjection/Compiler/EntityListenerPass.php b/DependencyInjection/Compiler/EntityListenerPass.php index 124f2eb7c..39d7964dc 100644 --- a/DependencyInjection/Compiler/EntityListenerPass.php +++ b/DependencyInjection/Compiler/EntityListenerPass.php @@ -88,7 +88,7 @@ public function process(ContainerBuilder $container) } } - private function attachToListener(ContainerBuilder $container, $name, string $class, array $attributes) + private function attachToListener(ContainerBuilder $container, string $name, string $class, array $attributes) : void { $listenerId = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $name); diff --git a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php index 988155741..e67c8a501 100644 --- a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php +++ b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php @@ -11,7 +11,7 @@ final class ServiceRepositoryCompilerPass implements CompilerPassInterface { const REPOSITORY_SERVICE_TAG = 'doctrine.repository_service'; - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container) : void { // when ORM is not enabled if (! $container->hasDefinition('doctrine.orm.container_repository_factory')) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index dac5a1b57..e6e3fd1cb 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -49,7 +49,7 @@ public function getConfigTreeBuilder() : TreeBuilder /** * Add DBAL section to configuration tree */ - private function addDbalSection(ArrayNodeDefinition $node) + private function addDbalSection(ArrayNodeDefinition $node) : void { $node ->children() @@ -103,10 +103,8 @@ private function addDbalSection(ArrayNodeDefinition $node) /** * Return the dbal connections node - * - * @return ArrayNodeDefinition */ - private function getDbalConnectionsNode() + private function getDbalConnectionsNode() : ArrayNodeDefinition { $treeBuilder = new TreeBuilder('connections'); $node = $treeBuilder->getRootNode(); @@ -185,7 +183,7 @@ private function getDbalConnectionsNode() * * These keys are available for slave configurations too. */ - private function configureDbalDriverNode(ArrayNodeDefinition $node) + private function configureDbalDriverNode(ArrayNodeDefinition $node) : void { $node ->children() @@ -295,7 +293,7 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node) /** * Add the ORM section to configuration tree */ - private function addOrmSection(ArrayNodeDefinition $node) + private function addOrmSection(ArrayNodeDefinition $node) : void { $node ->children() @@ -377,10 +375,8 @@ private function addOrmSection(ArrayNodeDefinition $node) /** * Return ORM target entity resolver node - * - * @return NodeDefinition */ - private function getOrmTargetEntityResolverNode() + private function getOrmTargetEntityResolverNode() : NodeDefinition { $treeBuilder = new TreeBuilder('resolve_target_entities'); $node = $treeBuilder->getRootNode(); @@ -396,10 +392,8 @@ private function getOrmTargetEntityResolverNode() /** * Return ORM entity listener node - * - * @return NodeDefinition */ - private function getOrmEntityListenersNode() + private function getOrmEntityListenersNode() : NodeDefinition { $treeBuilder = new TreeBuilder('entity_listeners'); $node = $treeBuilder->getRootNode(); @@ -482,10 +476,8 @@ private function getOrmEntityListenersNode() /** * Return ORM entity manager node - * - * @return ArrayNodeDefinition */ - private function getOrmEntityManagersNode() + private function getOrmEntityManagersNode() : ArrayNodeDefinition { $treeBuilder = new TreeBuilder('entity_managers'); $node = $treeBuilder->getRootNode(); @@ -644,12 +636,8 @@ private function getOrmEntityManagersNode() /** * Return a ORM cache driver node for an given entity manager - * - * @param string $name - * - * @return ArrayNodeDefinition */ - private function getOrmCacheDriverNode($name) + private function getOrmCacheDriverNode(string $name) : ArrayNodeDefinition { $treeBuilder = new TreeBuilder($name); $node = $treeBuilder->getRootNode(); @@ -673,10 +661,8 @@ private function getOrmCacheDriverNode($name) /** * Find proxy auto generate modes for their names and int values - * - * @return array */ - private function getAutoGenerateModes() + private function getAutoGenerateModes() : array { $constPrefix = 'AUTOGENERATE_'; $prefixLen = strlen($constPrefix); diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index 1a95a72a6..223eaa4d3 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -760,10 +760,8 @@ protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $c /** * Loads a property info extractor for each defined entity manager. - * - * @param string $entityManagerName */ - private function loadPropertyInfoExtractor($entityManagerName, ContainerBuilder $container) + private function loadPropertyInfoExtractor(string $entityManagerName, ContainerBuilder $container) : void { $propertyExtractorDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.property_info_extractor', $entityManagerName), DoctrineExtractor::class); $argumentId = sprintf('doctrine.orm.%s_entity_manager', $entityManagerName); diff --git a/ManagerConfigurator.php b/ManagerConfigurator.php index 6143890a8..c65055d64 100644 --- a/ManagerConfigurator.php +++ b/ManagerConfigurator.php @@ -13,12 +13,12 @@ class ManagerConfigurator /** @var string[] */ private $enabledFilters = []; - /** @var string[] */ + /** @var array> */ private $filtersParameters = []; /** - * @param string[] $enabledFilters - * @param string[] $filtersParameters + * @param string[] $enabledFilters + * @param array> $filtersParameters */ public function __construct(array $enabledFilters, array $filtersParameters) { @@ -37,7 +37,7 @@ public function configure(EntityManagerInterface $entityManager) /** * Enables filters for a given entity manager */ - private function enableFilters(EntityManagerInterface $entityManager) + private function enableFilters(EntityManagerInterface $entityManager) : void { if (empty($this->enabledFilters)) { return; @@ -56,11 +56,8 @@ private function enableFilters(EntityManagerInterface $entityManager) /** * Sets default parameters for a given filter - * - * @param string $name Filter name - * @param SQLFilter $filter Filter object */ - private function setFilterParameters($name, SQLFilter $filter) + private function setFilterParameters(string $name, SQLFilter $filter) : void { if (empty($this->filtersParameters[$name])) { return; diff --git a/Mapping/DisconnectedMetadataFactory.php b/Mapping/DisconnectedMetadataFactory.php index 163259df9..5cd986b42 100644 --- a/Mapping/DisconnectedMetadataFactory.php +++ b/Mapping/DisconnectedMetadataFactory.php @@ -126,15 +126,9 @@ public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadat /** * Get a base path for a class * - * @param string $name class name - * @param string $namespace class namespace - * @param string $path class path - * - * @return string - * * @throws RuntimeException When base path not found. */ - private function getBasePathForClass($name, $namespace, $path) + private function getBasePathForClass(string $name, string $namespace, string $path) : string { $namespace = str_replace('\\', '/', $namespace); $search = str_replace('\\', '/', $path); @@ -147,12 +141,7 @@ private function getBasePathForClass($name, $namespace, $path) return $destination; } - /** - * @param string $namespace - * - * @return ClassMetadataCollection - */ - private function getMetadataForNamespace($namespace) + private function getMetadataForNamespace(string $namespace) : ClassMetadataCollection { $metadata = []; foreach ($this->getAllMetadata() as $m) { @@ -166,12 +155,7 @@ private function getMetadataForNamespace($namespace) return new ClassMetadataCollection($metadata); } - /** - * @param string $entity - * - * @return ClassMetadataCollection - */ - private function getMetadataForClass($entity) + private function getMetadataForClass(string $entity) : ClassMetadataCollection { foreach ($this->registry->getManagers() as $em) { $cmf = new DisconnectedClassMetadataFactory(); @@ -188,7 +172,7 @@ private function getMetadataForClass($entity) /** * @return ClassMetadata[] */ - private function getAllMetadata() + private function getAllMetadata() : array { $metadata = []; foreach ($this->registry->getManagers() as $em) { diff --git a/Repository/ContainerRepositoryFactory.php b/Repository/ContainerRepositoryFactory.php index b16427b5c..e1ace3143 100644 --- a/Repository/ContainerRepositoryFactory.php +++ b/Repository/ContainerRepositoryFactory.php @@ -39,7 +39,7 @@ public function __construct(ContainerInterface $container = null) /** * {@inheritdoc} */ - public function getRepository(EntityManagerInterface $entityManager, $entityName) + public function getRepository(EntityManagerInterface $entityManager, $entityName) : ObjectRepository { $metadata = $entityManager->getClassMetadata($entityName); $repositoryServiceId = $metadata->customRepositoryClassName; @@ -72,8 +72,10 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName return $this->getOrCreateRepository($entityManager, $metadata); } - private function getOrCreateRepository(EntityManagerInterface $entityManager, ClassMetadata $metadata) - { + private function getOrCreateRepository( + EntityManagerInterface $entityManager, + ClassMetadata $metadata + ) : ObjectRepository { $repositoryHash = $metadata->getName() . spl_object_hash($entityManager); if (isset($this->managedRepositories[$repositoryHash])) { return $this->managedRepositories[$repositoryHash]; diff --git a/Tests/Builder/BundleConfigurationBuilder.php b/Tests/Builder/BundleConfigurationBuilder.php index 234349289..670f57c93 100644 --- a/Tests/Builder/BundleConfigurationBuilder.php +++ b/Tests/Builder/BundleConfigurationBuilder.php @@ -21,7 +21,7 @@ public static function createBuilderWithBaseValues() return $builder; } - public function addBaseConnection() + public function addBaseConnection() : self { $this->addConnection([ 'connections' => [ @@ -32,7 +32,7 @@ public function addBaseConnection() return $this; } - public function addBaseEntityManager() + public function addBaseEntityManager() : self { $this->addEntityManager([ 'default_entity_manager' => 'default', @@ -48,7 +48,7 @@ public function addBaseEntityManager() return $this; } - public function addBaseSecondLevelCache() + public function addBaseSecondLevelCache() : self { $this->addSecondLevelCache([ 'region_cache_driver' => ['type' => 'pool', 'pool' => 'my_pool'], @@ -60,28 +60,28 @@ public function addBaseSecondLevelCache() return $this; } - public function addConnection($config) + public function addConnection($config) : self { $this->configuration['dbal'] = $config; return $this; } - public function addEntityManager($config) + public function addEntityManager($config) : self { $this->configuration['orm'] = $config; return $this; } - public function addSecondLevelCache($config, $manager = 'default') + public function addSecondLevelCache($config, $manager = 'default') : self { $this->configuration['orm']['entity_managers'][$manager]['second_level_cache'] = $config; return $this; } - public function build() + public function build() : array { return $this->configuration; } diff --git a/Tests/Command/CreateDatabaseDoctrineTest.php b/Tests/Command/CreateDatabaseDoctrineTest.php index d33c2b291..b3ea8e586 100644 --- a/Tests/Command/CreateDatabaseDoctrineTest.php +++ b/Tests/Command/CreateDatabaseDoctrineTest.php @@ -3,8 +3,8 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests\Command; use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -86,12 +86,9 @@ public function testExecuteWithShardOption() : void } /** - * @param string $connectionName Connection name - * @param mixed[]|null $params Connection parameters - * - * @return PHPUnit_Framework_MockObject_MockObject + * @param mixed[]|null $params Connection parameters */ - private function getMockContainer($connectionName, $params = null) + private function getMockContainer(string $connectionName, array $params = null) : MockObject { // Mock the container and everything you'll need here $mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry') diff --git a/Tests/Command/DropDatabaseDoctrineTest.php b/Tests/Command/DropDatabaseDoctrineTest.php index e3ba8650c..010f598d8 100644 --- a/Tests/Command/DropDatabaseDoctrineTest.php +++ b/Tests/Command/DropDatabaseDoctrineTest.php @@ -3,8 +3,8 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests\Command; use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -75,12 +75,9 @@ public function testExecuteWithoutOptionForceWillFailWithAttentionMessage() : vo } /** - * @param string $connectionName Connection name - * @param array|null $params Connection parameters - * - * @return PHPUnit_Framework_MockObject_MockObject + * @param array|null $params Connection parameters */ - private function getMockContainer($connectionName, $params = null) + private function getMockContainer(string $connectionName, array $params = null) : MockObject { // Mock the container and everything you'll need here $mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry') diff --git a/Tests/ConnectionFactoryTest.php b/Tests/ConnectionFactoryTest.php index bbb44a230..b112447b5 100644 --- a/Tests/ConnectionFactoryTest.php +++ b/Tests/ConnectionFactoryTest.php @@ -89,7 +89,7 @@ class FakeDriver implements Driver * * @link https://github.com/doctrine/DoctrineBundle/issues/673 */ - public function getDatabasePlatform() + public function getDatabasePlatform() : AbstractPlatform { if (self::$exception !== null) { throw self::$exception; @@ -116,12 +116,12 @@ public function getSchemaManager(Connection $conn) : void throw new Exception('not implemented'); } - public function getName() + public function getName() : string { return 'FakeDriver'; } - public function getDatabase(Connection $conn) + public function getDatabase(Connection $conn) : string { return 'fake_db'; } diff --git a/Tests/DataCollector/DoctrineDataCollectorTest.php b/Tests/DataCollector/DoctrineDataCollectorTest.php index 4c4b5f518..d4c81762a 100644 --- a/Tests/DataCollector/DoctrineDataCollectorTest.php +++ b/Tests/DataCollector/DoctrineDataCollectorTest.php @@ -86,12 +86,7 @@ public function testGetGroupedQueries() : void $this->assertSame(1, $groupedQueries['default'][1]['count']); } - /** - * @param string $entityFQCN - * - * @return ClassMetadataInfo - */ - private function createEntityMetadata($entityFQCN) + private function createEntityMetadata(string $entityFQCN) : ClassMetadataInfo { $metadata = new ClassMetadataInfo($entityFQCN); $metadata->name = $entityFQCN; @@ -100,12 +95,7 @@ private function createEntityMetadata($entityFQCN) return $metadata; } - /** - * @param array $managers - * - * @return DoctrineDataCollector - */ - private function createCollector(array $managers) + private function createCollector(array $managers) : DoctrineDataCollector { $registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock(); $registry diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 1857a3d90..8c0ddf09e 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -23,7 +23,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase { - abstract protected function loadFromFile(ContainerBuilder $container, $file); + abstract protected function loadFromFile(ContainerBuilder $container, string $file) : void; public function testDbalLoadFromXmlMultipleConnections() : void { @@ -1019,8 +1019,11 @@ public function testRepositoryFactory() : void $this->assertDICDefinitionMethodCallOnce($definition, 'setRepositoryFactory', ['repository_factory']); } - private function loadContainer($fixture, array $bundles = ['YamlBundle'], CompilerPassInterface $compilerPass = null) - { + private function loadContainer( + string $fixture, + array $bundles = ['YamlBundle'], + CompilerPassInterface $compilerPass = null + ) : ContainerBuilder { $container = $this->getContainer($bundles); $container->registerExtension(new DoctrineExtension()); @@ -1035,7 +1038,7 @@ private function loadContainer($fixture, array $bundles = ['YamlBundle'], Compil return $container; } - private function getContainer(array $bundles) + private function getContainer(array $bundles) : ContainerBuilder { $map = []; foreach ($bundles as $bundle) { @@ -1065,21 +1068,23 @@ private function getContainer(array $bundles) /** * Assertion on the Class of a DIC Service Definition. - * - * @param string $expectedClass */ - private function assertDICDefinitionClass(Definition $definition, $expectedClass) : void + private function assertDICDefinitionClass(Definition $definition, string $expectedClass) : void { $this->assertEquals($expectedClass, $definition->getClass(), 'Expected Class of the DIC Container Service Definition is wrong.'); } - private function assertDICConstructorArguments(Definition $definition, $args) : void + private function assertDICConstructorArguments(Definition $definition, array $args) : void { $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '" . $definition->getClass() . "' don't match."); } - private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $methodName, array $params = null) : void - { + private function assertDICDefinitionMethodCallAt( + int $pos, + Definition $definition, + string $methodName, + array $params = null + ) : void { $calls = $definition->getMethodCalls(); if (! isset($calls[$pos][0])) { $this->fail(sprintf('Method call at position %s not found!', $pos)); @@ -1098,12 +1103,12 @@ private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $ /** * Assertion for the DI Container, check if the given definition contains a method call with the given parameters. - * - * @param string $methodName - * @param array $params */ - private function assertDICDefinitionMethodCallOnce(Definition $definition, $methodName, array $params = null) : void - { + private function assertDICDefinitionMethodCallOnce( + Definition $definition, + string $methodName, + array $params = null + ) : void { $calls = $definition->getMethodCalls(); $called = false; foreach ($calls as $call) { @@ -1127,8 +1132,12 @@ private function assertDICDefinitionMethodCallOnce(Definition $definition, $meth $this->fail("Method '" . $methodName . "' is expected to be called once, definition does not contain a call though."); } - private function assertDICDefinitionMethodCallCount(Definition $definition, $methodName, array $params = [], $nbCalls = 1) : void - { + private function assertDICDefinitionMethodCallCount( + Definition $definition, + string $methodName, + array $params = [], + int $nbCalls = 1 + ) : void { $calls = $definition->getMethodCalls(); $called = 0; foreach ($calls as $call) { @@ -1151,12 +1160,12 @@ private function assertDICDefinitionMethodCallCount(Definition $definition, $met /** * Assertion for the DI Container, check if the given definition does not contain a method call with the given parameters. - * - * @param string $methodName - * @param array $params */ - private function assertDICDefinitionNoMethodCall(Definition $definition, $methodName, array $params = null) : void - { + private function assertDICDefinitionNoMethodCall( + Definition $definition, + string $methodName, + array $params = null + ) : void { $calls = $definition->getMethodCalls(); foreach ($calls as $call) { if ($call[0] !== $methodName) { diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index 54aa6a5f5..231c6f294 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -107,7 +107,7 @@ public function testOrmRequiresDbal() : void $extension->load([['orm' => ['auto_mapping' => true]]], $this->getContainer()); } - public function getAutomappingConfigurations() + public function getAutomappingConfigurations() : array { return [ [ @@ -810,7 +810,7 @@ public function testShardManager() : void $this->assertFalse($container->hasDefinition('doctrine.dbal.bar_shard_manager')); } - private function getContainer($bundles = 'YamlBundle', $vendor = null) + private function getContainer($bundles = 'YamlBundle', $vendor = null) : ContainerBuilder { $bundles = (array) $bundles; @@ -843,7 +843,7 @@ private function assertDICConstructorArguments(Definition $definition, array $ar $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '" . $definition->getClass() . "' don't match."); } - private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $methodName, array $params = null) : void + private function assertDICDefinitionMethodCallAt(int $pos, Definition $definition, string $methodName, array $params = null) : void { $calls = $definition->getMethodCalls(); if (! isset($calls[$pos][0])) { @@ -861,11 +861,8 @@ private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $ /** * Assertion for the DI Container, check if the given definition contains a method call with the given parameters. - * - * @param string $methodName - * @param array|null $params */ - private function assertDICDefinitionMethodCallOnce(Definition $definition, $methodName, array $params = null) : void + private function assertDICDefinitionMethodCallOnce(Definition $definition, string $methodName, array $params = null) : void { $calls = $definition->getMethodCalls(); $called = false; diff --git a/Tests/DependencyInjection/TestDatetimeFunction.php b/Tests/DependencyInjection/TestDatetimeFunction.php index ed306f7d6..b761ff5aa 100644 --- a/Tests/DependencyInjection/TestDatetimeFunction.php +++ b/Tests/DependencyInjection/TestDatetimeFunction.php @@ -8,13 +8,13 @@ class TestDatetimeFunction extends FunctionNode { - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker) : string { return ''; } - public function parse(Parser $parser) + public function parse(Parser $parser) : void { - return ''; + return; } } diff --git a/Tests/DependencyInjection/TestNumericFunction.php b/Tests/DependencyInjection/TestNumericFunction.php index e19e4c888..3647d852e 100644 --- a/Tests/DependencyInjection/TestNumericFunction.php +++ b/Tests/DependencyInjection/TestNumericFunction.php @@ -8,13 +8,13 @@ class TestNumericFunction extends FunctionNode { - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker) : string { return ''; } - public function parse(Parser $parser) + public function parse(Parser $parser) : void { - return ''; + return; } } diff --git a/Tests/DependencyInjection/TestStringFunction.php b/Tests/DependencyInjection/TestStringFunction.php index 5275141cd..6306360c2 100644 --- a/Tests/DependencyInjection/TestStringFunction.php +++ b/Tests/DependencyInjection/TestStringFunction.php @@ -8,13 +8,13 @@ class TestStringFunction extends FunctionNode { - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker) : string { return ''; } - public function parse(Parser $parser) + public function parse(Parser $parser) : void { - return ''; + return; } } diff --git a/Tests/DependencyInjection/TestType.php b/Tests/DependencyInjection/TestType.php index ca06877df..0d598e7d3 100644 --- a/Tests/DependencyInjection/TestType.php +++ b/Tests/DependencyInjection/TestType.php @@ -7,12 +7,12 @@ class TestType extends Type { - public function getName() + public function getName() : string { return 'test'; } - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string { return ''; } diff --git a/Tests/DependencyInjection/XmlDoctrineExtensionTest.php b/Tests/DependencyInjection/XmlDoctrineExtensionTest.php index 6eb249cd9..8efab7648 100644 --- a/Tests/DependencyInjection/XmlDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/XmlDoctrineExtensionTest.php @@ -8,7 +8,7 @@ class XmlDoctrineExtensionTest extends AbstractDoctrineExtensionTest { - protected function loadFromFile(ContainerBuilder $container, $file) : void + protected function loadFromFile(ContainerBuilder $container, string $file) : void { $loadXml = new XmlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures/config/xml')); $loadXml->load($file . '.xml'); diff --git a/Tests/DependencyInjection/YamlDoctrineExtensionTest.php b/Tests/DependencyInjection/YamlDoctrineExtensionTest.php index 487050e48..24c950a84 100644 --- a/Tests/DependencyInjection/YamlDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/YamlDoctrineExtensionTest.php @@ -8,7 +8,7 @@ class YamlDoctrineExtensionTest extends AbstractDoctrineExtensionTest { - protected function loadFromFile(ContainerBuilder $container, $file) : void + protected function loadFromFile(ContainerBuilder $container, string $file) : void { $loadYaml = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures/config/yml')); $loadYaml->load($file . '.yml'); diff --git a/Tests/Repository/ContainerRepositoryFactoryTest.php b/Tests/Repository/ContainerRepositoryFactoryTest.php index 92623d6f9..07b5bd799 100644 --- a/Tests/Repository/ContainerRepositoryFactoryTest.php +++ b/Tests/Repository/ContainerRepositoryFactoryTest.php @@ -9,6 +9,7 @@ use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Persistence\ObjectRepository; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; @@ -111,7 +112,7 @@ public function testCustomRepositoryIsNotAValidClass() : void $factory->getRepository($em, 'Foo\CoolEntity'); } - private function createContainer(array $services) + private function createContainer(array $services) : MockObject { $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); $container->expects($this->any()) @@ -128,7 +129,7 @@ private function createContainer(array $services) return $container; } - private function createEntityManager(array $entityRepositoryClasses) + private function createEntityManager(array $entityRepositoryClasses) : MockObject { $classMetadatas = []; foreach ($entityRepositoryClasses as $entityClass => $entityRepositoryClass) { diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 0d6f47f4e..456ff1513 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -15,7 +15,7 @@ class TestCase extends BaseTestCase { - public function createXmlBundleTestContainer() + public function createXmlBundleTestContainer() : ContainerBuilder { $container = new ContainerBuilder(new ParameterBag([ 'kernel.name' => 'app', diff --git a/Tests/Twig/DoctrineExtensionTest.php b/Tests/Twig/DoctrineExtensionTest.php index 13328dbf8..3d8f739aa 100644 --- a/Tests/Twig/DoctrineExtensionTest.php +++ b/Tests/Twig/DoctrineExtensionTest.php @@ -94,12 +94,12 @@ class DummyClass /** @var string */ protected $str; - public function __construct($str) + public function __construct(string $str) { $this->str = $str; } - public function __toString() + public function __toString() : string { return $this->str; } diff --git a/Twig/DoctrineExtension.php b/Twig/DoctrineExtension.php index b06ac94c9..997130997 100644 --- a/Twig/DoctrineExtension.php +++ b/Twig/DoctrineExtension.php @@ -27,13 +27,8 @@ public function getFilters() /** * Get the possible combinations of elements from the given array - * - * @param array $elements - * @param int $combinationsLevel - * - * @return array */ - private function getPossibleCombinations(array $elements, $combinationsLevel) + private function getPossibleCombinations(array $elements, int $combinationsLevel) : array { $baseCount = count($elements); $result = [];