From 6afc00682d45bae3c8392ce9f94d45b80eaa0031 Mon Sep 17 00:00:00 2001 From: Riccardo Tempesta Date: Mon, 20 Nov 2017 15:25:11 +0100 Subject: [PATCH] Default / Additional layouts --- Model/PageInfo.php | 73 ++++++++++++++++++++++++++++++++++++++++------ etc/module.xml | 2 +- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Model/PageInfo.php b/Model/PageInfo.php index aab3cea..0234381 100644 --- a/Model/PageInfo.php +++ b/Model/PageInfo.php @@ -30,6 +30,10 @@ use Magento\Framework\Interception\DefinitionInterface; use Magento\Framework\App\ResourceConnection; +/** + * Class PageInfo + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class PageInfo { /** @@ -97,6 +101,23 @@ class PageInfo */ private $collectionRegistry; + /** + * PageInfo constructor. + * @param ProductMetadataInterface $productMetadata + * @param LayoutInterface $layout + * @param RequestInterface $request + * @param EventRegistry $eventRegistry + * @param ElementRegistry $elementRegistry + * @param DataModelRegistry $dataModelRegistry + * @param CollectionRegistry $collectionRegistry + * @param DesignInterface $designInterface + * @param Http $httpRequest + * @param Config $config + * @param Stat $stat + * @param ResourceConnection $resource + * @param PluginList $pluginList + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + */ public function __construct( ProductMetadataInterface $productMetadata, LayoutInterface $layout, @@ -129,16 +150,32 @@ public function __construct( /** * Get page information - * * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getPageInfo() { - $layoutUpdates = $this->layout->getUpdate(); $request = $this->request; $httpRequest = $this->httpRequest; $design = $this->design; + try { + $layoutUpdates = $this->layout->getUpdate(); + $allLayoutHandles = $layoutUpdates->getHandles(); + } catch (\Exception $e) { + $allLayoutHandles = []; + } + + $addedLayoutHandles = []; + $layoutHandles = []; + foreach ($allLayoutHandles as $layoutHandle) { + if (in_array($layoutHandle, ['default', $httpRequest->getFullActionName()])) { + $layoutHandles[] = $layoutHandle; + } else { + $addedLayoutHandles[] = $layoutHandle; + } + } + $themeInheritance = []; $theme = $design->getDesignTheme(); @@ -184,7 +221,12 @@ public function getPageInfo() [ 'id' => 'handles', 'label' => 'Layout Handles', - 'value' => $layoutUpdates->getHandles(), + 'value' => $layoutHandles, + 'type' => 'complex' + ], [ + 'id' => 'additional_handles', + 'label' => 'Additional Handles', + 'value' => $addedLayoutHandles, 'type' => 'complex' ], [ 'id' => 'theme_code', @@ -212,11 +254,17 @@ public function getPageInfo() return $info; } - + /** + * Get a list of plugins + * @return array + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ public function getPluginsList() { $plugins = []; + // @codingStandardsIgnoreStart $reflection = new \ReflectionClass($this->pluginList); + // @codingStandardsIgnoreEnd $processed = $reflection->getProperty('_processed'); $processed->setAccessible(true); @@ -243,13 +291,15 @@ public function getPluginsList() $method = $matches[2]; if (!empty($inherited[$type])) { - foreach($processDef as $keyType => $pluginsNames) { + foreach ($processDef as $keyType => $pluginsNames) { if (!is_array($pluginsNames)) { $pluginsNames = [$pluginsNames]; } $classMethod = $type . '::' . $method; + // @codingStandardsIgnoreStart $key = md5($classMethod); + // @codingStandardsIgnoreEnd if (!isset($plugins[$key])) { $fileName = $this->config->getPhpClassFile($type); @@ -275,7 +325,7 @@ public function getPluginsList() foreach ($pluginsNames as $pluginName) { if (!empty($inherited[$type][$pluginName])) { - $sortOrder = intval($inherited[$type][$pluginName]['sortOrder']); + $sortOrder = (int) $inherited[$type][$pluginName]['sortOrder']; $fileName = $this->config->getPhpClassFile( $inherited[$type][$pluginName]['instance'] @@ -304,7 +354,12 @@ public function getPluginsList() return $plugins; } - protected function getSqlProfilerData() + /** + * Get a list of plugins + * @return array + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + private function getSqlProfilerData() { $allQueries = []; $sqlProfiler = $this->resource->getConnection('read')->getProfiler(); @@ -342,7 +397,7 @@ protected function getSqlProfilerData() $squareSum = 0; - foreach ($allQueries as $index=>$query) { + foreach ($allQueries as $index => $query) { $squareSum = pow($query['time'] - $average, 2); } @@ -353,7 +408,7 @@ protected function getSqlProfilerData() foreach ($allQueries as $index => $query) { if ($query['time'] < ($shortestQueryTime + 2*$standardDeviation)) { $allQueries[$index]['grade'] = 'good'; - } elseif($query['time'] > ($longestQueryTime - 2*$standardDeviation)) { + } elseif ($query['time'] > ($longestQueryTime - 2*$standardDeviation)) { $allQueries[$index]['grade'] = 'bad'; } diff --git a/etc/module.xml b/etc/module.xml index 1544937..680ef0e 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -21,7 +21,7 @@ --> - +