Conditions | 12 |
Paths | 15 |
Total Lines | 68 |
Code Lines | 44 |
Lines | 12 |
Ratio | 17.65 % |
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 |
||
34 | public function execute($input_parameters = null) |
||
35 | { |
||
36 | $log = ['query' => '']; |
||
37 | if (config('app.debug') === true) { |
||
38 | //$cache = Ajde_Db_Cache::getInstance(); |
||
39 | if (count($input_parameters)) { |
||
40 | $log = ['query' => vsprintf(str_replace('?', '%s', $this->queryString), $input_parameters)]; |
||
41 | } else { |
||
42 | $log = ['query' => '[PS] '.$this->queryString]; |
||
43 | } |
||
44 | // add backtrace |
||
45 | $i = 0; |
||
46 | $source = []; |
||
47 | foreach (array_reverse(debug_backtrace()) as $item) { |
||
48 | try { |
||
49 | $line = issetor($item['line']); |
||
|
|||
50 | $file = issetor($item['file']); |
||
51 | $source[] = sprintf('%s. <em>%s</em>%s<strong>%s</strong> (%s on line %s)', |
||
52 | $i, |
||
53 | !empty($item['class']) ? $item['class'] : '<unknown class>', |
||
54 | // Assume of no classname is available, dumped from template.. (naive) |
||
55 | !empty($item['type']) ? $item['type'] : '::', |
||
56 | !empty($item['function']) ? $item['function'] : '<unknown function>', |
||
57 | $file, |
||
58 | $line); |
||
59 | } catch (Exception $e) { |
||
60 | } |
||
61 | |||
62 | $i++; |
||
63 | } |
||
64 | $hash = md5(implode('', $source).microtime()); |
||
65 | |||
66 | $log['query'] = '<a href="javascript:void(0)" onclick="$(\'#'.$hash.'\').slideToggle(\'fast\');" style="color: black;">'.$log['query'].'</a>'; |
||
67 | $log['query'] .= '<div id="'.$hash.'" style="display: none;">'.implode('<br/>', $source).'</div>'; |
||
68 | } |
||
69 | // start timer |
||
70 | $start = microtime(true); |
||
71 | try { |
||
72 | //if (!$cache->has($this->queryString . serialize($input_parameters))) { |
||
73 | $result = parent::execute($input_parameters); |
||
74 | //$cache->set($this->queryString . serialize($input_parameters), $result); |
||
75 | // $log['cache'] = false; |
||
76 | //} else { |
||
77 | // $result = $cache->get($this->queryString . serialize($input_parameters)); |
||
78 | // $log['cache'] = true; |
||
79 | //} |
||
80 | } catch (Exception $e) { |
||
81 | if (substr_count(strtolower($e->getMessage()), 'integrity constraint violation')) { |
||
82 | throw new Ajde_Db_IntegrityException($e->getMessage()); |
||
83 | View Code Duplication | } else { |
|
84 | if (config('app.debug') === true) { |
||
85 | if (isset($this->queryString)) { |
||
86 | dump($this->queryString); |
||
87 | } |
||
88 | dump('Go to '.config('app.rootUrl').'?install=1 to install DB'); |
||
89 | throw new Ajde_Db_Exception($e->getMessage()); |
||
90 | } else { |
||
91 | Ajde_Exception_Log::logException($e); |
||
92 | die('DB connection problem. <a href="?install=1">Install database?</a>'); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | $time = microtime(true) - $start; |
||
97 | $log['time'] = round($time * 1000, 0); |
||
98 | Ajde_Db_PDO::$log[] = $log; |
||
99 | |||
100 | return $result; |
||
101 | } |
||
102 | |||
129 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.