| Conditions | 6 |
| Paths | 4 |
| Total Lines | 62 |
| 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 |
||
| 95 | private function logQuery($query) |
||
| 96 | { |
||
| 97 | $sqlQuery = htmlentities($query['query']); |
||
| 98 | |||
| 99 | $bindings = $query['bindings']; |
||
| 100 | |||
| 101 | $time = $query['time']; |
||
| 102 | |||
| 103 | $name = $query['name']; |
||
| 104 | |||
| 105 | if (!$this->sqlQueryIsLoggable($sqlQuery)) { |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | |||
| 109 | $connectionId = $this->connectionRepository->findOrCreate( |
||
| 110 | ['name' => $name], |
||
| 111 | ['name'] |
||
| 112 | ); |
||
| 113 | |||
| 114 | $sqlQueryId = $this->findOrCreate( |
||
| 115 | [ |
||
| 116 | 'sha1' => sha1($sqlQuery), |
||
| 117 | 'statement' => $sqlQuery, |
||
| 118 | 'time' => $time, |
||
| 119 | 'connection_id' => $connectionId, |
||
| 120 | ], |
||
| 121 | ['sha1'] |
||
| 122 | ); |
||
| 123 | |||
| 124 | if ($bindings && $this->canLogBindings()) { |
||
| 125 | $bindingsSerialized = $this->serializeBindings($bindings); |
||
| 126 | |||
| 127 | $sqlQuery_bindings_id = $this->sqlQueryBindingRepository->findOrCreate( |
||
| 128 | ['sha1' => sha1($bindingsSerialized), 'serialized' => $bindingsSerialized], |
||
| 129 | ['sha1'], |
||
| 130 | $created |
||
| 131 | ); |
||
| 132 | |||
| 133 | if ($created) { |
||
| 134 | foreach ($bindings as $parameter => $value) { |
||
| 135 | $this->sqlQueryBindingParameterRepository->create( |
||
| 136 | [ |
||
| 137 | 'sql_query_bindings_id' => $sqlQuery_bindings_id, |
||
| 138 | |||
| 139 | // unfortunately laravel uses question marks, |
||
| 140 | // but hopefully someday this will change |
||
| 141 | 'name' => '?', |
||
| 142 | |||
| 143 | 'value' => $value, |
||
| 144 | ] |
||
| 145 | ); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | $this->sqlQueryLogRepository->create( |
||
| 151 | [ |
||
| 152 | 'log_id' => $this->logRepository->getCurrentLogId(), |
||
| 153 | 'sql_query_id' => $sqlQueryId, |
||
| 154 | ] |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | |||
| 171 |