Conditions | 66 |
Paths | 6657 |
Total Lines | 189 |
Code Lines | 96 |
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 |
||
39 | public function run() |
||
40 | { |
||
41 | |||
42 | // Check the conditions are right to run |
||
43 | if (Craft::$app->request->isCpRequest && !Craft::$app->request->getAcceptsJson()) |
||
44 | { |
||
45 | |||
46 | $segments = Craft::$app->request->getSegments(); |
||
47 | |||
48 | /** |
||
49 | * Check third party plugin support |
||
50 | */ |
||
51 | $commercePlugin = \Craft::$app->plugins->getPlugin('commerce'); |
||
52 | $calendarPlugin = \Craft::$app->plugins->getPlugin('calendar'); |
||
53 | |||
54 | /** |
||
55 | * Work out the context for the block type groups configuration |
||
56 | */ |
||
57 | // Entry types |
||
58 | if (count($segments) === 5 |
||
59 | && $segments[0] === 'settings' |
||
60 | && $segments[1] === 'sections' |
||
61 | && $segments[3] === 'entrytypes' |
||
62 | && $segments[4] !== 'new' |
||
63 | ) |
||
64 | { |
||
65 | $this->configurator('#fieldlayoutform', 'entrytype:'.$segments[4]); |
||
66 | } |
||
67 | |||
68 | // Category groups |
||
69 | if (count($segments) === 3 |
||
70 | && $segments[0] === 'settings' |
||
71 | && $segments[1] === 'categories' |
||
72 | && $segments[2] !== 'new' |
||
73 | ) |
||
74 | { |
||
75 | $this->configurator('#fieldlayoutform', 'categorygroup:'.$segments[2]); |
||
76 | } |
||
77 | |||
78 | // Global sets |
||
79 | if (count($segments) === 3 |
||
80 | && $segments[0] === 'settings' |
||
81 | && $segments[1] === 'globals' |
||
82 | && $segments[2] !== 'new' |
||
83 | ) |
||
84 | { |
||
85 | $this->configurator('#fieldlayoutform', 'globalset:'.$segments[2]); |
||
86 | } |
||
87 | |||
88 | // Users |
||
89 | if (count($segments) === 2 |
||
90 | && $segments[0] === 'settings' |
||
91 | && $segments[1] === 'users' |
||
92 | ) |
||
93 | { |
||
94 | $this->configurator('#fieldlayoutform', 'users'); |
||
95 | } |
||
96 | |||
97 | // Solpace Calendar |
||
98 | if (count($segments) === 3 |
||
99 | && $segments[0] === 'calendar' |
||
100 | && $segments[1] === 'calendars' |
||
101 | && $segments[2] !== 'new' |
||
102 | && $calendarPlugin |
||
103 | ) |
||
104 | { |
||
105 | $calendarService = new \Solspace\Calendar\Services\CalendarsService(); |
||
|
|||
106 | if ($calendarService) { |
||
107 | $calendar = $calendarService->getCalendarByHandle(end($segments)); |
||
108 | if ($calendar) { |
||
109 | $this->configurator('#fieldlayoutform', 'calendar:'.$calendar->id); |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | |||
114 | // Commerce |
||
115 | if (count($segments) === 4 |
||
116 | && $segments[0] === 'commerce' |
||
117 | && $segments[1] === 'settings' |
||
118 | && $segments[2] === 'producttypes' |
||
119 | && $segments[3] !== 'new' |
||
120 | && $commercePlugin |
||
121 | ) { |
||
122 | $productTypesService = new \craft\commerce\services\ProductTypes(); |
||
123 | if ($productTypesService) { |
||
124 | $productType = $productTypesService->getProductTypeById($segments[3]); |
||
125 | if ($productType) { |
||
126 | $this->configurator('#fieldlayoutform', 'producttype:'.$productType->id); |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Work out the context for the Matrix field manipulation |
||
133 | */ |
||
134 | // Global |
||
135 | $context = 'global'; |
||
136 | $versioned = false; |
||
137 | |||
138 | // Entry types |
||
139 | if (count($segments) >= 3 && $segments[0] === 'entries') { |
||
140 | |||
141 | if ($segments[2] === 'new') { |
||
142 | /** @var Section $section */ |
||
143 | $section = Craft::$app->sections->getSectionByHandle($segments[1]); |
||
144 | $sectionEntryTypes = $section->getEntryTypes(); |
||
145 | $entryType = reset($sectionEntryTypes); |
||
146 | } else { |
||
147 | $entryId = (integer)explode('-', $segments[2])[0]; |
||
148 | $entry = Craft::$app->entries->getEntryById($entryId); |
||
149 | |||
150 | if ($entry) |
||
151 | { |
||
152 | $entryType = $entry->type; |
||
153 | } |
||
154 | } |
||
155 | |||
156 | if (isset($segments[3]) && $segments[3] === 'versions') { |
||
157 | $versioned = true; |
||
158 | } |
||
159 | |||
160 | if (isset($entryType) && $entryType) { |
||
161 | $context = 'entrytype:'.$entryType->id; |
||
162 | } |
||
163 | |||
164 | } |
||
165 | // Category groups |
||
166 | else if (count($segments) >= 3 && $segments[0] === 'categories') |
||
167 | { |
||
168 | $group = Craft::$app->categories->getGroupByHandle($segments[1]); |
||
169 | if ($group) |
||
170 | { |
||
171 | $context = 'categorygroup:'.$group->id; |
||
172 | } |
||
173 | } |
||
174 | // Global sets |
||
175 | else if (count($segments) >= 2 && $segments[0] === 'globals') |
||
176 | { |
||
177 | $set = Craft::$app->globals->getSetByHandle(end($segments)); |
||
178 | if ($set) |
||
179 | { |
||
180 | $context = 'globalset:'.$set->id; |
||
181 | } |
||
182 | } |
||
183 | // Users |
||
184 | else if ((count($segments) === 1 && $segments[0] === 'myaccount') || (count($segments) == 2 && $segments[0] === 'users')) |
||
185 | { |
||
186 | $context = 'users'; |
||
187 | } |
||
188 | // Solspace Calendar |
||
189 | else if (count($segments) >= 4 |
||
190 | && $segments[0] === 'calendar' |
||
191 | && $segments[1] === 'events' |
||
192 | && $calendarPlugin |
||
193 | ) { |
||
194 | |||
195 | if ($segments[2] === 'new') { |
||
196 | $calendarService = new \Solspace\Calendar\Services\CalendarsService(); |
||
197 | $calendar = $calendarService->getCalendarByHandle($segments[3]); |
||
198 | if ($calendar) { |
||
199 | $context = 'calendar:'.$calendar->id; |
||
200 | } |
||
201 | } else { |
||
202 | $calendarEventsService = new \Solspace\Calendar\Services\EventsService(); |
||
203 | if ($calendarEventsService) { |
||
204 | $event = $calendarEventsService->getEventById($segments[2]); |
||
205 | if ($event) { |
||
206 | $context = 'calendar:'.$event->getCalendar()->id; |
||
207 | } |
||
208 | } |
||
209 | } |
||
210 | } |
||
211 | // Commerce |
||
212 | else if (count($segments) >= 3 |
||
213 | && $segments[0] === 'commerce' |
||
214 | && $segments[1] === 'products' |
||
215 | && $commercePlugin |
||
216 | ) { |
||
217 | $productTypesService = new \craft\commerce\services\ProductTypes(); |
||
218 | if ($productTypesService) { |
||
219 | $productType = $productTypesService->getProductTypeByHandle($segments[2]); |
||
220 | if ($productType) { |
||
221 | $context = 'producttype:'.$productType->id; |
||
222 | } |
||
223 | } |
||
224 | } |
||
225 | |||
226 | // Run the field manipulation code |
||
227 | $this->fieldManipulator($context, $versioned); |
||
228 | |||
312 |
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