| Conditions | 16 |
| Paths | 12 |
| Total Lines | 135 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 | public static function installEventHandlers() |
||
| 102 | { |
||
| 103 | $request = Craft::$app->getRequest(); |
||
| 104 | |||
| 105 | // Install for all requests |
||
| 106 | Event::on( |
||
| 107 | ProductTypes::class, |
||
| 108 | ProductTypes::EVENT_AFTER_SAVE_PRODUCTTYPE, |
||
| 109 | function(ProductTypeEvent $event) { |
||
| 110 | Craft::debug( |
||
| 111 | 'ProductTypes::EVENT_AFTER_SAVE_PRODUCTTYPE', |
||
| 112 | __METHOD__ |
||
| 113 | ); |
||
| 114 | Seomatic::$plugin->metaBundles->resaveMetaBundles(self::META_BUNDLE_TYPE); |
||
| 115 | } |
||
| 116 | ); |
||
| 117 | |||
| 118 | // Install for all non-console requests |
||
| 119 | if (!$request->getIsConsoleRequest()) { |
||
| 120 | // Handler: ProductTypes::EVENT_AFTER_SAVE_PRODUCTTYPE |
||
| 121 | Event::on( |
||
| 122 | ProductTypes::class, |
||
| 123 | ProductTypes::EVENT_AFTER_SAVE_PRODUCTTYPE, |
||
| 124 | static function(ProductTypeEvent $event) { |
||
| 125 | Craft::debug( |
||
| 126 | 'ProductTypes::EVENT_AFTER_SAVE_PRODUCTTYPE', |
||
| 127 | __METHOD__ |
||
| 128 | ); |
||
| 129 | if ($event->productType !== null && $event->productType->id !== null) { |
||
| 130 | Seomatic::$plugin->metaBundles->invalidateMetaBundleById( |
||
| 131 | SeoProduct::getMetaBundleType(), |
||
| 132 | $event->productType->id, |
||
| 133 | $event->isNew |
||
| 134 | ); |
||
| 135 | // Create the meta bundles for this Product Type if it's new |
||
| 136 | if ($event->isNew) { |
||
| 137 | SeoProduct::createContentMetaBundle($event->productType); |
||
| 138 | Seomatic::$plugin->sitemaps->submitSitemapIndex(); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | ); |
||
| 143 | /* |
||
| 144 | * @TODO Sadly this event doesn't exist yet |
||
| 145 | // Handler: ProductTypes::EVENT_AFTER_DELETE_PRODUCTTYPE |
||
| 146 | Event::on( |
||
| 147 | ProductTypes::class, |
||
| 148 | ProductTypes::EVENT_AFTER_DELETE_PRODUCTTYPE, |
||
| 149 | function (ProductTypeEvent $event) { |
||
| 150 | Craft::debug( |
||
| 151 | 'ProductTypes::EVENT_AFTER_DELETE_PRODUCTTYPE', |
||
| 152 | __METHOD__ |
||
| 153 | ); |
||
| 154 | if ($event->productType !== null && $event->productType->id !== null) { |
||
| 155 | Seomatic::$plugin->metaBundles->invalidateMetaBundleById( |
||
| 156 | SeoProduct::getMetaBundleType(), |
||
| 157 | $event->productType->id, |
||
| 158 | false |
||
| 159 | ); |
||
| 160 | // Delete the meta bundles for this Product Type |
||
| 161 | Seomatic::$plugin->metaBundles->deleteMetaBundleBySourceId( |
||
| 162 | SeoProduct::getMetaBundleType(), |
||
| 163 | $event->productType->id |
||
| 164 | ); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | ); |
||
| 168 | */ |
||
| 169 | } |
||
| 170 | |||
| 171 | // Install only for non-console site requests |
||
| 172 | if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) { |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * N.B. This is in here seemingly twice (see the Product::EVENT_DEFINE_SIDEBAR_HTML below) |
||
| 177 | * because Commerce apparently doesn't render the templates in a way that causes the |
||
| 178 | * Product::EVENT_DEFINE_SIDEBAR_HTML to be thrown, despite there being code that implies it does: |
||
| 179 | * https://github.com/craftcms/commerce/blob/develop/src/elements/Product.php#L796 |
||
| 180 | **/ |
||
| 181 | |||
| 182 | // Install only for non-console Control Panel requests |
||
| 183 | if ($request->getIsCpRequest() && !$request->getIsConsoleRequest()) { |
||
| 184 | // Commerce Product Types sidebar |
||
| 185 | $commerce = CommercePlugin::getInstance(); |
||
| 186 | if ($commerce !== null) { |
||
| 187 | Seomatic::$view->hook('cp.commerce.product.edit.details', static function(&$context) { |
||
| 188 | $html = ''; |
||
| 189 | Seomatic::$view->registerAssetBundle(SeomaticAsset::class); |
||
| 190 | /** @var Product $product */ |
||
| 191 | $product = $context[self::getElementRefHandle()] ?? null; |
||
| 192 | if ($product !== null && $product->uri !== null) { |
||
| 193 | Seomatic::$plugin->metaContainers->previewMetaContainers($product->uri, $product->siteId, true); |
||
| 194 | // Render our preview sidebar template |
||
| 195 | if (Seomatic::$settings->displayPreviewSidebar) { |
||
| 196 | $html .= PluginTemplate::renderPluginTemplate('_sidebars/product-preview.twig'); |
||
| 197 | } |
||
| 198 | // Render our analysis sidebar template |
||
| 199 | // @TODO: This will be added an upcoming 'pro' edition |
||
| 200 | // if (Seomatic::$settings->displayAnalysisSidebar) { |
||
| 201 | // $html .= PluginTemplate::renderPluginTemplate('_sidebars/product-analysis.twig'); |
||
| 202 | // } |
||
| 203 | } |
||
| 204 | |||
| 205 | return $html; |
||
| 206 | }); |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | // Handler: Product::EVENT_DEFINE_SIDEBAR_HTML |
||
| 211 | Event::on( |
||
| 212 | Product::class, |
||
| 213 | Product::EVENT_DEFINE_SIDEBAR_HTML, |
||
| 214 | static function(DefineHtmlEvent $event) { |
||
| 215 | Craft::debug( |
||
| 216 | 'Product::EVENT_DEFINE_SIDEBAR_HTML', |
||
| 217 | __METHOD__ |
||
| 218 | ); |
||
| 219 | $html = ''; |
||
| 220 | Seomatic::$view->registerAssetBundle(SeomaticAsset::class); |
||
| 221 | /** @var Product $product */ |
||
| 222 | $product = $event->sender ?? null; |
||
| 223 | if ($product !== null && $product->uri !== null) { |
||
| 224 | Seomatic::$plugin->metaContainers->previewMetaContainers($product->uri, $product->siteId, true); |
||
| 225 | // Render our preview sidebar template |
||
| 226 | if (Seomatic::$settings->displayPreviewSidebar) { |
||
| 227 | $html .= PluginTemplate::renderPluginTemplate('_sidebars/product-preview.twig'); |
||
| 228 | } |
||
| 229 | // Render our analysis sidebar template |
||
| 230 | // @TODO: This will be added an upcoming 'pro' edition |
||
| 231 | // if (Seomatic::$settings->displayAnalysisSidebar) { |
||
| 232 | // $html .= PluginTemplate::renderPluginTemplate('_sidebars/product-analysis.twig'); |
||
| 233 | // } |
||
| 234 | } |
||
| 235 | $event->html .= $html; |
||
| 236 | } |
||
| 514 |
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