| Conditions | 15 |
| Paths | 2 |
| Total Lines | 110 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 2 | 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 |
||
| 35 | public function updateProxy(ProxyGenerator &$proxy) |
||
| 36 | { |
||
| 37 | if (self::$findSource === null) { |
||
| 38 | self::$findSource = DebugBar::config()->get('find_source'); |
||
| 39 | } |
||
| 40 | |||
| 41 | // In the closure, $this is the proxied database |
||
| 42 | $callback = function ($args, $next) { |
||
| 43 | // The first argument is always the sql query |
||
| 44 | $sql = $args[0]; |
||
| 45 | $parameters = isset($args[2]) ? $args[2] : []; |
||
| 46 | |||
| 47 | // Sql can be an array |
||
| 48 | if (is_array($sql)) { |
||
| 49 | $parameters = $sql[1]; |
||
| 50 | $sql = $sql[0]; |
||
| 51 | } |
||
| 52 | |||
| 53 | // Inline sql |
||
| 54 | $sql = DB::inline_parameters($sql, $parameters); |
||
| 55 | |||
| 56 | // Get time and memory for the request |
||
| 57 | $startTime = microtime(true); |
||
| 58 | $startMemory = memory_get_usage(true); |
||
| 59 | |||
| 60 | // Execute all middleware |
||
| 61 | $handle = $next(...$args); |
||
| 62 | |||
| 63 | // Get time and memory after the request |
||
| 64 | $endTime = microtime(true); |
||
| 65 | $endMemory = memory_get_usage(true); |
||
| 66 | |||
| 67 | // Show query on screen |
||
| 68 | if (DebugBar::getShowQueries()) { |
||
| 69 | $formattedSql = DebugBarUtils::formatSql($sql); |
||
| 70 | $rows = $handle->numRecords(); |
||
| 71 | |||
| 72 | echo '<pre>The following query took <b>' . round($endTime - $startTime, 4) . '</b>s an returned <b>' . $rows . "</b> row(s) \n"; |
||
| 73 | echo 'Triggered by: <i>' . self::findSource() . '</i></pre>'; |
||
| 74 | echo $formattedSql; |
||
| 75 | |||
| 76 | // Preview results |
||
| 77 | $results = iterator_to_array($handle); |
||
| 78 | if ($rows > 0) { |
||
| 79 | if ($rows == 1) { |
||
| 80 | dump($results[0]); |
||
| 81 | } else { |
||
| 82 | $linearValues = count($results[0]); |
||
| 83 | if ($linearValues) { |
||
| 84 | dump(implode( |
||
| 85 | ',', |
||
| 86 | array_map( |
||
| 87 | function ($item) { |
||
| 88 | return $item[key($item)]; |
||
| 89 | }, |
||
| 90 | $results |
||
| 91 | ) |
||
| 92 | )); |
||
| 93 | } else { |
||
| 94 | if ($rows < 20) { |
||
| 95 | dump($results); |
||
| 96 | } else { |
||
| 97 | dump("Too many results to display"); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | echo '<hr/>'; |
||
| 103 | |||
| 104 | $handle->rewind(); // Rewind the results |
||
| 105 | } |
||
| 106 | |||
| 107 | // Sometimes, ugly spaces are there |
||
| 108 | $sql = preg_replace('/[[:blank:]]+/', ' ', trim($sql)); |
||
| 109 | |||
| 110 | // Sometimes, the select statement can be very long and unreadable |
||
| 111 | $shortsql = $sql; |
||
| 112 | $matches = null; |
||
| 113 | preg_match_all('/SELECT(.+?) FROM/is', $sql, $matches); |
||
| 114 | $select = empty($matches[1]) ? null : trim($matches[1][0]); |
||
| 115 | if ($select !== null) { |
||
| 116 | if (strlen($select) > 100) { |
||
| 117 | $shortsql = str_replace($select, '"ClickToShowFields"', $sql); |
||
| 118 | } else { |
||
| 119 | $select = null; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | // null on the first query, since it's the select statement itself |
||
| 124 | $db = DB::get_conn()->getSelectedDatabase(); |
||
| 125 | |||
| 126 | self::$queries[] = [ |
||
| 127 | 'short_query' => $shortsql, |
||
| 128 | 'select' => $select, |
||
| 129 | 'query' => $sql, |
||
| 130 | 'start_time' => $startTime, |
||
| 131 | 'end_time' => $endTime, |
||
| 132 | 'duration' => $endTime - $startTime, |
||
| 133 | 'memory' => $endMemory - $startMemory, |
||
| 134 | 'rows' => $handle ? $handle->numRecords() : null, |
||
| 135 | 'success' => $handle ? true : false, |
||
| 136 | 'database' => $db, |
||
| 137 | 'source' => self::$findSource ? self::findSource() : null |
||
| 138 | ]; |
||
| 139 | |||
| 140 | return $handle; |
||
| 141 | }; |
||
| 142 | |||
| 143 | // Attach to benchmarkQuery to fire on both query and preparedQuery |
||
| 144 | $proxy = $proxy->addMethod('benchmarkQuery', $callback); |
||
| 145 | } |
||
| 310 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths