Conditions | 6 |
Paths | 32 |
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 |
||
23 | public function testFieldSortClause(array $foldersNameToCreate, string $sortClauseXML, array $foldersInExpectedOrder) |
||
24 | { |
||
25 | $string = $this->addTestSuffix(__FUNCTION__); |
||
26 | $mainTestFolderContent = $this->createFolder($string, '/api/ezp/v2/content/locations/1/2'); |
||
27 | |||
28 | $response = $this->sendHttpRequest( |
||
29 | $this->createHttpRequest('GET', $mainTestFolderContent['_href'], '', 'Content+json') |
||
30 | ); |
||
31 | |||
32 | self::assertHttpResponseCodeEquals($response, 200); |
||
33 | |||
34 | $mainFolderContent = json_decode($response->getBody(), true); |
||
35 | |||
36 | if (!isset($mainFolderContent['Content']['MainLocation']['_href'])) { |
||
37 | self::fail("Incomplete response (no main location):\n" . $response->getBody() . "\n"); |
||
38 | } |
||
39 | |||
40 | $mainFolderLocationHref = $mainFolderContent['Content']['MainLocation']['_href']; |
||
41 | |||
42 | $locationArray = explode('/', $mainFolderLocationHref); |
||
43 | $mainFolderLocationId = array_pop($locationArray); |
||
44 | |||
45 | $foldersNames = []; |
||
46 | foreach ($foldersNameToCreate as $folder) { |
||
47 | $folderContent = $this->createFolder($folder, $mainFolderLocationHref); |
||
48 | $foldersNames[$folder] = $folderContent['Name']; |
||
49 | } |
||
50 | |||
51 | $sortedFoldersNames = []; |
||
52 | foreach ($foldersInExpectedOrder as $name) { |
||
53 | $sortedFoldersNames[] = $foldersNames[$name]; |
||
54 | } |
||
55 | |||
56 | $body = <<< XML |
||
57 | <?xml version="1.0" encoding="UTF-8"?> |
||
58 | <ViewInput> |
||
59 | <identifier>TestView</identifier> |
||
60 | <LocationQuery> |
||
61 | <Filter> |
||
62 | <ParentLocationIdCriterion>{$mainFolderLocationId}</ParentLocationIdCriterion> |
||
63 | </Filter> |
||
64 | <limit>10</limit> |
||
65 | <offset>0</offset> |
||
66 | <SortClauses> |
||
67 | $sortClauseXML |
||
68 | </SortClauses> |
||
69 | </LocationQuery> |
||
70 | </ViewInput> |
||
71 | XML; |
||
72 | $request = $this->createHttpRequest( |
||
73 | 'POST', |
||
74 | '/api/ezp/v2/views', |
||
75 | 'ViewInput+xml; version=1.1', |
||
76 | 'View+xml', |
||
77 | $body |
||
78 | ); |
||
79 | |||
80 | $response = $this->sendHttpRequest( |
||
81 | $request |
||
82 | ); |
||
83 | |||
84 | self::assertHttpResponseCodeEquals($response, 200); |
||
85 | $xml = new SimpleXMLElement($response->getBody()); |
||
86 | |||
87 | $searchHits = []; |
||
88 | foreach ($xml->xpath('//Name') as $searchHit) { |
||
89 | $searchHits[] = (string) $searchHit[0]; |
||
90 | } |
||
91 | |||
92 | $expectedCount = count($foldersInExpectedOrder); |
||
93 | self::assertCount($expectedCount, $searchHits); |
||
94 | |||
95 | for ($i = 0; $i <= $expectedCount - 1; ++$i) { |
||
96 | self::assertEquals($sortedFoldersNames[$i], $searchHits[$i]); |
||
97 | } |
||
98 | } |
||
99 | |||
132 |