| Conditions | 7 |
| Paths | 8 |
| Total Lines | 53 |
| Code Lines | 41 |
| 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 |
||
| 106 | public function getVisitsData(Request $request) |
||
| 107 | {
|
||
| 108 | $date = $this->getDateOrPeriodFromRequest($request); |
||
| 109 | $period = $this->getDateOrPeriodFromRequest($request, true); |
||
| 110 | |||
| 111 | $imgDate = ''; |
||
| 112 | |||
| 113 | switch ($period) {
|
||
| 114 | case 'range': |
||
| 115 | $imgDate = $date; |
||
| 116 | break; |
||
| 117 | case 'week': case 'month': |
||
| 118 | $value = $request->all()["value"]; |
||
| 119 | $range = array( |
||
| 120 | 'start' => $value["y2"].'-'.$value["m2"].'-'.$value["d2"], |
||
| 121 | 'end' => $value["y1"].'-'.$value["m1"].'-'.$value["d1"] |
||
| 122 | ); |
||
| 123 | $imgDate = $range['start'].','.$range['end']; |
||
| 124 | break; |
||
| 125 | case 'day': |
||
| 126 | if($date == 'today'){
|
||
| 127 | $imgDate = date('Y-m-d').",".date('Y-m-d', strtotime(date('Y-m-d')." +2 day"));
|
||
| 128 | } |
||
| 129 | if($date == 'yesterday'){
|
||
| 130 | $imgDate = date('Y-m-d').",".date('Y-m-d', strtotime(date('Y-m-d')." +2 day"));
|
||
| 131 | } |
||
| 132 | break; |
||
| 133 | } |
||
| 134 | |||
| 135 | $matomoUrl = $this->matomoUrl; |
||
| 136 | $query_factory = QueryFactory::create($matomoUrl); |
||
| 137 | |||
| 138 | $query_factory |
||
| 139 | ->set('idSite', $this->siteId)
|
||
| 140 | ->set('token_auth', $this->authToken);
|
||
| 141 | |||
| 142 | $data = $query_factory->getQuery('API.get ')
|
||
| 143 | ->setParameter('date', $date)
|
||
| 144 | ->setParameter('period', $period)
|
||
| 145 | ->execute() |
||
| 146 | ->getResponse(); |
||
| 147 | |||
| 148 | return response()->json([ |
||
| 149 | '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, |
||
| 150 | '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, |
||
| 151 | 'bouncerateimg'=> $matomoUrl.'/index.php?forceView=1&viewDataTable=sparkline&module=API&idSite='.$this->siteId.'&period='.$period.'&date='.$imgDate.'&columns=bounce_rate&token_auth='.$this->authToken, |
||
| 152 | '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, |
||
| 153 | '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, |
||
| 154 | '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, |
||
| 155 | '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, |
||
| 156 | '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, |
||
| 157 | '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, |
||
| 158 | 'data'=> $data |
||
| 159 | ]); |
||
| 227 | } |
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