| Total Complexity | 42 |
| Total Lines | 245 |
| Duplicated Lines | 0 % |
| Changes | 13 | ||
| Bugs | 2 | Features | 2 |
Complex classes like APAnalytics often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use APAnalytics, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class APAnalytics |
||
| 14 | { |
||
| 15 | protected $connection; |
||
| 16 | protected $namespace; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Instantiate a new instance. |
||
| 20 | * |
||
| 21 | * @return void |
||
| 22 | */ |
||
| 23 | public function __construct() |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Track the Analytic. |
||
| 31 | * |
||
| 32 | * @return void |
||
| 33 | * @param mixed $collection |
||
| 34 | * @param mixed $items |
||
| 35 | * @param null|mixed $userId |
||
| 36 | * @param mixed $params |
||
| 37 | */ |
||
| 38 | public function track($collection, $items, $userId = null, $params = []) |
||
| 39 | { |
||
| 40 | Track::dispatch($collection, $items, $userId, $params); |
||
| 41 | |||
| 42 | return true; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function update($collection, $item, $params) |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the Analytics. |
||
| 54 | * |
||
| 55 | * @param mixed $collection |
||
| 56 | * @param null|mixed $timeframe |
||
| 57 | * @param null|mixed $filters |
||
| 58 | * @param mixed $interval |
||
| 59 | * @param mixed $groupBy |
||
| 60 | */ |
||
| 61 | public function show($collection, $interval = 'count', $timeframe = null, $filters = null, $groupBy = null) |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Convert the Cursor to Laravel Models. |
||
| 185 | * |
||
| 186 | * @return void |
||
| 187 | * @param mixed $data |
||
| 188 | * @param null|mixed $model |
||
| 189 | */ |
||
| 190 | private function toModels($data, $model = null) |
||
| 191 | { |
||
| 192 | if (! $model) { |
||
| 193 | $model = '\Jenssegers\Mongodb\Eloquent\Model'; |
||
| 194 | } |
||
| 195 | |||
| 196 | if (! class_exists($model)) { |
||
| 197 | throw new InvalidArgumentException("Model {$model} does not exist."); |
||
| 198 | } |
||
| 199 | |||
| 200 | if ($data instanceof Cursor) { |
||
| 201 | // Convert MongoCursor results to a collection of models. |
||
| 202 | $data = iterator_to_array($data, false); |
||
| 203 | |||
| 204 | return $model::hydrate($data); |
||
| 205 | } elseif ($data instanceof BSONDocument) { |
||
| 206 | // Convert Mongo BSONDocument to a single object. |
||
| 207 | $data = $data::getArrayCopy(); |
||
| 208 | |||
| 209 | return $model::newFromBuilder((array) $data); |
||
| 210 | } elseif (is_array($data) && array_key_exists('_id', $data)) { |
||
| 211 | // The result is a single object. |
||
| 212 | return $model::newFromBuilder((array) $data); |
||
| 213 | } |
||
| 214 | |||
| 215 | return $data; |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Check specified user has permission to see these analytics. |
||
| 220 | * |
||
| 221 | * @param array $filterArray |
||
| 222 | * @param User $user |
||
| 223 | * @param mixed $analyticModel |
||
| 224 | * |
||
| 225 | * @return bool |
||
| 226 | */ |
||
| 227 | private function canViewAnalytic($analyticModel, $filterArray, User $user = null) |
||
| 258 | } |
||
| 259 | } |
||
| 260 |
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