| Conditions | 14 |
| Paths | 1184 |
| Total Lines | 54 |
| 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 |
||
| 30 | public function all_stats($ids, $metricGroups, $params = [], $async = false) |
||
| 31 | { |
||
| 32 | $endTime = isset($params[AnalyticsFields::END_TIME]) ? $params[AnalyticsFields::END_TIME] : new \DateTime('now'); |
||
| 33 | $endTime->setTime($endTime->format('H'), 0, 0); |
||
| 34 | $startTime = isset($params[AnalyticsFields::START_TIME]) ? $params[AnalyticsFields::START_TIME] : new \DateTime($endTime->format('c') . " - 7 days"); |
||
| 35 | $startTime->setTime($startTime->format('H'), 0, 0); |
||
| 36 | $granularity = isset($params[AnalyticsFields::GRANULARITY]) ? $params[AnalyticsFields::GRANULARITY] : Enumerations::GRANULARITY_TOTAL; |
||
| 37 | $placement = isset($params[AnalyticsFields::PLACEMENT]) ? $params[AnalyticsFields::PLACEMENT] : Enumerations::PLACEMENT_ALL_ON_TWITTER; |
||
| 38 | if (isset($params[AnalyticsFields::ENTITY])) { |
||
| 39 | $entity = $params[AnalyticsFields::ENTITY]; |
||
| 40 | } else { |
||
| 41 | throw new BadRequest('Entity parameter is mandatory', 500, []); |
||
| 42 | } |
||
| 43 | if (!self::inAvailableEntities($entity)) { |
||
| 44 | throw new BadRequest('Entity must be one of ACCOUNT,FUNDING_INSTRUMENT,CAMPAIGN,LINE_ITEM,PROMOTED_TWEET,ORGANIC_TWEET', 500, []); |
||
| 45 | } |
||
| 46 | $segmentationType = isset($params[AnalyticsFields::SEGMENTATION_TYPE]) ? $params[AnalyticsFields::SEGMENTATION_TYPE] : null; |
||
| 47 | $country = isset($params[JobFields::COUNTRY]) ? $params[JobFields::COUNTRY] : null; |
||
| 48 | $platform = isset($params[JobFields::PLATFORM]) ? $params[JobFields::PLATFORM] : null; |
||
| 49 | |||
| 50 | $params = [ |
||
| 51 | AnalyticsFields::METRIC_GROUPS => implode(",", $metricGroups), |
||
| 52 | AnalyticsFields::START_TIME => $startTime->format('c'), |
||
| 53 | AnalyticsFields::END_TIME => $endTime->format('c'), |
||
| 54 | AnalyticsFields::GRANULARITY => $granularity, |
||
| 55 | AnalyticsFields::ENTITY => $entity, |
||
| 56 | AnalyticsFields::ENTITY_IDS => implode(",", $ids), |
||
| 57 | AnalyticsFields::PLACEMENT => $placement, |
||
| 58 | ]; |
||
| 59 | |||
| 60 | if (!$async) { |
||
| 61 | $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_STATS); |
||
| 62 | $response = $this->getTwitterAds()->get($resource, $params); |
||
| 63 | |||
| 64 | return $response->getBody()->data; |
||
| 65 | } else { |
||
| 66 | if (!is_null($segmentationType)) { |
||
| 67 | $params[AnalyticsFields::SEGMENTATION_TYPE] = $segmentationType; |
||
| 68 | } |
||
| 69 | |||
| 70 | if (!is_null($country)) { |
||
| 71 | $params[JobFields::COUNTRY] = $country; |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!is_null($platform)) { |
||
| 75 | $params[JobFields::PLATFORM] = $platform; |
||
| 76 | } |
||
| 77 | |||
| 78 | $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_STATS_JOBS); |
||
| 79 | $response = $this->getTwitterAds()->post($resource, $params); |
||
| 80 | $job = new Job(); |
||
| 81 | return $job->fromResponse($response->getBody()->data); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 104 |
This check looks for function calls that miss required arguments.