Conditions | 4 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 43 |
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 |
||
105 | private function getRowView(string $type, ?array $data, ?MockObject $listViewMock = null): RowView |
||
106 | { |
||
107 | $valueAccessor = $this->createMock(ValueAccessor::class); |
||
108 | $listViewMock = $listViewMock ?: $this->createMock(ListView::class); |
||
109 | $fieldViewMock = $this->createMock(FieldView::class); |
||
110 | $listViewMock->expects($this->once()) |
||
111 | ->method('getFieldViews') |
||
112 | ->willReturn([$fieldViewMock]); |
||
113 | $listFieldMock = $this->createMock(ListField::class); |
||
114 | $listFieldMock->expects($this->once()) |
||
115 | ->method('getId') |
||
116 | ->willReturn('id'); |
||
117 | $fieldViewMock->method('getListField') |
||
118 | ->willReturn($listFieldMock); |
||
119 | |||
120 | if ($type === 'body') { |
||
121 | $queryBuilderMock = $this->createMock(QueryBuilder::class); |
||
122 | $valueAccessor->expects($this->once()) |
||
123 | ->method('getFieldValue') |
||
124 | ->with($fieldViewMock, ['normalized' => 'data']) |
||
125 | ->willReturn('field'); |
||
126 | $valueAccessor->expects($this->once()) |
||
127 | ->method('normalizeData') |
||
128 | ->with($data, $queryBuilderMock) |
||
129 | ->willReturn(['normalized' => 'data']); |
||
130 | $fieldViewMock->method('getValue') |
||
131 | ->willReturn('field'); |
||
132 | } else { |
||
133 | $queryBuilderMock = null; |
||
134 | $valueAccessor->expects($this->once()) |
||
135 | ->method('getHeaderValue') |
||
136 | ->with($fieldViewMock) |
||
137 | ->willReturn('header'); |
||
138 | $listFieldMock->expects($this->once()) |
||
139 | ->method('setOption') |
||
140 | ->with('label', 'header'); |
||
141 | $fieldViewMock->method('getValue') |
||
142 | ->willReturn('header'); |
||
143 | } |
||
144 | |||
145 | $fieldViewMock->method('getLabel') |
||
146 | ->willReturn('header'); |
||
147 | |||
148 | $fieldViewMock->expects($this->once()) |
||
149 | ->method('init') |
||
150 | ->with($this->isInstanceOf(RowView::class), $type === 'body' ? 'field' : 'header'); |
||
151 | |||
152 | $rowView = new RowView($valueAccessor, $queryBuilderMock); |
||
153 | $rowView->init($listViewMock, $type, $data); |
||
154 | |||
155 | return $rowView; |
||
156 | } |
||
158 |