Conditions | 1 |
Paths | 1 |
Total Lines | 76 |
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 |
||
28 | public function testRepositoryServiceWiring() |
||
29 | { |
||
30 | $container = new ContainerBuilder(new ParameterBag([ |
||
31 | 'kernel.name' => 'app', |
||
32 | 'kernel.debug' => false, |
||
33 | 'kernel.bundles' => ['RepositoryServiceBundle' => RepositoryServiceBundle::class], |
||
34 | 'kernel.cache_dir' => sys_get_temp_dir(), |
||
35 | 'kernel.environment' => 'test', |
||
36 | 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir |
||
37 | 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir |
||
38 | 'kernel.bundles_metadata' => [], |
||
39 | 'kernel.charset' => 'UTF-8', |
||
40 | 'kernel.container_class' => ContainerBuilder::class, |
||
41 | 'kernel.secret' => 'test', |
||
42 | 'container.build_id' => uniqid(), |
||
43 | 'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo', |
||
44 | ])); |
||
45 | $container->set('annotation_reader', new AnnotationReader()); |
||
46 | |||
47 | $extension = new FrameworkExtension(); |
||
48 | $container->registerExtension($extension); |
||
49 | $extension->load(['framework' => []], $container); |
||
50 | |||
51 | $extension = new DoctrineExtension(); |
||
52 | $container->registerExtension($extension); |
||
53 | $extension->load([[ |
||
54 | 'dbal' => [ |
||
55 | 'driver' => 'pdo_sqlite', |
||
56 | 'charset' => 'UTF8', |
||
57 | ], |
||
58 | 'orm' => [ |
||
59 | 'mappings' => [ |
||
60 | 'RepositoryServiceBundle' => [ |
||
61 | 'type' => 'annotation', |
||
62 | 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity', |
||
63 | 'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity', |
||
64 | ], |
||
65 | ], |
||
66 | ], |
||
67 | ], |
||
68 | ], $container); |
||
69 | |||
70 | $def = $container->register(TestCustomServiceRepoRepository::class, TestCustomServiceRepoRepository::class) |
||
71 | ->setPublic(false); |
||
72 | // create a public alias so we can use it below for testing |
||
73 | $container->setAlias('test_alias__' . TestCustomServiceRepoRepository::class, new Alias(TestCustomServiceRepoRepository::class, true)); |
||
74 | |||
75 | $def->setAutowired(true); |
||
76 | $def->setAutoconfigured(true); |
||
77 | |||
78 | $container->addCompilerPass(new ServiceRepositoryCompilerPass()); |
||
79 | $container->compile(); |
||
80 | |||
81 | $em = $container->get('doctrine.orm.default_entity_manager'); |
||
82 | |||
83 | // traditional custom class repository |
||
84 | $customClassRepo = $em->getRepository(TestCustomClassRepoEntity::class); |
||
85 | $this->assertInstanceOf(TestCustomClassRepoRepository::class, $customClassRepo); |
||
86 | // a smoke test, trying some methods |
||
87 | $this->assertSame(TestCustomClassRepoEntity::class, $customClassRepo->getClassName()); |
||
88 | $this->assertInstanceOf(QueryBuilder::class, $customClassRepo->createQueryBuilder('tc')); |
||
89 | |||
90 | // generic EntityRepository |
||
91 | $genericRepository = $em->getRepository(TestDefaultRepoEntity::class); |
||
92 | $this->assertInstanceOf(EntityRepository::class, $genericRepository); |
||
93 | $this->assertSame($genericRepository, $genericRepository = $em->getRepository(TestDefaultRepoEntity::class)); |
||
94 | // a smoke test, trying one of the methods |
||
95 | $this->assertSame(TestDefaultRepoEntity::class, $genericRepository->getClassName()); |
||
96 | |||
97 | // custom service repository |
||
98 | $customServiceRepo = $em->getRepository(TestCustomServiceRepoEntity::class); |
||
99 | $this->assertSame($customServiceRepo, $container->get('test_alias__' . TestCustomServiceRepoRepository::class)); |
||
100 | // a smoke test, trying some methods |
||
101 | $this->assertSame(TestCustomServiceRepoEntity::class, $customServiceRepo->getClassName()); |
||
102 | $this->assertInstanceOf(QueryBuilder::class, $customServiceRepo->createQueryBuilder('tc')); |
||
103 | } |
||
104 | } |
||
105 |