| Conditions | 7 |
| Paths | 8 |
| Total Lines | 57 |
| Code Lines | 42 |
| 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 |
||
| 113 | public function getVisitsData(Request $request) |
||
| 114 | {
|
||
| 115 | $date = $this->getDateOrPeriodFromRequest($request); |
||
| 116 | $period = $this->getDateOrPeriodFromRequest($request, true); |
||
| 117 | |||
| 118 | $imgDate = ''; |
||
| 119 | |||
| 120 | switch ($period) {
|
||
| 121 | case 'range': |
||
| 122 | $imgDate = $date; |
||
| 123 | break; |
||
| 124 | |||
| 125 | case 'week': |
||
| 126 | case 'month': |
||
| 127 | $value = $request->all()['value']; |
||
| 128 | $range = [ |
||
| 129 | 'start' => $value['y2'].'-'.$value['m2'].'-'.$value['d2'], |
||
| 130 | 'end' => $value['y1'].'-'.$value['m1'].'-'.$value['d1'], |
||
| 131 | ]; |
||
| 132 | $imgDate = $range['start'].','.$range['end']; |
||
| 133 | break; |
||
| 134 | |||
| 135 | case 'day': |
||
| 136 | if ($date == 'today') {
|
||
| 137 | $imgDate = date('Y-m-d').','.date('Y-m-d', strtotime(date('Y-m-d').' 2 day'));
|
||
| 138 | } |
||
| 139 | if ($date == 'yesterday') {
|
||
| 140 | $imgDate = date('Y-m-d').','.date('Y-m-d', strtotime(date('Y-m-d').' 2 day'));
|
||
| 141 | } |
||
| 142 | break; |
||
| 143 | } |
||
| 144 | |||
| 145 | $matomoUrl = $this->matomoUrl; |
||
| 146 | $query_factory = QueryFactory::create($matomoUrl); |
||
| 147 | |||
| 148 | $query_factory |
||
| 149 | ->set('idSite', $this->siteId)
|
||
| 150 | ->set('token_auth', $this->authToken);
|
||
| 151 | |||
| 152 | $data = $query_factory->getQuery('API.get ')
|
||
| 153 | ->setParameter('date', $date)
|
||
| 154 | ->setParameter('period', $period)
|
||
| 155 | ->execute() |
||
| 156 | ->getResponse(); |
||
| 157 | |||
| 158 | return response()->json( |
||
| 159 | [ |
||
| 160 | 'visitimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&segment=&showtitle=1&random=6179&columns=nb_visits%2Cnb_uniq_visitors&token_auth='.$this->authToken, |
||
| 161 | 'avgvisitimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&showtitle=1&random=6179&columns=avg_time_on_site&token_auth='.$this->authToken, |
||
| 162 | 'bouncerateimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=bounce_rate&token_auth='.$this->authToken, |
||
| 163 | 'actions_per_visit_img' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=nb_actions_per_visit&token_auth='.$this->authToken, |
||
| 164 | 'pageviewimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=nb_pageviews%2Cnb_uniq_pageviews&token_auth='.$this->authToken, |
||
| 165 | 'searchesandkeywordsimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=nb_searches%2Cnb_keywords&token_auth='.$this->authToken, |
||
| 166 | 'downloadsimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=nb_downloads%2Cnb_uniq_downloads&token_auth='.$this->authToken, |
||
| 167 | 'outlinksimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=nb_outlinks%2Cnb_uniq_outlinks&token_auth='.$this->authToken, |
||
| 168 | 'maxactionsimg' => $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&action=get&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=max_actions&token_auth='.$this->authToken, |
||
| 169 | 'data' => $data, |
||
| 170 | ] |
||
| 237 | } |
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