Conditions | 4 |
Paths | 6 |
Total Lines | 77 |
Code Lines | 39 |
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 |
||
25 | public function index() |
||
26 | { |
||
27 | // Settings |
||
28 | $query = $this->db->query(" |
||
29 | SELECT * |
||
30 | FROM setting |
||
31 | "); |
||
32 | |||
33 | foreach ($query->rows as $setting) { |
||
34 | if (!$setting['serialized']) { |
||
35 | $this->config->set( |
||
36 | $setting['key'], |
||
37 | $setting['value'] |
||
38 | ); |
||
39 | } else { |
||
40 | $this->config->set( |
||
41 | $setting['key'], |
||
42 | json_decode($setting['value'], true) |
||
43 | ); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | // Language |
||
48 | $query = $this->db->query(" |
||
49 | SELECT * |
||
50 | FROM `language` |
||
51 | WHERE code = '" . $this->db->escape($this->config->get('config_admin_language')) . "' |
||
52 | "); |
||
53 | |||
54 | if ($query->num_rows) { |
||
55 | $this->config->set( |
||
56 | 'config_language_id', |
||
57 | $query->row['language_id'] |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | // Language |
||
62 | $language = new \Divine\Engine\Library\Language( |
||
63 | $this->config->get('config_admin_language') |
||
64 | ); |
||
65 | $language->load( |
||
66 | $this->config->get('config_admin_language') |
||
67 | ); |
||
68 | $this->registry->set( |
||
69 | 'language', |
||
70 | $language |
||
71 | ); |
||
72 | |||
73 | // Customer |
||
74 | $this->registry->set( |
||
75 | 'customer', |
||
76 | new \Divine\Engine\Library\Customer( |
||
77 | $this->registry |
||
78 | ) |
||
79 | ); |
||
80 | |||
81 | // Currency |
||
82 | $this->registry->set( |
||
83 | 'currency', |
||
84 | new \Divine\Engine\Library\Currency( |
||
85 | $this->registry |
||
86 | ) |
||
87 | ); |
||
88 | |||
89 | // Cart |
||
90 | $this->registry->set( |
||
91 | 'cart', |
||
92 | new \Divine\Engine\Library\Cart( |
||
93 | $this->registry |
||
94 | ) |
||
95 | ); |
||
96 | |||
97 | // Encryption |
||
98 | $this->registry->set( |
||
99 | 'encryption', |
||
100 | new \Divine\Engine\Library\Encryption( |
||
101 | $this->config->get('config_encryption') |
||
102 | ) |
||
106 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.