Conditions | 9 |
Paths | 4 |
Total Lines | 78 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
32 | public function getInsightsReport() |
||
33 | { |
||
34 | $pluginSettings = Craft::$app->getPlugins()->getPlugin('facebook')->getSettings(); |
||
35 | |||
36 | $facebookInsightsObjectId = $pluginSettings['facebookInsightsObjectId']; |
||
37 | |||
38 | $report = Facebook::$plugin->getCache()->get(['insightsReport', $facebookInsightsObjectId]); |
||
39 | |||
40 | if (!$report) { |
||
41 | $token = Facebook::$plugin->getOauth()->getToken(); |
||
42 | |||
43 | if ($token !== null) { |
||
44 | // Object |
||
45 | |||
46 | $object = Facebook::$plugin->getApi()->get('/'.$facebookInsightsObjectId, ['metadata' => 1, 'fields' => 'name,picture']); |
||
47 | $objectType = $object['metadata']['type']; |
||
48 | $message = false; |
||
49 | |||
50 | $counts = []; |
||
51 | |||
52 | if ($objectType == 'page') { |
||
53 | // Insights for objects of type `page` |
||
54 | $supportedObject = true; |
||
55 | $insights = Facebook::$plugin->getApi()->getInsights($facebookInsightsObjectId, [ |
||
56 | 'query' => [ |
||
57 | 'metric' => 'page_fans,page_impressions_unique', |
||
58 | 'since' => date('Y-m-d', strtotime('-6 day')), |
||
59 | 'until' => date('Y-m-d', strtotime('+1 day')), |
||
60 | ] |
||
61 | ]); |
||
62 | foreach ($insights['data'] as $insight) { |
||
63 | if ($insight['name'] == 'page_fans') { |
||
64 | $weekTotalStart = $insight['values'][0]['value']; |
||
65 | $weekTotalEnd = end($insight['values'])['value']; |
||
66 | $weekTotal = $weekTotalEnd - $weekTotalStart; |
||
67 | $counts[] = [ |
||
68 | 'label' => Craft::t('facebook', 'Total likes'), |
||
69 | 'value' => end($insight['values'])['value'] |
||
70 | ]; |
||
71 | $counts[] = [ |
||
72 | 'label' => Craft::t('facebook', 'Likes this week'), |
||
73 | 'value' => $weekTotal |
||
74 | ]; |
||
75 | } elseif ($insight['name'] == 'page_impressions_unique') { |
||
76 | if ($insight['period'] == 'week') { |
||
77 | $counts[] = [ |
||
78 | 'label' => Craft::t('facebook', 'Total Reach this week'), |
||
79 | 'value' => end($insight['values'])['value'] |
||
80 | ]; |
||
81 | } elseif ($insight['period'] == 'days_28') { |
||
82 | $counts[] = [ |
||
83 | 'label' => Craft::t('facebook', 'Total Reach this month'), |
||
84 | 'value' => end($insight['values'])['value'] |
||
85 | ]; |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } else { |
||
90 | $supportedObject = false; |
||
91 | $message = 'Insights only supports pages, please choose a different Facebook Page ID in <a href="'.UrlHelper::getUrl('facebook/settings').'">Facebook’s settings</a>.'; |
||
|
|||
92 | Craft::info("Insights not available for object type `".$objectType."`, only pages are supported.", __METHOD__); |
||
93 | } |
||
94 | |||
95 | $report = [ |
||
96 | 'supportedObject' => $supportedObject, |
||
97 | 'message' => $message, |
||
98 | 'object' => $object, |
||
99 | 'objectType' => $objectType, |
||
100 | 'counts' => $counts, |
||
101 | ]; |
||
102 | |||
103 | Facebook::$plugin->getCache()->set(['insightsReport', $facebookInsightsObjectId], $report); |
||
104 | } else { |
||
105 | throw new Exception("Not authenticated"); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | return $report; |
||
110 | } |
||
112 |
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