Conditions | 1 |
Paths | 1 |
Total Lines | 80 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 | protected function getEntityManager() |
||
29 | { |
||
30 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
||
31 | ->setMethods(array('getRepository', 'getClassMetadata', 'persist', 'flush', 'clear', 'getConnection', 'getReference')) |
||
32 | ->disableOriginalConstructor() |
||
33 | ->getMock(); |
||
34 | |||
35 | $repo = $this->getMockBuilder('Doctrine\ORM\EntityRepository') |
||
36 | ->disableOriginalConstructor() |
||
37 | ->getMock(); |
||
38 | |||
39 | $metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata') |
||
40 | ->setMethods(array('getName', 'getFieldNames', 'getAssociationNames', 'setFieldValue', 'getAssociationMappings')) |
||
41 | ->disableOriginalConstructor() |
||
42 | ->getMock(); |
||
43 | |||
44 | $metadata->expects($this->any()) |
||
45 | ->method('getName') |
||
46 | ->will($this->returnValue('Ddeboer\DataImport\Tests\Fixtures\Entity\TestEntity')); |
||
47 | |||
48 | $metadata->expects($this->any()) |
||
49 | ->method('getFieldNames') |
||
50 | ->will($this->returnValue(array('firstProperty', 'secondProperty'))); |
||
51 | |||
52 | $metadata->expects($this->any()) |
||
53 | ->method('getAssociationNames') |
||
54 | ->will($this->returnValue(array('firstAssociation'))); |
||
55 | |||
56 | $metadata->expects($this->any()) |
||
57 | ->method('getAssociationMappings') |
||
58 | ->will($this->returnValue(array(array('fieldName' => 'firstAssociation','targetEntity' => 'Ddeboer\DataImport\Tests\Fixtures\Entity\TestEntity')))); |
||
59 | |||
60 | $configuration = $this->getMockBuilder('Doctrine\DBAL\Configuration') |
||
61 | ->setMethods(array('getConnection')) |
||
62 | ->disableOriginalConstructor() |
||
63 | ->getMock(); |
||
64 | |||
65 | $connection = $this->getMockBuilder('Doctrine\DBAL\Connection') |
||
66 | ->setMethods(array('getConfiguration', 'getDatabasePlatform', 'getTruncateTableSQL', 'executeQuery')) |
||
67 | ->disableOriginalConstructor() |
||
68 | ->getMock(); |
||
69 | |||
70 | $connection->expects($this->any()) |
||
71 | ->method('getConfiguration') |
||
72 | ->will($this->returnValue($configuration)); |
||
73 | |||
74 | $connection->expects($this->any()) |
||
75 | ->method('getDatabasePlatform') |
||
76 | ->will($this->returnSelf()); |
||
77 | |||
78 | $connection->expects($this->any()) |
||
79 | ->method('getTruncateTableSQL') |
||
80 | ->will($this->returnValue('TRUNCATE SQL')); |
||
81 | |||
82 | $connection->expects($this->any()) |
||
83 | ->method('executeQuery') |
||
84 | ->with('TRUNCATE SQL'); |
||
85 | |||
86 | $em->expects($this->once()) |
||
87 | ->method('getRepository') |
||
88 | ->will($this->returnValue($repo)); |
||
89 | |||
90 | $em->expects($this->once()) |
||
91 | ->method('getClassMetadata') |
||
92 | ->will($this->returnValue($metadata)); |
||
93 | |||
94 | $em->expects($this->any()) |
||
95 | ->method('getConnection') |
||
96 | ->will($this->returnValue($connection)); |
||
97 | |||
98 | $self = $this; |
||
99 | $em->expects($this->any()) |
||
100 | ->method('persist') |
||
101 | ->will($this->returnCallback(function ($argument) use ($self) { |
||
102 | $self->assertNotNull($argument->getFirstAssociation()); |
||
103 | return true; |
||
104 | })); |
||
105 | |||
106 | return $em; |
||
107 | } |
||
108 | |||
167 |