Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 49 |
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 |
||
153 | protected function assertSspAssetSearchData(array $data, SspAssetTransfer $sspAssetTransfer): void |
||
154 | { |
||
155 | $this->assertArrayHasKey(SspAssetIndexMap::TYPE, $data); |
||
156 | $this->assertArrayHasKey(SspAssetIndexMap::SEARCH_RESULT_DATA, $data); |
||
157 | $this->assertArrayHasKey(SspAssetIndexMap::FULL_TEXT_BOOSTED, $data); |
||
158 | $this->assertArrayHasKey(SspAssetIndexMap::SUGGESTION_TERMS, $data); |
||
159 | $this->assertArrayHasKey(SspAssetIndexMap::COMPLETION_TERMS, $data); |
||
160 | $this->assertArrayHasKey(SspAssetIndexMap::STORE, $data); |
||
161 | $this->assertArrayHasKey(SspAssetIndexMap::BUSINESS_UNIT_IDS, $data); |
||
162 | $this->assertArrayHasKey(SspAssetIndexMap::COMPANY_IDS, $data); |
||
163 | $this->assertArrayHasKey(SspAssetIndexMap::ID_OWNER_BUSINESS_UNIT, $data); |
||
164 | $this->assertArrayHasKey(SspAssetIndexMap::ID_OWNER_COMPANY_ID, $data); |
||
165 | |||
166 | $this->assertSame(SelfServicePortalConfig::SSP_ASSET_RESOURCE_NAME, $data[SspAssetIndexMap::TYPE]); |
||
167 | $this->assertSame([ |
||
168 | 'name' => $sspAssetTransfer->getName(), |
||
169 | 'serial_number' => $sspAssetTransfer->getSerialNumber(), |
||
170 | 'model_ids' => array_map(fn (SspModelTransfer $sspModel) => $sspModel->getIdSspModel(), $sspAssetTransfer->getSspModels()->getArrayCopy()), |
||
171 | 'busines_unit_ids' => array_map(fn (SspAssetBusinessUnitAssignmentTransfer $businessUnitAssignment) => $businessUnitAssignment->getCompanyBusinessUnitOrFail()->getIdCompanyBusinessUnitOrFail(), $sspAssetTransfer->getBusinessUnitAssignments()->getArrayCopy()), |
||
172 | 'company_ids' => array_map(fn (SspAssetBusinessUnitAssignmentTransfer $businessUnitAssignment) => $businessUnitAssignment->getCompanyBusinessUnitOrFail()->getFkCompanyOrFail(), $sspAssetTransfer->getBusinessUnitAssignments()->getArrayCopy()), |
||
173 | 'id_owner_business_unit' => $sspAssetTransfer->getCompanyBusinessUnit()?->getIdCompanyBusinessUnitOrFail(), |
||
174 | 'id_owner_company_id' => $sspAssetTransfer->getCompanyBusinessUnit()?->getFkCompany(), |
||
175 | ], $data[SspAssetIndexMap::SEARCH_RESULT_DATA]); |
||
176 | |||
177 | $this->assertSame([static::STORE_NAME_UF, static::STORE_NAME_LO], $data[SspAssetIndexMap::STORE]); |
||
178 | |||
179 | $assignedBusinessUnitIds = array_map( |
||
180 | fn (SspAssetBusinessUnitAssignmentTransfer $businessUnitAssignment) => $businessUnitAssignment->getCompanyBusinessUnitOrFail()->getIdCompanyBusinessUnitOrFail(), |
||
181 | $sspAssetTransfer->getBusinessUnitAssignments()->getArrayCopy(), |
||
182 | ); |
||
183 | |||
184 | $assignedCompanyIds = array_map( |
||
185 | fn (SspAssetBusinessUnitAssignmentTransfer $businessUnitAssignment) => $businessUnitAssignment->getCompanyBusinessUnitOrFail()->getFkCompany(), |
||
186 | $sspAssetTransfer->getBusinessUnitAssignments()->getArrayCopy(), |
||
187 | ); |
||
188 | |||
189 | $this->assertSame($assignedBusinessUnitIds, $data[SspAssetIndexMap::BUSINESS_UNIT_IDS]); |
||
190 | $this->assertSame($assignedCompanyIds, $data[SspAssetIndexMap::COMPANY_IDS]); |
||
191 | $this->assertSame($sspAssetTransfer->getCompanyBusinessUnit()?->getIdCompanyBusinessUnitOrFail(), $data[SspAssetIndexMap::ID_OWNER_BUSINESS_UNIT]); |
||
192 | $this->assertSame($sspAssetTransfer->getCompanyBusinessUnit()?->getFkCompany(), $data[SspAssetIndexMap::ID_OWNER_COMPANY_ID]); |
||
193 | |||
194 | $sspModelNames = array_map(fn (SspModelTransfer $sspModel) => $sspModel->getName(), $sspAssetTransfer->getSspModels()->getArrayCopy()); |
||
195 | |||
196 | $this->assertSame(array_filter([ |
||
197 | $sspAssetTransfer->getName(), |
||
198 | ...$sspModelNames, |
||
199 | $sspAssetTransfer->getSerialNumber(), |
||
200 | ]), $data[SspAssetIndexMap::FULL_TEXT_BOOSTED]); |
||
201 | |||
202 | $this->assertSame(array_filter([ |
||
203 | $sspAssetTransfer->getName(), |
||
204 | ...$sspModelNames, |
||
205 | ]), $data[SspAssetIndexMap::SUGGESTION_TERMS]); |
||
206 | |||
207 | $this->assertSame(array_filter([ |
||
208 | $sspAssetTransfer->getName(), |
||
209 | ...$sspModelNames, |
||
210 | ]), $data[SspAssetIndexMap::COMPLETION_TERMS]); |
||
211 | |||
212 | $this->assertSame($assignedBusinessUnitIds, $data[SspAssetIndexMap::BUSINESS_UNIT_IDS]); |
||
213 | $this->assertSame($assignedCompanyIds, $data[SspAssetIndexMap::COMPANY_IDS]); |
||
214 | $this->assertSame($sspAssetTransfer->getCompanyBusinessUnit()?->getIdCompanyBusinessUnitOrFail(), $data[SspAssetIndexMap::ID_OWNER_BUSINESS_UNIT]); |
||
215 | $this->assertSame($sspAssetTransfer->getCompanyBusinessUnit()?->getFkCompany(), $data[SspAssetIndexMap::ID_OWNER_COMPANY_ID]); |
||
216 | } |
||
218 |