Conditions | 4 |
Paths | 8 |
Total Lines | 76 |
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->getBody(), true); |
||
26 | |||
27 | if (!isset($mainFolderContent['Content']['MainLocation']['_href'])) { |
||
28 | self::fail("Incomplete response (no main location):\n" . $response->getBody() . "\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 | </LocationQuery> |
||
63 | </ViewInput> |
||
64 | XML; |
||
65 | $request = $this->createHttpRequest( |
||
66 | 'POST', |
||
67 | '/api/ezp/v2/views', |
||
68 | 'ViewInput+xml; version=1.1', |
||
69 | 'View+xml', |
||
70 | $body |
||
71 | ); |
||
72 | |||
73 | $response = $this->sendHttpRequest( |
||
74 | $request |
||
75 | ); |
||
76 | |||
77 | self::assertHttpResponseCodeEquals($response, 200); |
||
78 | $xml = new SimpleXMLElement($response->getBody()); |
||
79 | |||
80 | $searchHits = []; |
||
81 | foreach ($xml->xpath('//Name') as $searchHit) { |
||
82 | $searchHits[] = (string) $searchHit[0]; |
||
83 | } |
||
84 | |||
85 | self::assertCount(3, $searchHits); |
||
86 | self::assertEquals($foldersNames['CCC'], $searchHits[0]); |
||
87 | self::assertEquals($foldersNames['BBB'], $searchHits[1]); |
||
88 | self::assertEquals($foldersNames['AAA'], $searchHits[2]); |
||
89 | } |
||
90 | } |
||
91 |