| Conditions | 4 |
| Paths | 8 |
| Total Lines | 73 |
| 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 |
||
| 14 | public function testFieldSortClause() |
||
| 15 | { |
||
| 16 | $string = $this->addTestSuffix(__FUNCTION__); |
||
| 17 | $mainTestFolderContent = $this->createFolder($string, '/api/ezp/v2/content/locations/1/2'); |
||
| 18 | |||
| 19 | $response = $this->sendHttpRequest( |
||
| 20 | $this->createHttpRequest('GET', $mainTestFolderContent['_href'], '', 'Content+json') |
||
| 21 | ); |
||
| 22 | |||
| 23 | self::assertHttpResponseCodeEquals($response, 200); |
||
| 24 | |||
| 25 | $mainFolderContent = json_decode($response->getContent(), true); |
||
| 26 | |||
| 27 | if (!isset($mainFolderContent['Content']['MainLocation']['_href'])) { |
||
| 28 | self::fail("Incomplete response (no main location):\n" . $response->getContent() . "\n"); |
||
| 29 | } |
||
| 30 | |||
| 31 | $mainFolderLocationHref = $mainFolderContent['Content']['MainLocation']['_href']; |
||
| 32 | |||
| 33 | $locationArray = explode('/', $mainFolderLocationHref); |
||
| 34 | $mainFolderLocationId = array_pop($locationArray); |
||
| 35 | |||
| 36 | $foldersForSorting = [ |
||
| 37 | 'AAA', |
||
| 38 | 'BBB', |
||
| 39 | 'CCC', |
||
| 40 | ]; |
||
| 41 | |||
| 42 | $foldersNames = []; |
||
| 43 | |||
| 44 | foreach ($foldersForSorting as $folder) { |
||
| 45 | $folderContent = $this->createFolder($folder, $mainFolderLocationHref); |
||
| 46 | $foldersNames[$folder] = $folderContent['Name']; |
||
| 47 | } |
||
| 48 | |||
| 49 | $body = <<< XML |
||
| 50 | <?xml version="1.0" encoding="UTF-8"?> |
||
| 51 | <ViewInput> |
||
| 52 | <identifier>TestView</identifier> |
||
| 53 | <LocationQuery> |
||
| 54 | <Filter> |
||
| 55 | <ParentLocationIdCriterion>{$mainFolderLocationId}</ParentLocationIdCriterion> |
||
| 56 | </Filter> |
||
| 57 | <limit>10</limit> |
||
| 58 | <offset>0</offset> |
||
| 59 | <SortClauses> |
||
| 60 | <Field identifier="folder/name">descending</Field> |
||
| 61 | </SortClauses> |
||
| 62 | <FacetBuilders> |
||
| 63 | <contentTypeFacetBuilder/> |
||
| 64 | </FacetBuilders> |
||
| 65 | </LocationQuery> |
||
| 66 | </ViewInput> |
||
| 67 | XML; |
||
| 68 | $request = $this->createHttpRequest('POST', '/api/ezp/v2/content/views', 'ViewInput+xml; version=1.1', 'View+xml'); |
||
| 69 | $request->setContent($body); |
||
| 70 | |||
| 71 | $response = $this->sendHttpRequest( |
||
| 72 | $request |
||
| 73 | ); |
||
| 74 | |||
| 75 | $xml = new SimpleXMLElement($response->getContent()); |
||
| 76 | |||
| 77 | $searchHits = []; |
||
| 78 | foreach ($xml->xpath('//Name') as $searchHit) { |
||
| 79 | $searchHits[] = (string) $searchHit[0]; |
||
| 80 | } |
||
| 81 | |||
| 82 | self::assertCount(3, $searchHits); |
||
| 83 | self::assertEquals($foldersNames['CCC'], $searchHits[0]); |
||
| 84 | self::assertEquals($foldersNames['BBB'], $searchHits[1]); |
||
| 85 | self::assertEquals($foldersNames['AAA'], $searchHits[2]); |
||
| 86 | } |
||
| 87 | } |
||
| 88 |