Conditions | 7 |
Paths | 3 |
Total Lines | 61 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 13 | ||
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 |
||
101 | protected function doIt(): void |
||
102 | { |
||
103 | |||
104 | // Do nothing if the user is not an admin, or if they don't have field handles visible |
||
105 | /** @var User $user */ |
||
106 | $user = Craft::$app->getUser()->getIdentity(); |
||
107 | if (!$user?->admin) { |
||
108 | return; |
||
109 | } |
||
110 | |||
111 | // Make sure element cards and chips have a [data-type-id] attribute, which we'll use to bootstrap an "Edit Entry Type" link in their settings menus |
||
112 | foreach ([ |
||
113 | Cp::EVENT_DEFINE_ELEMENT_CARD_HTML, |
||
114 | Cp::EVENT_DEFINE_ELEMENT_CHIP_HTML, |
||
115 | ] as $eventName) { |
||
116 | Event::on( |
||
117 | Cp::class, |
||
118 | $eventName, |
||
119 | static function (DefineElementHtmlEvent $event) { |
||
120 | $typeId = $event->element?->typeId ?? null; |
||
121 | if (empty($typeId)) { |
||
122 | return; |
||
123 | } |
||
124 | try { |
||
125 | $html = Html::modifyTagAttributes($event->html, [ |
||
126 | 'data-type-id' => $typeId, |
||
127 | ]); |
||
128 | } catch (\Throwable $e) { |
||
129 | Craft::error($e, __METHOD__); |
||
130 | return; |
||
131 | } |
||
132 | $event->html = $html; |
||
133 | } |
||
134 | ); |
||
135 | } |
||
136 | |||
137 | // Inject edit source buttons for elements that support the EVENT_DEFINE_META_FIELDS_HTML event |
||
138 | Event::on( |
||
139 | Element::class, |
||
140 | Element::EVENT_DEFINE_META_FIELDS_HTML, |
||
141 | static function (DefineHtmlEvent $event) { |
||
142 | if ($event->static) { |
||
143 | return; |
||
144 | } |
||
145 | $event->html .= CpFieldInspectHelper::getEditElementSourceButton($event->sender); |
||
146 | } |
||
147 | ); |
||
148 | |||
149 | // Inject edit source buttons for elements that still use the old template hooks |
||
150 | Craft::$app->getView()->hook('cp.globals.edit.content', [CpFieldInspectHelper::class, 'renderEditSourceLink']); |
||
151 | Craft::$app->getView()->hook('cp.commerce.product.edit.details', [CpFieldInspectHelper::class, 'renderEditSourceLink']); |
||
152 | |||
153 | // Register asset bundle |
||
154 | Event::on( |
||
155 | View::class, |
||
156 | View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE, |
||
157 | static function (TemplateEvent $event) { |
||
158 | if ($event->templateMode !== View::TEMPLATE_MODE_CP) { |
||
159 | return; |
||
160 | } |
||
161 | Craft::$app->getView()->registerAssetBundle(CpFieldInspectBundle::class, ViewAlias::POS_END); |
||
162 | } |
||
168 |
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