| Conditions | 8 |
| Paths | 16 |
| Total Lines | 72 |
| Lines | 3 |
| Ratio | 4.17 % |
| 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 |
||
| 72 | } else { |
||
| 73 | $projection = $options['projection']; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($projection === false) { |
||
| 78 | $result = $this->storage->find($filter, null); |
||
| 79 | } else { |
||
| 80 | $result = $this->storage->find($filter, $projection); |
||
| 81 | } |
||
| 82 | |||
| 83 | $totalRows = $this->storage->count($filter); |
||
| 84 | $totalPages = max(ceil($totalRows / $filter->getPerPage()), 1); |
||
| 85 | |||
| 86 | return array( |
||
| 87 | 'results' => $this->_wrap($result), |
||
| 88 | 'sort' => $filter->getSort(), |
||
| 89 | 'direction' => $filter->getDirection(), |
||
| 90 | 'page' => $filter->getPage(), |
||
| 91 | 'perPage' => $filter->getPerPage(), |
||
| 92 | 'totalPages' => $totalPages |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get the Percentile metrics for a URL |
||
| 98 | * |
||
| 99 | * This will group data by date and returns only the |
||
| 100 | * percentile + date, making the data ideal for time series graphs |
||
| 101 | * |
||
| 102 | * @param integer $percentile The percentile you want. e.g. 90. |
||
| 103 | * @param string $url |
||
| 104 | * @param array $search Search options containing startDate and or endDate |
||
| 105 | * @return array Array of metrics grouped by date |
||
| 106 | */ |
||
| 107 | public function getPercentileForUrl($percentile, $url, $filter) |
||
| 108 | { |
||
| 109 | $col = '$meta.request_date'; |
||
| 110 | // if (!empty($search['limit']) && $search['limit'][0] == "P") { |
||
| 111 | // $col = '$meta.request_ts'; |
||
| 112 | // } |
||
| 113 | |||
| 114 | $results = $this->storage->aggregate($filter, $col, $percentile); |
||
| 115 | if (empty($results['result'])) { |
||
| 116 | return array(); |
||
| 117 | } |
||
| 118 | $keys = array( |
||
| 119 | 'wall_times' => 'wt', |
||
| 120 | 'cpu_times' => 'cpu', |
||
| 121 | 'mu_times' => 'mu', |
||
| 122 | 'pmu_times' => 'pmu' |
||
| 123 | ); |
||
| 124 | foreach ($results['result'] as &$result) { |
||
| 125 | $result['date'] = ($result['_id'] instanceof MongoDate) ? date('Y-m-d H:i:s', $result['_id']->sec) : $result['_id']; |
||
| 126 | unset($result['_id']); |
||
| 127 | $index = max(round($result['raw_index']) - 1, 0); |
||
| 128 | foreach ($keys as $key => $out) { |
||
| 129 | sort($result[$key]); |
||
| 130 | $result[$out] = isset($result[$key][$index]) ? $result[$key][$index] : null; |
||
| 131 | unset($result[$key]); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | return array_values($results['result']); |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Get a paginated set of results. |
||
| 139 | * |
||
| 140 | * @param array $options The find options to use. |
||
| 141 | * @return array An array of result data. |
||
| 142 | */ |
||
| 143 | public function getAll($filter) |
||
| 144 | { |
||
| 208 |
This check looks for function calls that miss required arguments.