Conditions | 10 |
Paths | 9 |
Total Lines | 40 |
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 |
||
94 | public function reorderAction(Request $request) |
||
95 | { |
||
96 | $parentPath = $request->get('parent'); |
||
97 | $dropedAtPath = $request->get('dropped'); |
||
98 | $targetPath = $request->get('target'); |
||
99 | $position = $request->get('position'); |
||
100 | |||
101 | if (null === $parentPath || null === $dropedAtPath || null === $targetPath) { |
||
102 | return new JsonResponse(['Parameters parent, dropped and target has to be set to reorder.'], Response::HTTP_BAD_REQUEST); |
||
103 | } |
||
104 | |||
105 | if (in_array($position, ['over', 'child'])) { |
||
106 | return new JsonResponse(['Can not reorder when dropping into a collection.'], Response::HTTP_BAD_REQUEST); |
||
107 | } |
||
108 | |||
109 | $before = 'before' == $position; |
||
110 | $parentNode = $this->session->getNode($parentPath); |
||
111 | $targetName = PathHelper::getNodeName($targetPath); |
||
112 | if (!$before) { |
||
113 | $nodesIterator = $parentNode->getNodes(); |
||
114 | $nodesIterator->rewind(); |
||
115 | while ($nodesIterator->valid()) { |
||
116 | if ($nodesIterator->key() == $targetName) { |
||
117 | break; |
||
118 | } |
||
119 | $nodesIterator->next(); |
||
120 | } |
||
121 | $targetName = null; |
||
122 | if ($nodesIterator->valid()) { |
||
123 | $nodesIterator->next(); |
||
124 | if ($nodesIterator->valid()) { |
||
125 | $targetName = $nodesIterator->key(); |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | $parentNode->orderBefore($targetName, PathHelper::getNodeName($dropedAtPath)); |
||
130 | $this->session->save(); |
||
131 | |||
132 | return new Response('', Response::HTTP_NO_CONTENT); |
||
133 | } |
||
134 | } |
||
135 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: