Conditions | 2 |
Paths | 2 |
Total Lines | 53 |
Code Lines | 41 |
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 |
||
44 | public function testBuildListFields(): JoinMapper |
||
45 | { |
||
46 | $paths = [ |
||
47 | [['prop'], false], |
||
48 | [['entity1.prop'], true], |
||
49 | [['entity1.prop2'], false], |
||
50 | [['entity1.entity2.prop', 'entity1.entity2.prop2'], true], |
||
51 | [['entity3.entity4.entity5.prop', 'entity3.prop'], false] |
||
52 | ]; |
||
53 | $fields = []; |
||
54 | |||
55 | foreach ($paths as $path) { |
||
56 | $field = $this->createMock(ListField::class); |
||
57 | $field->expects($this->exactly(5)) |
||
58 | ->method('getOption') |
||
59 | ->willReturnMap([ |
||
60 | ['join_type', null, 'INNER'], |
||
61 | ['sortable', null, true], |
||
62 | ['sort_value', null, 'ASC'], |
||
63 | ['sort_path', null, 'custom_path'], |
||
64 | ['lazy', null, $path[1]] |
||
65 | ]); |
||
66 | $field->expects($this->once()) |
||
67 | ->method('getPaths') |
||
68 | ->willReturn($path[0]); |
||
69 | |||
70 | $fields[] = $field; |
||
71 | } |
||
72 | |||
73 | $listMapperMock = $this->createMock(ListMapper::class); |
||
74 | $listMapperMock->expects($this->once()) |
||
75 | ->method('getFields') |
||
76 | ->willReturn(new ArrayCollection($fields)); |
||
77 | |||
78 | $filterMapperMock = $this->createMock(FilterMapper::class); |
||
79 | $filterMapperMock->expects($this->once()) |
||
80 | ->method('getFields') |
||
81 | ->willReturn(new ArrayCollection([])); |
||
82 | |||
83 | $mapper = new JoinMapper($listMapperMock, $filterMapperMock); |
||
84 | $mapper->build(); |
||
85 | |||
86 | $this->assertCount(6, $mapper->getFields()); |
||
87 | $this->assertCount(2, $mapper->getFields(true)); |
||
88 | $this->assertCount(4, $mapper->getFields(false)); |
||
89 | $this->assertEquals('a.entity1', $mapper->getByPath('entity1', true)->getJoinPath('a')); |
||
90 | $this->assertEquals('a.entity1', $mapper->getByPath('entity1', false)->getJoinPath('a')); |
||
91 | $this->assertEquals('entity1_a.entity2', $mapper->getByPath('entity1.entity2', true)->getJoinPath('a')); |
||
92 | $this->assertEquals('a.entity3', $mapper->getByPath('entity3', false)->getJoinPath('a')); |
||
93 | $this->assertEquals('entity3_a.entity4', $mapper->getByPath('entity3.entity4', false)->getJoinPath('a')); |
||
94 | $this->assertEquals('entity3_entity4_a.entity5', $mapper->getByPath('entity3.entity4.entity5', false)->getJoinPath('a')); |
||
95 | |||
96 | return $mapper; |
||
97 | } |
||
179 |