| Conditions | 2 |
| Paths | 2 |
| Total Lines | 53 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 43 | public function testRepositoryServiceWiring() |
||
| 44 | { |
||
| 45 | if (!class_exists(ServiceLocatorTagPass::class)) { |
||
| 46 | $this->markTestSkipped(); |
||
| 47 | } |
||
| 48 | |||
| 49 | $container = new ContainerBuilder(new ParameterBag(array( |
||
| 50 | 'kernel.name' => 'app', |
||
| 51 | 'kernel.debug' => false, |
||
| 52 | 'kernel.bundles' => array('RepositoryServiceBundle' => RepositoryServiceBundle::class), |
||
| 53 | 'kernel.cache_dir' => sys_get_temp_dir(), |
||
| 54 | 'kernel.environment' => 'test', |
||
| 55 | 'kernel.root_dir' => __DIR__.'/../../../../', // src dir |
||
| 56 | ))); |
||
| 57 | $container->set('annotation_reader', new AnnotationReader()); |
||
| 58 | $extension = new DoctrineExtension(); |
||
| 59 | $container->registerExtension($extension); |
||
| 60 | $extension->load(array(array( |
||
| 61 | 'dbal' => array( |
||
| 62 | 'driver' => 'pdo_mysql', |
||
| 63 | 'charset' => 'UTF8', |
||
| 64 | ), |
||
| 65 | 'orm' => array( |
||
| 66 | 'mappings' => array('RepositoryServiceBundle' => array( |
||
| 67 | 'type' => 'annotation', |
||
| 68 | 'dir' => __DIR__.'/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity', |
||
| 69 | 'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity', |
||
| 70 | )), |
||
| 71 | 'use_service_repositories' => true, |
||
| 72 | ), |
||
| 73 | )), $container); |
||
| 74 | |||
| 75 | $container->register(TestCustomRepoRepository::class) |
||
| 76 | ->setAutowired(true) |
||
| 77 | ->setPublic(false) |
||
| 78 | ->addTag('doctrine.repository_service'); |
||
| 79 | |||
| 80 | $container->getCompilerPassConfig()->addPass(new ServiceRepositoryCompilerPass()); |
||
| 81 | $container->compile(); |
||
| 82 | |||
| 83 | $em = $container->get('doctrine.orm.default_entity_manager'); |
||
| 84 | $customRepo = $em->getRepository(TestCustomRepoEntity::class); |
||
| 85 | $this->assertSame($customRepo, $container->get(TestCustomRepoRepository::class)); |
||
| 86 | // a smoke test, trying some methods |
||
| 87 | $this->assertSame(TestCustomRepoEntity::class, $customRepo->getClassName()); |
||
| 88 | $this->assertInstanceOf(QueryBuilder::class, $customRepo->createQueryBuilder('tc')); |
||
| 89 | |||
| 90 | $genericRepository = $em->getRepository(TestDefaultRepoEntity::class); |
||
| 91 | $this->assertInstanceOf(EntityRepository::class, $genericRepository); |
||
| 92 | $this->assertSame($genericRepository, $genericRepository = $em->getRepository(TestDefaultRepoEntity::class)); |
||
| 93 | // a smoke test, trying one of the methods |
||
| 94 | $this->assertSame(TestDefaultRepoEntity::class, $genericRepository->getClassName()); |
||
| 95 | } |
||
| 96 | } |
||
| 97 |