Conditions | 16 |
Paths | 37 |
Total Lines | 44 |
Code Lines | 31 |
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 |
||
18 | public function view() |
||
19 | { |
||
20 | $items = $_REQUEST['items']; |
||
21 | |||
22 | if (!is_array($items) || empty($items)) { |
||
23 | return; |
||
24 | } |
||
25 | |||
26 | $destination = self::kREORDER_UNKNOWN; |
||
27 | |||
28 | if ($this->_context[0] == 'blueprints' && $this->_context[1] == 'pages') { |
||
29 | $destination = self::kREORDER_PAGES; |
||
30 | } elseif ($this->_context[0] == 'blueprints' && $this->_context[1] == 'sections') { |
||
31 | $destination = self::kREORDER_SECTIONS; |
||
32 | } elseif ($this->_context[0] == 'extensions') { |
||
33 | $destination = self::kREORDER_EXTENSION; |
||
34 | } |
||
35 | |||
36 | switch ($destination) { |
||
37 | case self::kREORDER_PAGES: |
||
38 | foreach ($items as $id => $position) { |
||
39 | if (!PageManager::edit($id, array('sortorder' => $position))) { |
||
40 | $this->setHttpStatus(self::HTTP_STATUS_ERROR); |
||
41 | $this->_Result->setValue(__('A database error occurred while attempting to reorder.')); |
||
42 | break; |
||
43 | } |
||
44 | } |
||
45 | break; |
||
46 | case self::kREORDER_SECTIONS: |
||
47 | foreach ($items as $id => $position) { |
||
48 | if (!SectionManager::edit($id, array('sortorder' => $position))) { |
||
49 | $this->setHttpStatus(self::HTTP_STATUS_ERROR); |
||
50 | $this->_Result->setValue(__('A database error occurred while attempting to reorder.')); |
||
51 | break; |
||
52 | } |
||
53 | } |
||
54 | break; |
||
55 | case self::kREORDER_EXTENSION: |
||
56 | // TODO |
||
57 | break; |
||
58 | case self::kREORDER_UNKNOWN: |
||
59 | default: |
||
60 | $this->setHttpStatus(self::HTTP_STATUS_BAD_REQUEST); |
||
61 | break; |
||
62 | } |
||
65 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.