Conditions | 10 |
Paths | 24 |
Total Lines | 44 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
12 | public function view() |
||
13 | { |
||
14 | $database = Symphony::Configuration()->get('db', 'database'); |
||
15 | $field_ids = array_map(array('General','intval'), explode(',', General::sanitize($_GET['field_id']))); |
||
16 | $search = MySQL::cleanValue(General::sanitize($_GET['query'])); |
||
17 | $types = array_map(array('MySQL','cleanValue'), explode(',', General::sanitize($_GET['types']))); |
||
18 | $limit = General::intval(General::sanitize($_GET['limit'])); |
||
19 | |||
20 | // Set limit |
||
21 | if ($limit === 0) { |
||
22 | $max = ''; |
||
23 | } elseif ($limit < 0) { |
||
24 | $max = ' LIMIT 100'; |
||
25 | } else { |
||
26 | $max = sprintf(' LIMIT %d', $limit); |
||
27 | } |
||
28 | |||
29 | // Entries |
||
30 | if (in_array('entry', $types)) { |
||
31 | foreach ($field_ids as $field_id) { |
||
32 | $this->get($database, intval($field_id), $search, $max); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | // Associations |
||
37 | if (in_array('association', $types)) { |
||
38 | foreach ($field_ids as $field_id) { |
||
39 | $association_id = $this->getAssociationId($field_id); |
||
40 | |||
41 | if ($association_id) { |
||
42 | $this->get($database, $association_id, $search, $max); |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 | |||
47 | // Static values |
||
48 | if (in_array('static', $types)) { |
||
49 | foreach ($field_ids as $field_id) { |
||
50 | $this->getStatic($field_id, $search); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | // Return results |
||
55 | return $this->_Result; |
||
56 | } |
||
168 |
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
.