diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..63866af --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/doc export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/CHANGELOG.md export-ignore +/CONTRIBUTING.md export-ignore +/README.md export-ignore diff --git a/.gitignore b/.gitignore index 4cfec22..e0d383d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ -# Eclipse -.buildpath -.project -.settings - -# PhpStorm -.idea +/.idea +/vendor +/composer.lock diff --git a/Block/Toolbar.php b/Block/Toolbar.php index 8e637d3..409c3f7 100644 --- a/Block/Toolbar.php +++ b/Block/Toolbar.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block; use Magento\Framework\App\Request\Http as MagentoRequest; @@ -12,6 +14,7 @@ use Magento\Framework\HTTP\PhpEnvironment\Response as MagentoResponse; use Magento\Framework\View\Element\Template as MagentoTemplateBlock; use Magento\Framework\View\Element\Template\Context; +use RuntimeException; use Smile\DebugToolbar\Block\Zone\Summary; use Smile\DebugToolbar\Block\Zone\SummaryFactory; use Smile\DebugToolbar\Helper\Data as HelperData; @@ -58,7 +61,7 @@ public function __construct( $this->blockSummaryFactory = $blockSummaryFactory; $this->setData('cache_lifetime', 0); - $this->setTemplate('toolbar.phtml'); + $this->setTemplate('Smile_DebugToolbar::toolbar.phtml'); } /** @@ -67,7 +70,7 @@ public function __construct( * @param MagentoRequest $request * @param MagentoResponse $response */ - public function loadZones(MagentoRequest $request, MagentoResponse $response) + public function loadZones(MagentoRequest $request, MagentoResponse $response): void { /** @var Summary $summaryBlock */ $summaryBlock = $this->blockSummaryFactory->create(); @@ -96,7 +99,7 @@ public function loadZones(MagentoRequest $request, MagentoResponse $response) * * @return Zone\AbstractZone[] */ - public function getZones() + public function getZones(): array { return $this->zones; } @@ -106,7 +109,7 @@ public function getZones() * * @return bool */ - public function isWarning() + public function isWarning(): bool { $warning = false; @@ -123,26 +126,17 @@ public function isWarning() * Get the toolbar id. * * @return string + * @throws RuntimeException */ - public function getToolbarId() + public function getToolbarId(): string { return $this->helperData->getToolbarId(); } - /** - * Get the data helper. - * - * @return HelperData - */ - public function getHelperData() - { - return $this->helperData; - } - /** * @inheritdoc */ - public function toHtml() + public function toHtml(): string { return $this->_toHtml(); } diff --git a/Block/Toolbars.php b/Block/Toolbars.php index dd871de..8013515 100644 --- a/Block/Toolbars.php +++ b/Block/Toolbars.php @@ -5,8 +5,11 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\View\Element\Template as MagentoTemplateBlock; use Magento\Framework\View\Element\Template\Context; use Smile\DebugToolbar\Helper\Data as HelperData; @@ -46,9 +49,10 @@ public function __construct( /** * Return the list of the toolbars. * - * @return \string[] + * @return string[] + * @throws FileSystemException */ - public function getToolbarList() + public function getToolbarList(): array { return $this->helperData->getContentToolbars(); } @@ -56,7 +60,7 @@ public function getToolbarList() /** * @inheritdoc */ - public function toHtml() + public function toHtml(): string { return $this->_toHtml(); } diff --git a/Block/Zone/AbstractZone.php b/Block/Zone/AbstractZone.php index 6553c43..457a190 100644 --- a/Block/Zone/AbstractZone.php +++ b/Block/Zone/AbstractZone.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\View\Element\Template as MagentoTemplateBlock; @@ -15,7 +17,6 @@ /** * Zone for Debug Toolbar Block * - * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -66,7 +67,7 @@ public function __construct( $this->formatterFactory = $formatterFactory; $this->setData('cache_lifetime', 0); - $this->setTemplate('zone/' . $this->getCode() . '.phtml'); + $this->setTemplate('Smile_DebugToolbar::zone/' . $this->getCode() . '.phtml'); } /** @@ -74,19 +75,19 @@ public function __construct( * * @return string */ - abstract public function getCode(); + abstract public function getCode(): string; /** * Get the title. * * @return string */ - abstract public function getTitle(); + abstract public function getTitle(): string; /** * @inheritdoc */ - public function toHtml() + public function toHtml(): string { return $this->_toHtml(); } @@ -95,9 +96,10 @@ public function toHtml() * Add the summary block. * * @param Summary $block + * * @return $this */ - public function setSummaryBlock(Summary $block) + public function setSummaryBlock(Summary $block): AbstractZone { $this->summaryBlock = $block; @@ -111,7 +113,7 @@ public function setSummaryBlock(Summary $block) * @param string $key * @param mixed $value */ - public function addToSummary($sectionName, $key, $value) + public function addToSummary(string $sectionName, string $key, $value): void { $this->summaryBlock->addToSummary($sectionName, $key, $value); } @@ -121,7 +123,7 @@ public function addToSummary($sectionName, $key, $value) * * @return $this */ - public function hasWarning() + public function hasWarning(): AbstractZone { $this->warning = true; @@ -133,7 +135,7 @@ public function hasWarning() * * @return bool */ - public function isWarning() + public function isWarning(): bool { return $this->warning; } @@ -144,7 +146,7 @@ public function isWarning() * @param array $sections * @return string */ - public function displaySections($sections = []) + public function displaySections(array $sections = []): string { $html = ''; @@ -153,7 +155,7 @@ public function displaySections($sections = []) $html .= "\n"; $html .= ''; - if (count($sectionValues) == 0) { + if (count($sectionValues) === 0) { $html .= "\n"; } @@ -174,7 +176,7 @@ public function displaySections($sections = []) * @param array $sections * @return string */ - public function displaySectionsGrouped($sections = []) + public function displaySectionsGrouped(array $sections = []): string { $sectionNames = array_keys($sections); $rowNames = array_keys($sections[$sectionNames[0]]); @@ -186,7 +188,7 @@ public function displaySectionsGrouped($sections = []) $html .= ''; $html .= ''; foreach ($sectionNames as $sectionName) { - list($class, $value) = $this->getClassAndValue($sections[$sectionName][$rowName]); + [$class, $value] = $this->getClassAndValue($sections[$sectionName][$rowName]); $html .= ''; } $html .= ''; @@ -203,7 +205,7 @@ public function displaySectionsGrouped($sections = []) * @param mixed $value * @return string[] */ - protected function getClassAndValue($value) + protected function getClassAndValue($value): array { if (!is_array($value) || !array_key_exists('value', $value) @@ -218,13 +220,13 @@ protected function getClassAndValue($value) /** * Display a row section. * - * @param string $name + * @param string|int $name * @param mixed $value * @return string */ - protected function displaySectionValue($name, $value) + protected function displaySectionValue($name, $value): string { - list($class, $value) = $this->getClassAndValue($value); + [$class, $value] = $this->getClassAndValue($value); return " \n"; } @@ -234,7 +236,7 @@ protected function displaySectionValue($name, $value) * * @return string */ - public function getToolbarId() + public function getToolbarId(): string { return $this->helperData->getToolbarId(); } @@ -245,10 +247,10 @@ public function getToolbarId() * @param string $title * @param array $values * @param array $columns - * @param string $additional + * @param string|null $additional * @return string */ - public function displayTable($title, &$values, $columns, $additional = null) + public function displayTable(string $title, array &$values, array $columns, ?string $additional = null): string { $tableId = $this->helperData->getNewTableId(); $tableTitle = str_replace('-', '_', $tableId) . '_title'; @@ -284,7 +286,7 @@ public function displayTable($title, &$values, $columns, $additional = null) * * @return array */ - public function getTablesToDisplay() + public function getTablesToDisplay(): array { return $this->tablesToDisplay; } @@ -294,7 +296,7 @@ public function getTablesToDisplay() * * @return HelperData */ - public function getHelperData() + public function getHelperData(): HelperData { return $this->helperData; } @@ -302,12 +304,13 @@ public function getHelperData() /** * Format a value, using rules, and type. * - * @param float $value + * @param string|float $value * @param array $rules - * @param string $type + * @param string|null $type + * * @return array */ - public function formatValue($value, $rules = [], $type = null) + public function formatValue($value, array $rules = [], ?string $type = null): array { $formatter = $this->formatterFactory->create( [ diff --git a/Block/Zone/Cache.php b/Block/Zone/Cache.php index d849938..cfcc623 100644 --- a/Block/Zone/Cache.php +++ b/Block/Zone/Cache.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\App\DeploymentConfig; @@ -16,6 +18,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -57,7 +60,7 @@ public function __construct( /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'cache'; } @@ -65,7 +68,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Cache'; } @@ -75,7 +78,7 @@ public function getTitle() * * @return string */ - public function getCacheMode() + public function getCacheMode(): string { $config = $this->deployConfig->get('cache'); if (!$config || !is_array($config) || empty($config['frontend']['default']['backend'])) { @@ -88,7 +91,7 @@ public function getCacheMode() /** * Get the cache info. * - * @return string + * @return string|array */ public function getCacheInfo() { @@ -105,7 +108,7 @@ public function getCacheInfo() * * @return array */ - public function getCacheTypes() + public function getCacheTypes(): array { return $this->helperCache->getCacheTypes(); } @@ -115,7 +118,7 @@ public function getCacheTypes() * * @return array */ - public function getCacheUsage() + public function getCacheUsage(): array { return array_values($this->helperCache->getCacheUsage()); } @@ -125,7 +128,7 @@ public function getCacheUsage() * * @return array */ - public function getStatsPerAction() + public function getStatsPerAction(): array { return $this->helperCache->getStatsPerAction(); } @@ -136,7 +139,7 @@ public function getStatsPerAction() * @param array $calls * @return string */ - public function buildHtmlInfo(array $calls = []) + public function buildHtmlInfo(array $calls = []): string { $html = '
No Values
' . $rowName . '' . $value . '
{$name}{$value}
'; diff --git a/Block/Zone/Generic.php b/Block/Zone/Generic.php index 809f6f7..4a500fd 100644 --- a/Block/Zone/Generic.php +++ b/Block/Zone/Generic.php @@ -5,11 +5,14 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\ProductMetadataInterface; use Magento\Framework\App\State as AppState; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Element\Template\Context; use Smile\DebugToolbar\Formatter\FormatterFactory; use Smile\DebugToolbar\Helper\Data as HelperData; @@ -17,6 +20,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -66,7 +70,7 @@ public function __construct( /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'generic'; } @@ -74,7 +78,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Generic'; } @@ -84,7 +88,7 @@ public function getTitle() * * @return string */ - public function getProductName() + public function getProductName(): string { return $this->productMetadata->getName(); } @@ -94,7 +98,7 @@ public function getProductName() * * @return string */ - public function getProductEdition() + public function getProductEdition(): string { return $this->productMetadata->getEdition(); } @@ -104,7 +108,7 @@ public function getProductEdition() * * @return string */ - public function getProductVersion() + public function getProductVersion(): string { return $this->productMetadata->getVersion(); } @@ -114,9 +118,13 @@ public function getProductVersion() * * @return string */ - public function getMagentoArea() + public function getMagentoArea(): string { - return $this->appState->getAreaCode(); + try { + return $this->appState->getAreaCode(); + } catch (LocalizedException $e) { + return ''; + } } /** @@ -124,7 +132,7 @@ public function getMagentoArea() * * @return string */ - public function getMagentoMode() + public function getMagentoMode(): string { return $this->appState->getMode(); } @@ -134,7 +142,7 @@ public function getMagentoMode() * * @return string */ - public function getSessionMode() + public function getSessionMode(): string { $config = $this->deployConfig->get('session'); if (!$config || !is_array($config) || empty($config['save'])) { @@ -147,7 +155,7 @@ public function getSessionMode() /** * Get the session info. * - * @return string + * @return array|string */ public function getSessionInfo() { @@ -164,9 +172,9 @@ public function getSessionInfo() * * @return string */ - public function getPhpVersion() + public function getPhpVersion(): string { - return phpversion(); + return PHP_VERSION; } /** @@ -174,13 +182,13 @@ public function getPhpVersion() * * @return int */ - public function getPhpMemoryLimit() + public function getPhpMemoryLimit(): int { $value = ini_get('memory_limit'); $value = trim($value); $unit = strtolower($value[strlen($value) - 1]); - $value = (int) substr($value, 0, strlen($value) - 1); + $value = (int) substr($value, 0, -1); $units = [ 'k' => 1024, @@ -200,7 +208,7 @@ public function getPhpMemoryLimit() * * @return int */ - public function getPhpMemoryUsed() + public function getPhpMemoryUsed(): int { return (int) memory_get_peak_usage(true); } @@ -210,7 +218,7 @@ public function getPhpMemoryUsed() * * @return int */ - public function getPhpMaxExecutionTime() + public function getPhpMaxExecutionTime(): int { return (int) ini_get('max_execution_time'); } @@ -218,9 +226,9 @@ public function getPhpMaxExecutionTime() /** * Get the php max execution time. * - * @return string + * @return float */ - public function getPhpExecutionTime() + public function getPhpExecutionTime(): float { return $this->helperData->getTimer('app_http'); } diff --git a/Block/Zone/Layout.php b/Block/Zone/Layout.php index 283cfb6..26ad4de 100644 --- a/Block/Zone/Layout.php +++ b/Block/Zone/Layout.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\View\Element\Template\Context; @@ -15,6 +17,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -48,7 +51,7 @@ public function __construct( /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'layout'; } @@ -56,7 +59,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Layout'; } @@ -66,7 +69,7 @@ public function getTitle() * * @return array */ - public function getLayoutBuild() + public function getLayoutBuild(): array { return $this->helperLayout->getLayoutBuild(); } @@ -76,7 +79,7 @@ public function getLayoutBuild() * * @return array */ - public function getHandles() + public function getHandles(): array { return $this->helperLayout->getHandles(); } @@ -86,7 +89,7 @@ public function getHandles() * * @return string */ - public function displayLayoutTable() + public function displayLayoutTable(): string { return $this->displayLayoutRecursive($this->getLayoutBuild(), 0); } @@ -98,7 +101,7 @@ public function displayLayoutTable() * @param int $level * @return string */ - protected function displayLayoutRecursive($list, $level) + protected function displayLayoutRecursive(array $list, int $level): string { $html = ''; foreach ($list as $row) { @@ -116,7 +119,7 @@ protected function displayLayoutRecursive($list, $level) * @param int $level * @return string */ - protected function displayLayoutRecursiveRow($row, $level) + protected function displayLayoutRecursiveRow(array $row, int $level): string { $prefix = $this->getToolbarId() . '-lt-'; diff --git a/Block/Zone/Mysql.php b/Block/Zone/Mysql.php index 67b5587..e2c4d96 100644 --- a/Block/Zone/Mysql.php +++ b/Block/Zone/Mysql.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\View\Element\Template\Context; @@ -15,6 +17,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -48,7 +51,7 @@ public function __construct( /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'mysql'; } @@ -56,7 +59,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Mysql'; } @@ -66,7 +69,7 @@ public function getTitle() * * @return array */ - public function getQueries() + public function getQueries(): array { return $this->resourceModel->getExecutedQueries(); } @@ -76,7 +79,7 @@ public function getQueries() * * @return array */ - public function getCountPerTypes() + public function getCountPerTypes(): array { return $this->resourceModel->getCountPerTypes(); } @@ -86,7 +89,7 @@ public function getCountPerTypes() * * @return array */ - public function getTimePerTypes() + public function getTimePerTypes(): array { return $this->resourceModel->getTimePerTypes(); } @@ -96,7 +99,7 @@ public function getTimePerTypes() * * @return string */ - public function getMysqlVersion() + public function getMysqlVersion(): string { return $this->resourceModel->getMysqlVersion(); } @@ -108,7 +111,7 @@ public function getMysqlVersion() * @param array $trace * @return string */ - public function buildHtmlInfo(array $params = [], array $trace = []) + public function buildHtmlInfo(array $params = [], array $trace = []): string { $html = ''; diff --git a/Block/Zone/Observer.php b/Block/Zone/Observer.php index f39e0b0..2fb4994 100644 --- a/Block/Zone/Observer.php +++ b/Block/Zone/Observer.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\View\Element\Template\Context; @@ -15,6 +17,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -48,7 +51,7 @@ public function __construct( /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'observer'; } @@ -56,7 +59,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Observer'; } @@ -66,7 +69,7 @@ public function getTitle() * * @return array */ - public function getObserverStats() + public function getObserverStats(): array { return $this->helperObserver->getEventStats(); } @@ -77,7 +80,7 @@ public function getObserverStats() * @param array $observers * @return string */ - public function buildHtmlInfo(array $observers = []) + public function buildHtmlInfo(array $observers = []): string { $html = '
'; diff --git a/Block/Zone/Preference.php b/Block/Zone/Preference.php index 86d1f5a..74f5b0a 100644 --- a/Block/Zone/Preference.php +++ b/Block/Zone/Preference.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\View\Element\Template\Context; @@ -15,6 +17,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -48,7 +51,7 @@ public function __construct( /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'preference'; } @@ -56,7 +59,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Preference'; } @@ -66,7 +69,7 @@ public function getTitle() * * @return array */ - public function getPluginStats() + public function getPluginStats(): array { return $this->helperPreference->getPluginStats(); } @@ -76,7 +79,7 @@ public function getPluginStats() * * @return array */ - public function getPreferenceStats() + public function getPreferenceStats(): array { return $this->helperPreference->getPreferenceStats(); } @@ -87,17 +90,19 @@ public function getPreferenceStats() * @param string[] $methods * @return string */ - public function buildPluginHtmlInfo($methods) + public function buildPluginHtmlInfo(array $methods): string { $html = "
- - + + + + - + "; foreach ($methods as $method => $type) { diff --git a/Block/Zone/Profiler.php b/Block/Zone/Profiler.php index c3f867f..68dd1b7 100644 --- a/Block/Zone/Profiler.php +++ b/Block/Zone/Profiler.php @@ -5,9 +5,12 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\View\Element\Template\Context; +use RuntimeException; use Smile\DebugToolbar\Formatter\FormatterFactory; use Smile\DebugToolbar\Helper\Data as HelperData; use Smile\DebugToolbar\Helper\Profiler as HelperProfiler; @@ -15,6 +18,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -48,7 +52,7 @@ public function __construct( /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'profiler'; } @@ -56,7 +60,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Profiler'; } @@ -65,8 +69,9 @@ public function getTitle() * Get the profiler timers. * * @return array + * @throws RuntimeException */ - public function getTimers() + public function getTimers(): array { return $this->helperProfiler->getTimers(); } diff --git a/Block/Zone/Request.php b/Block/Zone/Request.php index 7624274..f8c42ac 100644 --- a/Block/Zone/Request.php +++ b/Block/Zone/Request.php @@ -5,13 +5,17 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\App\Request\Http as MagentoRequest; +use Magento\Framework\App\RequestInterface; /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -26,7 +30,7 @@ class Request extends AbstractZone /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'request'; } @@ -34,7 +38,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Request'; } @@ -45,7 +49,7 @@ public function getTitle() * @param MagentoRequest $request * @return $this */ - public function setRequest(MagentoRequest $request) + public function setRequest(MagentoRequest $request): Request { $this->request = $request; @@ -55,7 +59,7 @@ public function setRequest(MagentoRequest $request) /** * @inheritdoc */ - public function getRequest() + public function getRequest(): RequestInterface { return $this->request; } @@ -65,8 +69,8 @@ public function getRequest() * * @return string */ - public function getControllerClassName() + public function getControllerClassName(): string { - return $this->helperData->getValue('controller_classname'); + return (string) $this->helperData->getValue('controller_classname'); } } diff --git a/Block/Zone/Response.php b/Block/Zone/Response.php index 75cf0bc..e2ad31b 100644 --- a/Block/Zone/Response.php +++ b/Block/Zone/Response.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; use Magento\Framework\HTTP\PhpEnvironment\Response as MagentoResponse; @@ -12,6 +14,7 @@ /** * Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -26,7 +29,7 @@ class Response extends AbstractZone /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'response'; } @@ -34,7 +37,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Response'; } @@ -45,7 +48,7 @@ public function getTitle() * @param MagentoResponse $response * @return $this */ - public function setResponse(MagentoResponse $response) + public function setResponse(MagentoResponse $response): Response { $this->response = $response; @@ -57,7 +60,7 @@ public function setResponse(MagentoResponse $response) * * @return MagentoResponse */ - public function getResponse() + public function getResponse(): MagentoResponse { return $this->response; } @@ -67,7 +70,7 @@ public function getResponse() * * @return string */ - public function getFullPageCacheMode() + public function getFullPageCacheMode(): string { return $this->helperData->getFullPageCacheMode(); } @@ -77,7 +80,7 @@ public function getFullPageCacheMode() * * @return string[] */ - public function getEsiUrlList() + public function getEsiUrlList(): array { $list = []; diff --git a/Block/Zone/Summary.php b/Block/Zone/Summary.php index 0b2c7b3..934b011 100644 --- a/Block/Zone/Summary.php +++ b/Block/Zone/Summary.php @@ -5,11 +5,14 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Block\Zone; /** * Summary Zone for Debug Toolbar Block * + * @api * @author Laurent Minguet * @copyright 2019 Smile * @license Eclipse Public License 2.0 (EPL-2.0) @@ -24,7 +27,7 @@ class Summary extends AbstractZone /** * @inheritdoc */ - public function getCode() + public function getCode(): string { return 'summary'; } @@ -32,7 +35,7 @@ public function getCode() /** * @inheritdoc */ - public function getTitle() + public function getTitle(): string { return 'Summary'; } @@ -42,7 +45,7 @@ public function getTitle() * * @return array */ - public function getSummarySections() + public function getSummarySections(): array { return $this->summary; } @@ -50,7 +53,7 @@ public function getSummarySections() /** * @inheritdoc */ - public function addToSummary($sectionName, $key, $value) + public function addToSummary(string $sectionName, string $key, $value): void { if (is_array($value) && array_key_exists('has_warning', $value) && $value['has_warning']) { $this->hasWarning(); diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d1ef3d..b75f6ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [5.0.0] - 2020-08-17 +[5.0.0]: https://github.com/Smile-SA/magento2-module-debug-toolbar/compare/4.0.3...5.0.0 + +- Add type hinting and strict types +- Add escaping in templates +- Set minimum requirements to Magento 2.4 + ## [4.0.3] - 2019-11-26 [4.0.3]: https://github.com/Smile-SA/magento2-module-debug-toolbar/compare/4.0.2...4.0.3 diff --git a/DB/Profiler.php b/DB/Profiler.php index 07aaaed..ac40611 100644 --- a/DB/Profiler.php +++ b/DB/Profiler.php @@ -5,9 +5,12 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\DB; use Zend_Db_Profiler as OriginalProfiler; +use Zend_Db_Profiler_Exception; /** * Smile Db Profiler @@ -57,7 +60,7 @@ class Profiler extends OriginalProfiler * @param string $host * @return $this */ - public function setHost($host) + public function setHost(string $host): Profiler { $this->host = $host; @@ -70,7 +73,7 @@ public function setHost($host) * @param string $type * @return $this */ - public function setType($type) + public function setType(string $type): Profiler { $this->type = $type; @@ -84,7 +87,7 @@ public function setType($type) * @param int|null $queryType * @return int|null */ - public function queryStart($queryText, $queryType = null) + public function queryStart($queryText, $queryType = null): ?int { if (!$this->_enabled) { return null; @@ -110,7 +113,7 @@ public function queryStart($queryText, $queryType = null) * @param string $queryText * @return int */ - protected function getTypeFromQuery($queryText) + protected function getTypeFromQuery(string $queryText): int { $queryText = ltrim($queryText); @@ -147,7 +150,7 @@ protected function getTypeFromQuery($queryText) * @param int $typeId * @return string */ - protected function getTypeText($typeId) + protected function getTypeText(int $typeId): string { $type = 'query'; @@ -163,34 +166,21 @@ protected function getTypeText($typeId) * * @param int $queryId * @return string + * @throws Zend_Db_Profiler_Exception */ - public function queryEnd($queryId) + public function queryEnd($queryId): string { $this->lastQueryId = null; return parent::queryEnd($queryId); } - /** - * Ends the last query if exists. Used for finalize broken queries. - * - * @return string - */ - public function queryEndLast() - { - if ($this->lastQueryId !== null) { - return $this->queryEnd($this->lastQueryId); - } - - return self::IGNORED; - } - /** * Get the queries as array. * * @return array */ - public function getQueryProfilesAsArray() + public function getQueryProfilesAsArray(): array { if ($this->queries === null) { $this->queries = []; @@ -215,7 +205,7 @@ public function getQueryProfilesAsArray() * @param Profiler\Query $queryProfile * @return array */ - protected function convertQueryProfileToArray(Profiler\Query $queryProfile) + protected function convertQueryProfileToArray(Profiler\Query $queryProfile): array { return [ 'id' => null, @@ -233,7 +223,7 @@ protected function convertQueryProfileToArray(Profiler\Query $queryProfile) * * @return string[] */ - public function getTypes() + public function getTypes(): array { return $this->types; } @@ -243,7 +233,7 @@ public function getTypes() * * @return array */ - public function getCountPerTypes() + public function getCountPerTypes(): array { $list = [ 'total' => 0, @@ -266,7 +256,7 @@ public function getCountPerTypes() * * @return array */ - public function getTimePerTypes() + public function getTimePerTypes(): array { $list = [ 'total' => 0, diff --git a/DB/Profiler/Query.php b/DB/Profiler/Query.php index af50742..093f60c 100644 --- a/DB/Profiler/Query.php +++ b/DB/Profiler/Query.php @@ -5,8 +5,11 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\DB\Profiler; +use Exception; use Zend_Db_Profiler_Query as OriginalProfilerQuery; /** @@ -26,7 +29,7 @@ class Query extends OriginalProfilerQuery /** * @inheritdoc */ - public function start() + public function start(): void { $this->initTrace(); @@ -36,9 +39,9 @@ public function start() /** * Init the trace */ - protected function initTrace() + protected function initTrace(): void { - $exception = new \Exception(); + $exception = new Exception(); $trace = $exception->getTraceAsString(); // Clean each lines @@ -61,7 +64,7 @@ protected function initTrace() * * @return string[] */ - public function getTrace() + public function getTrace(): array { return $this->trace; } diff --git a/Formatter/Formatter.php b/Formatter/Formatter.php index c6bd379..fba0d4f 100644 --- a/Formatter/Formatter.php +++ b/Formatter/Formatter.php @@ -5,9 +5,12 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Formatter; use Magento\Framework\Escaper; +use RuntimeException; /** * Formatter. @@ -32,7 +35,7 @@ class Formatter /** * @var string */ - protected $formatedValue; + protected $formattedValue; /** * @var string @@ -55,7 +58,7 @@ class Formatter protected $warning = false; /** - * @var string + * @var array */ protected $cssClasses = []; @@ -84,9 +87,9 @@ public function __construct(Escaper $escaper, $value, $type = null, $rules = []) * Prepare the value and type. * * @param mixed $value - * @param string $type + * @param string|null $type */ - protected function prepareValueAndType($value, $type) + protected function prepareValueAndType($value, ?string $type): void { if (is_object($value) || is_array($value)) { $type = 'printable'; @@ -115,7 +118,7 @@ protected function prepareValueAndType($value, $type) * * @param string|null $type */ - protected function prepareType($type) + protected function prepareType(?string $type): void { if ($type === null) { $type = $this->getTypeFromValue(); @@ -125,7 +128,7 @@ protected function prepareType($type) $subType = null; if (strpos($type, '_') !== false) { - list($type, $subType) = explode('_', $type, 2); + [$type, $subType] = explode('_', $type, 2); } if ($type !== 'code' && mb_strlen((string) $this->value) > self::MAX_STRING_LENGTH) { @@ -141,7 +144,7 @@ protected function prepareType($type) * * @return string */ - protected function getTypeFromValue() + protected function getTypeFromValue(): string { $this->value = (string) $this->value; @@ -169,14 +172,14 @@ protected function getTypeFromValue() * * @param array $rules * @return bool - * @throws \Exception + * @throws RuntimeException */ - protected function computeRules($rules) + protected function computeRules(array $rules): bool { $this->rules = $rules; $this->warning = false; - if (count($this->rules) == 0) { + if (count($this->rules) === 0) { return false; } @@ -196,9 +199,9 @@ protected function computeRules($rules) * @param string $ruleTest * @param mixed $ruleValue * @return bool - * @throws \Exception + * @throws RuntimeException */ - protected function computeRule($ruleTest, $ruleValue) + protected function computeRule(string $ruleTest, $ruleValue): bool { switch ($ruleTest) { case 'lt': @@ -220,13 +223,13 @@ protected function computeRule($ruleTest, $ruleValue) return !in_array($this->value, $ruleValue); } - throw new \Exception('Unknown Formatter Rule Test [' . $ruleTest . ']'); + throw new RuntimeException('Unknown Formatter Rule Test [' . $ruleTest . ']'); } /** * Compute the formatted value. */ - protected function computeFormattedValue() + protected function computeFormattedValue(): void { $value = $this->escaper->escapeHtml($this->value); @@ -240,11 +243,11 @@ protected function computeFormattedValue() break; case 'size': - $value = $this->displayHumanSize($value); + $value = $this->displayHumanSize((int) $value); break; case 'time': - $value = $this->displayHumanTime($value); + $value = $this->displayHumanTime((float) $value); break; // text, hour, date, datetime, center, number @@ -252,7 +255,7 @@ protected function computeFormattedValue() break; } - $this->formatedValue = $value; + $this->formattedValue = $value; } /** @@ -261,7 +264,7 @@ protected function computeFormattedValue() * @param int $value * @return string */ - protected function displayHumanSize($value) + protected function displayHumanSize(int $value): string { if ($this->subType === 'ko') { $value /= (1024.); @@ -300,20 +303,20 @@ protected function displayHumanSize($value) /** * Display human time (in seconds). * - * @param int $value + * @param float $value * @return string */ - protected function displayHumanTime($value) + protected function displayHumanTime(float $value): string { - if ($this->subType == 'ms') { + if ($this->subType === 'ms') { $value *= (1000.); } - if ($this->subType == 'm') { + if ($this->subType === 'm') { $value /= (60.); } - if ($this->subType == 'h') { + if ($this->subType === 'h') { $value /= (3600.); } @@ -342,14 +345,14 @@ protected function displayHumanTime($value) /** * Compute the css classes. */ - protected function computeCssClasses() + protected function computeCssClasses(): void { $css = 'st-value-' . $this->type; if ($this->subType) { $css .= '-' . $this->subType; } - if ($this->type == 'code') { + if ($this->type === 'code') { $css = 'hjs-code'; } @@ -365,10 +368,10 @@ protected function computeCssClasses() * * @return array */ - public function getResult() + public function getResult(): array { return [ - 'value' => $this->formatedValue, + 'value' => $this->formattedValue, 'css_class' => implode(' ', $this->cssClasses), 'has_warning' => $this->warning, ]; @@ -379,7 +382,7 @@ public function getResult() * * @return bool */ - public function hasWarning() + public function hasWarning(): bool { return $this->warning; } diff --git a/Helper/Cache.php b/Helper/Cache.php index 4a36976..198af55 100644 --- a/Helper/Cache.php +++ b/Helper/Cache.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Helper; use Magento\Framework\App\Cache\TypeListInterface; @@ -81,7 +83,7 @@ public function __construct(Context $context, TypeListInterface $cacheTypeList) * @param float $deltaTime * @param int $size */ - public function addStat($action, $identifier, $deltaTime = 0., $size = 0) + public function addStat(string $action, string $identifier, float $deltaTime = 0., int $size = 0): void { if (!array_key_exists($identifier, $this->cacheUsage)) { $this->cacheUsage[$identifier] = [ @@ -126,7 +128,7 @@ public function addStat($action, $identifier, $deltaTime = 0., $size = 0) * * @return array */ - public function getCacheUsage() + public function getCacheUsage(): array { return $this->cacheUsage; } @@ -136,7 +138,7 @@ public function getCacheUsage() * * @return array */ - public function getStatsPerAction() + public function getStatsPerAction(): array { return $this->cacheStats; } @@ -146,7 +148,7 @@ public function getStatsPerAction() * * @return array */ - public function getCacheTypes() + public function getCacheTypes(): array { if ($this->cacheTypes === null) { $this->cacheTypes = []; diff --git a/Helper/Config.php b/Helper/Config.php index c363b3d..d0d2413 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Helper; use Magento\Framework\App\Helper\AbstractHelper; @@ -30,7 +32,7 @@ class Config extends AbstractHelper * * @return bool */ - public function isEnabled() + public function isEnabled(): bool { $value = (int) $this->scopeConfig->getValue(self::KEY_CONFIG_ENABLE); @@ -42,7 +44,7 @@ public function isEnabled() * * @return int */ - public function getNbExecutionToKeep() + public function getNbExecutionToKeep(): int { $value = (int) $this->scopeConfig->getValue(self::KEY_CONFIG_NB_EXECUTION_TO_KEEP); diff --git a/Helper/Data.php b/Helper/Data.php index d0ff199..1cee055 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -5,13 +5,19 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Helper; +use DateTime; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; use Magento\Framework\App\State as AppState; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\LocalizedException; use Magento\PageCache\Model\Config as PageCacheConfig; +use RuntimeException; use Smile\DebugToolbar\Block\Toolbar; /** @@ -72,7 +78,7 @@ public function __construct(Context $context, DirectoryList $directoryList, AppS * @param string $code * @return $this */ - public function startTimer($code) + public function startTimer(string $code): Data { $this->timers[$code] = [ 'start' => microtime(true), @@ -89,7 +95,7 @@ public function startTimer($code) * @param string $code * @return $this */ - public function stopTimer($code) + public function stopTimer(string $code): Data { if (!array_key_exists($code, $this->timers)) { $this->startTimer($code); @@ -109,23 +115,13 @@ public function stopTimer($code) * @param string $code * @return float */ - public function getTimer($code) + public function getTimer(string $code): float { $this->stopTimer($code); return $this->timers[$code]['delta']; } - /** - * Get the timers. - * - * @return array - */ - public function getTimers() - { - return $this->timers; - } - /** * Set a value. * @@ -133,7 +129,7 @@ public function getTimers() * @param mixed $value * @return $this */ - public function setValue($key, $value) + public function setValue(string $key, $value): Data { $this->values[$key] = $value; @@ -146,9 +142,8 @@ public function setValue($key, $value) * @param string $key * @param mixed $default * @return mixed - * @throws \Exception */ - public function getValue($key, $default = null) + public function getValue(string $key, $default = null) { if (!array_key_exists($key, $this->values)) { return $default; @@ -162,16 +157,17 @@ public function getValue($key, $default = null) * * @param string $actionName * @return string - * @throws \Exception + * @throws RuntimeException + * @throws LocalizedException * @SuppressWarnings(PMD.StaticAccess) */ - public function initToolbarId($actionName) + public function initToolbarId(string $actionName): string { if ($this->toolbarId !== null) { - throw new \Exception('The toolbar id has already been set'); + throw new RuntimeException('The toolbar id has already been set'); } - $date = \DateTime::createFromFormat('U.u', microtime(true)); + $date = DateTime::createFromFormat('U.u', (string) microtime(true)); $values = [ 'st', @@ -191,12 +187,12 @@ public function initToolbarId($actionName) * Get toolbar id. * * @return string - * @throws \Exception + * @throws RuntimeException */ - public function getToolbarId() + public function getToolbarId(): string { if ($this->toolbarId === null) { - throw new \Exception('The toolbar id has not been set'); + throw new RuntimeException('The toolbar id has not been set'); } return $this->toolbarId; @@ -207,7 +203,7 @@ public function getToolbarId() * * @return string */ - public function getNewTableId() + public function getNewTableId(): string { $this->tableCount++; @@ -218,8 +214,10 @@ public function getNewTableId() * Get the toolbar storage folder. * * @return string + * @throws FileSystemException + * @throws RuntimeException */ - public function getToolbarFolder() + public function getToolbarFolder(): string { $folder = $this->directoryList->getPath('var') . DIRECTORY_SEPARATOR . 'smile_toolbar' . DIRECTORY_SEPARATOR; @@ -234,8 +232,10 @@ public function getToolbarFolder() * Save the current toolbar. * * @param Toolbar $toolbarBlock + * @throws FileSystemException + * @throws RuntimeException */ - public function saveToolbar(Toolbar $toolbarBlock) + public function saveToolbar(Toolbar $toolbarBlock): void { $filename = $this->getToolbarFolder() . $toolbarBlock->getToolbarId() . '.html'; @@ -246,8 +246,10 @@ public function saveToolbar(Toolbar $toolbarBlock) * Clean the old toolbars. * * @param int $nbToKeep + * @throws FileSystemException + * @throws RuntimeException */ - public function cleanOldToolbars($nbToKeep) + public function cleanOldToolbars(int $nbToKeep): void { $list = $this->getListToolbars(); @@ -267,8 +269,10 @@ public function cleanOldToolbars($nbToKeep) * Get the list of all the stored toolbars. * * @return string[] + * @throws FileSystemException + * @throws RuntimeException */ - public function getListToolbars() + public function getListToolbars(): array { $folder = $this->getToolbarFolder(); @@ -289,8 +293,10 @@ public function getListToolbars() * Get the content of all the stored toolbars. * * @return string[] + * @throws FileSystemException + * @throws RuntimeException */ - public function getContentToolbars() + public function getContentToolbars(): array { $list = $this->getListToolbars(); @@ -310,10 +316,10 @@ public function getContentToolbars() * * @return string */ - public function getFullPageCacheMode() + public function getFullPageCacheMode(): string { $key = 'system/full_page_cache/caching_application'; - return $this->scopeConfig->getValue($key) == PageCacheConfig::VARNISH ? 'varnish' : 'build-in'; + return $this->scopeConfig->getValue($key) === PageCacheConfig::VARNISH ? 'varnish' : 'build-in'; } } diff --git a/Helper/Layout.php b/Helper/Layout.php index d548bf3..2798588 100644 --- a/Helper/Layout.php +++ b/Helper/Layout.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Helper; use Magento\Framework\App\Helper\AbstractHelper; @@ -12,6 +14,8 @@ use Magento\Framework\View\Element\AbstractBlock; use Magento\Framework\View\Layout\Element; use Magento\Framework\View\LayoutInterface as MagentoLayoutInterface; +use ReflectionClass; +use ReflectionException; use Smile\DebugToolbar\Layout\Builder; /** @@ -49,8 +53,9 @@ public function __construct( * * @param string $parentNode * @return array + * @throws ReflectionException */ - protected function buildLayout($parentNode) + protected function buildLayout(string $parentNode): array { $layout = []; @@ -81,11 +86,12 @@ protected function buildLayout($parentNode) $block = $this->layout->getBlock($childName); if (is_object($block)) { - $reflectionClass = new \ReflectionClass($block); + $templateFile = $block->getTemplateFile() ? $this->cleanFilename($block->getTemplateFile()) : ''; + $reflectionClass = new ReflectionClass($block); $layout[$childName]['scope'] = $block->isScopePrivate(); $layout[$childName]['classname'] = $this->cleanClassname(get_class($block)); $layout[$childName]['filename'] = $this->cleanFilename($reflectionClass->getFileName()); - $layout[$childName]['template'] = $this->cleanFilename($block->getTemplateFile()); + $layout[$childName]['template'] = $templateFile; } $layout[$childName]['children'] = $this->buildLayout($childName); @@ -102,13 +108,13 @@ protected function buildLayout($parentNode) * @param string $blockName * @return bool */ - protected function isBlockCacheable($blockName) + protected function isBlockCacheable(string $blockName): bool { /** @var Element[] $element */ $element = $this->layout->getXPath('//' . Element::TYPE_BLOCK . '[@name="' . $blockName . '"]'); $cacheable = empty($element) ? null : $element[0]->getAttribute('cacheable'); - return $cacheable === null ? true : $cacheable == 'true'; + return $cacheable === null ? true : $cacheable === 'true'; } /** @@ -117,7 +123,7 @@ protected function isBlockCacheable($blockName) * @param string $classname * @return string */ - protected function cleanClassname($classname) + protected function cleanClassname(string $classname): string { return preg_replace('/\\\\Interceptor$/', '', $classname); } @@ -128,7 +134,7 @@ protected function cleanClassname($classname) * @param string $filename * @return string */ - protected function cleanFilename($filename) + protected function cleanFilename(string $filename): string { return str_replace(BP . '/', '', $filename); @@ -138,8 +144,9 @@ protected function cleanFilename($filename) * Get the event stats. * * @return array + * @throws ReflectionException */ - public function getLayoutBuild() + public function getLayoutBuild(): array { return $this->buildLayout('root'); } @@ -149,7 +156,7 @@ public function getLayoutBuild() * * @return array */ - public function getHandles() + public function getHandles(): array { return $this->layout->getUpdate()->getHandles(); } diff --git a/Helper/Observer.php b/Helper/Observer.php index c8f037d..6a4d132 100644 --- a/Helper/Observer.php +++ b/Helper/Observer.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Helper; use Magento\Framework\App\Helper\AbstractHelper; @@ -28,7 +30,7 @@ class Observer extends AbstractHelper * * @param string $eventName */ - public function initEventStat($eventName) + public function initEventStat(string $eventName): void { $eventName = strtolower($eventName); if (!array_key_exists($eventName, $this->eventStats)) { @@ -53,8 +55,12 @@ public function initEventStat($eventName) * @param string $observerInstance * @param bool $observerDisabled */ - public function initObserverStat($eventName, $observerName, $observerInstance, $observerDisabled) - { + public function initObserverStat( + string $eventName, + string $observerName, + string $observerInstance, + bool $observerDisabled + ): void { $eventName = strtolower($eventName); if (!array_key_exists($observerName, $this->eventStats[$eventName]['observers'])) { $this->eventStats[$eventName]['observers'][$observerName] = [ @@ -78,7 +84,7 @@ public function initObserverStat($eventName, $observerName, $observerInstance, $ * @param string $eventName * @param float $deltaTime */ - public function addEventStat($eventName, $deltaTime) + public function addEventStat(string $eventName, float $deltaTime): void { $eventName = strtolower($eventName); $usage = $this->eventStats[$eventName]; @@ -96,7 +102,7 @@ public function addEventStat($eventName, $deltaTime) * @param string $observerName * @param float $deltaTime */ - public function addObserverStat($eventName, $observerName, $deltaTime) + public function addObserverStat(string $eventName, string $observerName, float $deltaTime): void { $eventName = strtolower($eventName); $usage = $this->eventStats[$eventName]['observers'][$observerName]; @@ -112,7 +118,7 @@ public function addObserverStat($eventName, $observerName, $deltaTime) * * @return array */ - public function getEventStats() + public function getEventStats(): array { return $this->eventStats; } diff --git a/Helper/Preference.php b/Helper/Preference.php index 98d49c6..ce1401c 100644 --- a/Helper/Preference.php +++ b/Helper/Preference.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Helper; use Magento\Framework\App\Helper\AbstractHelper; @@ -14,6 +16,8 @@ use Magento\Framework\Interception\ObjectManager\Config\Developer as ObjectManagerConfigDev; use Magento\Framework\Interception\PluginListInterface as PluginList; use Magento\Framework\ObjectManager\ConfigInterface as ObjectManagerConfig; +use ReflectionClass; +use ReflectionException; /** * Helper: Preference @@ -54,11 +58,12 @@ public function __construct( * Get the plugin stats. * * @return array + * @throws ReflectionException */ - public function getPluginStats() + public function getPluginStats(): array { // Get some properties without rewrite but the properties are private - $reflectionClass = new \ReflectionClass($this->pluginList); + $reflectionClass = new ReflectionClass($this->pluginList); /** @var DefinitionInterface $definitions */ $property = $reflectionClass->getProperty('_definitions'); @@ -78,7 +83,7 @@ public function getPluginStats() $methods = $definitions->getMethodList($pluginInstance); foreach ($methods as $method => $methodType) { - $methods[$method] = $this->getPluginType($methodType); + $methods[$method] = $this->getPluginType((int) $methodType); } $plugins[] = [ @@ -101,7 +106,7 @@ public function getPluginStats() * @param int $methodType * @return string */ - protected function getPluginType($methodType) + protected function getPluginType(int $methodType): string { switch ($methodType) { case DefinitionInterface::LISTENER_AROUND: @@ -121,13 +126,14 @@ protected function getPluginType($methodType) * Get the preference stats. * * @return array + * @throws ReflectionException */ - public function getPreferenceStats() + public function getPreferenceStats(): array { $preferences = []; $config = $this->objectManagerConfig; - $reflectionClass = new \ReflectionClass($config); + $reflectionClass = new ReflectionClass($config); $property = null; /** diff --git a/Helper/Profiler.php b/Helper/Profiler.php index 44df84d..3b8ae24 100644 --- a/Helper/Profiler.php +++ b/Helper/Profiler.php @@ -5,10 +5,13 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Helper; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\Profiler\Driver\Standard\Stat; +use RuntimeException; /** * Helper: Profiler @@ -22,7 +25,7 @@ class Profiler extends AbstractHelper /** * @var Stat */ - static protected $stat; + protected static $stat; /** * @var array @@ -34,7 +37,8 @@ class Profiler extends AbstractHelper * * @param Stat $stat */ - public static function setStat(Stat $stat) + // phpcs:ignore Magento2.Functions.StaticFunction.StaticFunction + public static function setStat(Stat $stat): void { self::$stat = $stat; } @@ -43,12 +47,12 @@ public static function setStat(Stat $stat) * Get the profiler stat object. * * @return Stat - * @throws \Exception + * @throws RuntimeException */ - public function getStat() + public function getStat(): Stat { if (self::$stat === null) { - throw new \Exception('Global Smile Profiler Stat is missing'); + throw new RuntimeException('Global Smile Profiler Stat is missing'); } return self::$stat; @@ -57,12 +61,12 @@ public function getStat() /** * Compute the stats. * - * @throws \Exception + * @throws RuntimeException */ - public function computeStats() + public function computeStats(): void { if ($this->timers !== null) { - throw new \Exception('Profiler Stats are already computed'); + throw new RuntimeException('Profiler Stats are already computed'); } $this->prepareTimers(); @@ -72,9 +76,9 @@ public function computeStats() * Get the stat timers. * * @return array - * @throws \Exception + * @throws RuntimeException */ - public function getTimers() + public function getTimers(): array { if ($this->timers === null) { $this->prepareTimers(); @@ -86,9 +90,9 @@ public function getTimers() /** * Prepare the timers, with sorting. * - * @throws \Exception + * @throws RuntimeException */ - protected function prepareTimers() + protected function prepareTimers(): void { $this->timers = []; @@ -140,7 +144,7 @@ protected function prepareTimers() * * @return bool */ - protected function removeToolbarObserverFromTimers() + protected function removeToolbarObserverFromTimers(): bool { $toolbarKey = 'OBSERVER:smile_debugtoolbar_add_toolbar_to_response'; @@ -152,12 +156,14 @@ protected function removeToolbarObserverFromTimers() $toolbarSum = $toolbarTimer['sum']; $toolbarAvg = $toolbarTimer['avg']; $keys = explode('->', $toolbarTimer['id']); + $numberKeys = count($keys); - while (count($keys) > 1) { + while ($numberKeys > 1) { array_pop($keys); $key = implode('->', $keys); $this->timers[$key]['sum'] -= $toolbarSum; $this->timers[$key]['avg'] -= $toolbarAvg; + $numberKeys = count($keys); } unset($this->timers[$toolbarTimer['id']]); @@ -168,7 +174,7 @@ protected function removeToolbarObserverFromTimers() /** * Calculate the percents. */ - protected function calculatePercents() + protected function calculatePercents(): void { foreach ($this->timers as &$timer) { $percent = 0; diff --git a/Layout/Builder.php b/Layout/Builder.php index 0450b90..67ac1c6 100644 --- a/Layout/Builder.php +++ b/Layout/Builder.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Layout; use Magento\Framework\View\Layout\BuilderInterface; @@ -35,7 +37,7 @@ public function __construct(LayoutInterface $layout) /** * @inheritdoc */ - public function build() + public function build(): LayoutInterface { return $this->layout; } diff --git a/Model/ResourceModel/Info.php b/Model/ResourceModel/Info.php index afb1093..1a42463 100644 --- a/Model/ResourceModel/Info.php +++ b/Model/ResourceModel/Info.php @@ -5,10 +5,17 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Model\ResourceModel; +use Exception; use Magento\Framework\App\ResourceConnection; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\DB\Adapter\Pdo\Mysql; +use RuntimeException; use Smile\DebugToolbar\DB\Profiler; +use Zend_Db_Statement_Exception; /** * Main Debug Toolbar Resource Model @@ -40,9 +47,9 @@ public function __construct(ResourceConnection $resourceConnection) /** * Get the connection. * - * @return \Magento\Framework\DB\Adapter\AdapterInterface + * @return AdapterInterface */ - public function getConnection() + public function getConnection(): AdapterInterface { return $this->resourceConnection->getConnection('read'); } @@ -51,8 +58,9 @@ public function getConnection() * Get Mysql versions. * * @return string[] + * @throws Zend_Db_Statement_Exception */ - public function getMysqlVersions() + public function getMysqlVersions(): array { if ($this->version === null) { $this->version = []; @@ -72,8 +80,9 @@ public function getMysqlVersions() * * @param string $key * @return string + * @throws Zend_Db_Statement_Exception */ - public function getMysqlVersion($key = 'version') + public function getMysqlVersion(string $key = 'version'): string { $values = $this->getMysqlVersions(); @@ -88,8 +97,9 @@ public function getMysqlVersion($key = 'version') * Get the executed queries. * * @return array + * @throws Exception */ - public function getExecutedQueries() + public function getExecutedQueries(): array { return $this->getProfiler()->getQueryProfilesAsArray(); } @@ -98,8 +108,9 @@ public function getExecutedQueries() * Get the count per types. * * @return array + * @throws Exception */ - public function getCountPerTypes() + public function getCountPerTypes(): array { return $this->getProfiler()->getCountPerTypes(); } @@ -108,8 +119,9 @@ public function getCountPerTypes() * Get the time per types. * * @return array + * @throws Exception */ - public function getTimePerTypes() + public function getTimePerTypes(): array { return $this->getProfiler()->getTimePerTypes(); } @@ -117,19 +129,19 @@ public function getTimePerTypes() /** * Get the profiler. * - * @return \Smile\DebugToolbar\DB\Profiler - * @throws \Exception + * @return Profiler + * @throws RuntimeException */ - protected function getProfiler() + protected function getProfiler(): Profiler { - /** @var \Magento\Framework\DB\Adapter\Pdo\Mysql $connection */ + /** @var Mysql $connection */ $connection = $this->resourceConnection->getConnection(); /** @var Profiler $profiler */ $profiler = $connection->getProfiler(); if (!($profiler instanceof Profiler)) { - throw new \Exception( + throw new RuntimeException( 'DB Profiler is not set to \Smile\DebugToolbar\DB\Profiler. Please disable and enable the ToolBar' ); } diff --git a/Observer/AddToolbar.php b/Observer/AddToolbar.php index 8263f39..6009f88 100644 --- a/Observer/AddToolbar.php +++ b/Observer/AddToolbar.php @@ -5,11 +5,16 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Observer; +use Exception; use Magento\Framework\App\Request\Http as MagentoRequest; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\HTTP\PhpEnvironment\Response as MagentoResponse; use Smile\DebugToolbar\Block\Toolbar; use Smile\DebugToolbar\Block\ToolbarFactory; @@ -79,7 +84,7 @@ public function __construct( * @inheritdoc * @SuppressWarnings(PHPMD.ExitExpression) */ - public function execute(Observer $observer) + public function execute(Observer $observer): void { if (!$this->helperConfig->isEnabled()) { return; @@ -102,7 +107,7 @@ public function execute(Observer $observer) // Build the toolbar try { $this->buildToolbar($request, $response); - } catch (\Exception $e) { + } catch (Exception $e) { // @codingStandardsIgnoreStart echo json_encode($e->getMessage()); exit; @@ -115,11 +120,13 @@ public function execute(Observer $observer) * * @param MagentoRequest $request * @param MagentoResponse $response + * @throws LocalizedException + * @throws FileSystemException */ - protected function buildToolbar( + private function buildToolbar( MagentoRequest $request, MagentoResponse $response - ) { + ): void { // Init the toolbar id $this->helperData->initToolbarId($request->getFullActionName()); @@ -149,10 +156,10 @@ protected function buildToolbar( * @param MagentoResponse $response * @return Toolbar */ - protected function getCurrentExecutionToolbarBlock( + private function getCurrentExecutionToolbarBlock( MagentoRequest $request, MagentoResponse $response - ) { + ): Toolbar { /** @var Toolbar $block */ $block = $this->blockToolbarFactory->create(); $block->loadZones($request, $response); @@ -165,7 +172,7 @@ protected function getCurrentExecutionToolbarBlock( * * @return Toolbars */ - protected function getToolbarsBlock() + private function getToolbarsBlock(): Toolbars { /** @var Toolbars $block */ $block = $this->blockToolbarsFactory->create(); diff --git a/Observer/AddZones.php b/Observer/AddZones.php index ab14724..b2862cb 100644 --- a/Observer/AddZones.php +++ b/Observer/AddZones.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Observer; use Magento\Framework\Event\Observer; @@ -73,7 +75,7 @@ public function __construct( /** * @inheritdoc */ - public function execute(Observer $observer) + public function execute(Observer $observer): void { $list = $observer->getEvent()->getData('zones')->getData('list'); diff --git a/Observer/EnableDbProfiler.php b/Observer/EnableDbProfiler.php index decdad6..69152b5 100644 --- a/Observer/EnableDbProfiler.php +++ b/Observer/EnableDbProfiler.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Observer; use Magento\Framework\App\DeploymentConfig\Reader as DeploymentConfigReader; @@ -12,6 +14,8 @@ use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\RuntimeException; use Smile\DebugToolbar\DB\Profiler as DbProfiler; use Smile\DebugToolbar\Helper\Config as HelperConfig; @@ -56,8 +60,10 @@ public function __construct( /** * @inheritdoc + * @throws FileSystemException + * @throws RuntimeException */ - public function execute(Observer $observer) + public function execute(Observer $observer): void { $env = $this->deploymentConfigReader->load(ConfigFilePool::APP_ENV); diff --git a/Plugin/App/Action/AbstractAction.php b/Plugin/App/Action/AbstractAction.php index f213e12..d298059 100644 --- a/Plugin/App/Action/AbstractAction.php +++ b/Plugin/App/Action/AbstractAction.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Plugin\App\Action; use Magento\Framework\App\Action\AbstractAction as MagentoAction; @@ -49,7 +51,7 @@ public function __construct(HelperData $helperData, HelperConfig $helperConfig) * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeDispatch(MagentoAction $subject, RequestInterface $request) + public function beforeDispatch(MagentoAction $subject, RequestInterface $request): array { if ($this->helperConfig->isEnabled()) { $className = get_class($subject); diff --git a/Plugin/App/Cache.php b/Plugin/App/Cache.php index 3371fe3..f42c584 100644 --- a/Plugin/App/Cache.php +++ b/Plugin/App/Cache.php @@ -5,8 +5,11 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Plugin\App; +use Closure; use Magento\Framework\App\CacheInterface; use Smile\DebugToolbar\Helper\Cache as HelperCache; @@ -36,18 +39,18 @@ public function __construct(HelperCache $helperCache) * Add stats on load. * * @param CacheInterface $subject - * @param \Closure $closure + * @param Closure $closure * @param string $identifier - * @return string + * @return string|bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function aroundLoad(CacheInterface $subject, \Closure $closure, $identifier) + public function aroundLoad(CacheInterface $subject, Closure $closure, string $identifier) { $startTime = microtime(true); $result = $closure($identifier); - $this->helperCache->addStat('load', $identifier, microtime(true) - $startTime, strlen($result)); + $this->helperCache->addStat('load', $identifier, microtime(true) - $startTime, strlen((string) $result)); return $result; } @@ -56,7 +59,7 @@ public function aroundLoad(CacheInterface $subject, \Closure $closure, $identifi * Add stats on save. * * @param CacheInterface $subject - * @param \Closure $closure + * @param Closure $closure * @param string $data * @param string $identifier * @param array $tags @@ -66,12 +69,12 @@ public function aroundLoad(CacheInterface $subject, \Closure $closure, $identifi */ public function aroundSave( CacheInterface $subject, - \Closure $closure, - $data, - $identifier, - $tags = [], - $lifeTime = null - ) { + Closure $closure, + string $data, + string $identifier, + array $tags = [], + ?int $lifeTime = null + ): bool { $startTime = microtime(true); $result = $closure($data, $identifier, $tags, $lifeTime); @@ -85,12 +88,12 @@ public function aroundSave( * Add stats on remove. * * @param CacheInterface $subject - * @param \Closure $closure + * @param Closure $closure * @param string $identifier * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function aroundRemove(CacheInterface $subject, \Closure $closure, $identifier) + public function aroundRemove(CacheInterface $subject, Closure $closure, string $identifier): bool { $startTime = microtime(true); diff --git a/Plugin/App/Http.php b/Plugin/App/Http.php index f5c3d32..4c1f470 100644 --- a/Plugin/App/Http.php +++ b/Plugin/App/Http.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Plugin\App; use Magento\Framework\App\Http as MagentoHttp; @@ -47,7 +49,7 @@ public function __construct(HelperData $helperData, HelperConfig $helperConfig) * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeLaunch(MagentoHttp $subject) + public function beforeLaunch(MagentoHttp $subject): array { if ($this->helperConfig->isEnabled()) { $this->helperData->startTimer('app_http'); diff --git a/Plugin/Event/Invoker.php b/Plugin/Event/Invoker.php index cd3ae2e..3c377ff 100644 --- a/Plugin/Event/Invoker.php +++ b/Plugin/Event/Invoker.php @@ -5,6 +5,8 @@ * Do not edit or add to this file if you wish to upgrade this module * to newer versions in the future. */ +declare(strict_types=1); + namespace Smile\DebugToolbar\Plugin\Event; use Closure; diff --git a/Plugin/Event/Manager.php b/Plugin/Event/Manager.php index 56865aa..80b34d9 100644 --- a/Plugin/Event/Manager.php +++ b/Plugin/Event/Manager.php @@ -7,6 +7,7 @@ */ namespace Smile\DebugToolbar\Plugin\Event; +use Closure; use Magento\Framework\Event\ManagerInterface as MagentoManager; use Smile\DebugToolbar\Helper\Observer as HelperObserver; @@ -36,7 +37,7 @@ public function __construct(HelperObserver $helperObserver) * Plugin on dispatch. * * @param MagentoManager $subject - * @param \Closure $closure + * @param Closure $closure * @param string $eventName * @param array $data * @return mixed @@ -44,8 +45,8 @@ public function __construct(HelperObserver $helperObserver) */ public function aroundDispatch( MagentoManager $subject, - \Closure $closure, - $eventName, + Closure $closure, + string $eventName, array $data = [] ) { $this->helperObserver->initEventStat($eventName); diff --git a/composer.json b/composer.json index 3233a0b..c8130a4 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "license": "EPL-2.0", "require": { "php": ">=7.1.3", - "magento/framework": ">=102.0.0" + "magento/framework": ">=103.0.0" }, "autoload": { "files": [ diff --git a/registration.php b/registration.php index abf0e9a..1cfab5e 100644 --- a/registration.php +++ b/registration.php @@ -7,6 +7,9 @@ */ use Magento\Framework\Component\ComponentRegistrar; +use Magento\Framework\Profiler; +use Magento\Framework\Profiler\Driver\Standard\Stat; +use Smile\DebugToolbar\Helper\Profiler as SmileProfiler; if (PHP_SAPI !== 'cli') { // We need to declare the stat profiler manually, to use it after @@ -14,13 +17,13 @@ 'drivers' => [ [ 'output' => false, - 'stat' => new \Magento\Framework\Profiler\Driver\Standard\Stat(), + 'stat' => new Stat(), ], ], ]; - \Magento\Framework\Profiler::applyConfig($options, BP, false); - \Smile\DebugToolbar\Helper\Profiler::setStat($options['drivers'][0]['stat']); + Profiler::applyConfig($options, BP, false); + SmileProfiler::setStat($options['drivers'][0]['stat']); } ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Smile_DebugToolbar', __DIR__); diff --git a/view/base/templates/toolbar.phtml b/view/base/templates/toolbar.phtml index b698fa2..52611d6 100644 --- a/view/base/templates/toolbar.phtml +++ b/view/base/templates/toolbar.phtml @@ -6,70 +6,72 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Toolbar $block */ +use Magento\Framework\Escaper; +use Smile\DebugToolbar\Block\Toolbar; +/** @var Toolbar $block */ +/** @var Escaper $escaper */ $zones = $block->getZones(); $toolbarId = $block->getToolbarId(); ?> -
+
- -toHtml() ?> -
-
- - +
Smile Toolbar Navigator - Loading
-
+
- - - getTitle() ?> - - + + + escapeHtml($zone->getTitle()) ?> + +
diff --git a/view/base/templates/toolbars.phtml b/view/base/templates/toolbars.phtml index bf3176c..5873ca6 100644 --- a/view/base/templates/toolbars.phtml +++ b/view/base/templates/toolbars.phtml @@ -6,16 +6,13 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Toolbars $block */ +use Smile\DebugToolbar\Block\Toolbars; +/** @var Toolbars $block */ $toolbars = $block->getToolbarList(); -foreach ($toolbars as $toolbarContent): - echo $toolbarContent."\n"; -endforeach; -?> +foreach ($toolbars as $toolbarContent) : ?> + +
diff --git a/view/base/templates/zone/cache.phtml b/view/base/templates/zone/cache.phtml index 71db6ab..9f732f5 100644 --- a/view/base/templates/zone/cache.phtml +++ b/view/base/templates/zone/cache.phtml @@ -6,71 +6,73 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Cache $block */ +use Smile\DebugToolbar\Block\Zone\Cache; +/** @var Cache $block */ $list = $block->getCacheUsage(); foreach ($list as $key => $row) { $row['identifier'] = $block->formatValue($row['identifier'], [], 'text'); - $row['nb_call'] = $block->formatValue($row['nb_call'], [], 'number'); + $row['nb_call'] = $block->formatValue($row['nb_call'], [], 'number'); $row['size_total'] = $block->formatValue($row['size_total'], [], 'size_ko'); - $row['size_mean'] = $block->formatValue($row['size_mean'], ['gt' => 128*1024], 'size_ko'); + $row['size_mean'] = $block->formatValue($row['size_mean'], ['gt' => 128 * 1024], 'size_ko'); $row['time_total'] = $block->formatValue($row['time_total'], [], 'time_ms'); - $row['time_mean'] = $block->formatValue($row['time_mean'], ['gt' => 0.01], 'time_ms'); - $row['html_info'] = $block->buildHtmlInfo($row['calls']); + $row['time_mean'] = $block->formatValue($row['time_mean'], ['gt' => 0.01], 'time_ms'); + $row['html_info'] = $block->buildHtmlInfo($row['calls']); $list[$key] = $row; } +?> -echo $block->displayTable( +displayTable( 'Cache Usage', $list, [ - 'identifier' => ['label' => 'Identifier', 'width' => ''], - 'nb_call' => ['label' => 'Nb Call', 'width' => '100px'], - 'size_total' => ['label' => 'Size Total', 'width' => '120px'], - 'size_mean' => ['label' => 'Size Mean', 'width' => '120px'], - 'time_total' => ['label' => 'Time Total', 'width' => '120px'], - 'time_mean' => ['label' => 'Time Mean', 'width' => '120px'], + 'identifier' => ['label' => 'Identifier', 'width' => ''], + 'nb_call' => ['label' => 'Nb Call', 'width' => '100px'], + 'size_total' => ['label' => 'Size Total', 'width' => '120px'], + 'size_mean' => ['label' => 'Size Mean', 'width' => '120px'], + 'time_total' => ['label' => 'Time Total', 'width' => '120px'], + 'time_mean' => ['label' => 'Time Mean', 'width' => '120px'], ], 'html_info' -); +) ?> +getStatsPerAction(); $sections['Number'] = [ - 'total' => $block->formatValue($sections['Number']['total'], ['gt' => 150], 'number'), - 'load' => $block->formatValue($sections['Number']['load'], ['gt' => 100], 'number'), - 'save' => $block->formatValue($sections['Number']['save'], ['gt' => 100], 'number'), + 'total' => $block->formatValue($sections['Number']['total'], ['gt' => 150], 'number'), + 'load' => $block->formatValue($sections['Number']['load'], ['gt' => 100], 'number'), + 'save' => $block->formatValue($sections['Number']['save'], ['gt' => 100], 'number'), 'remove' => $block->formatValue($sections['Number']['remove'], ['gt' => 50], 'number'), ]; $sections['Size'] = [ - 'total' => $block->formatValue($sections['Size']['total'], ['gt' => 1024*1024], 'size'), - 'load' => $block->formatValue($sections['Size']['load'], ['gt' => 1024*1024], 'size'), - 'save' => $block->formatValue($sections['Size']['save'], ['gt' => 1024*1024], 'size'), - 'remove' => $block->formatValue($sections['Size']['remove'], ['gt' => 1024*1024], 'size'), + 'total' => $block->formatValue($sections['Size']['total'], ['gt' => 1024 * 1024], 'size'), + 'load' => $block->formatValue($sections['Size']['load'], ['gt' => 1024 * 1024], 'size'), + 'save' => $block->formatValue($sections['Size']['save'], ['gt' => 1024 * 1024], 'size'), + 'remove' => $block->formatValue($sections['Size']['remove'], ['gt' => 1024 * 1024], 'size'), ]; $sections['Time'] = [ - 'total' => $block->formatValue($sections['Time']['total'], ['gt' => 0.5], 'time'), - 'load' => $block->formatValue($sections['Time']['load'], ['gt' => 0.5], 'time'), - 'save' => $block->formatValue($sections['Time']['save'], ['gt' => 0.5], 'time'), + 'total' => $block->formatValue($sections['Time']['total'], ['gt' => 0.5], 'time'), + 'load' => $block->formatValue($sections['Time']['load'], ['gt' => 0.5], 'time'), + 'save' => $block->formatValue($sections['Time']['save'], ['gt' => 0.5], 'time'), 'remove' => $block->formatValue($sections['Time']['remove'], ['gt' => 0.5], 'time'), ]; $block->addToSummary('Cache', 'Number', $sections['Number']['total']); $block->addToSummary('Cache', 'Time', $sections['Time']['total']); $block->addToSummary('Cache', 'Size', $sections['Size']['total']); +?> -echo $block->displaySectionsGrouped($sections); +displaySectionsGrouped($sections) ?> + $block->getCacheTypes(), + 'Types' => $block->getCacheTypes(), 'Config' => [ - 'Mode' => $block->formatValue($block->getCacheMode(), ['neq' => 'Cm_Cache_Backend_Redis'], 'text'), + 'Mode' => $block->formatValue($block->getCacheMode(), ['neq' => 'Cm_Cache_Backend_Redis'], 'text'), 'Config' => $block->getCacheInfo(), ], ]; @@ -78,5 +80,6 @@ $sections = [ foreach ($sections['Types'] as $type => $value) { $sections['Types'][$type] = $block->formatValue($value, ['neq' => 'Enabled'], 'text'); } +?> -echo $block->displaySections($sections); +displaySections($sections) ?> diff --git a/view/base/templates/zone/generic.phtml b/view/base/templates/zone/generic.phtml index 4eb5e6e..d1121ad 100644 --- a/view/base/templates/zone/generic.phtml +++ b/view/base/templates/zone/generic.phtml @@ -6,33 +6,32 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Generic $block */ +use Smile\DebugToolbar\Block\Zone\Generic; +/** @var Generic $block */ $sections = [ 'Product' => [ 'Product' => $block->getProductName(), 'Edition' => $block->getProductEdition(), - //'Version' => $block->getProductVersion(), // disabled because it takes 300ms?! + 'Version' => $block->getProductVersion(), 'Area' => $block->getMagentoArea(), 'Mode' => $block->getMagentoMode(), ], 'Server' => [ - 'PHP Version' => $block->getPhpVersion(), - 'PHP Memory Limit' => $block->formatValue($block->getPhpMemoryLimit(), ['lt' => 256*1024*1024], 'size'), - 'PHP Memory Used' => $block->formatValue($block->getPhpMemoryUsed(), ['gt' => 128*1024*1024], 'size'), + 'PHP Version' => $block->getPhpVersion(), + 'PHP Memory Limit' => $block->formatValue($block->getPhpMemoryLimit(), ['lt' => 256 * 1024 * 1024], 'size'), + 'PHP Memory Used' => $block->formatValue($block->getPhpMemoryUsed(), ['gt' => 128 * 1024 * 1024], 'size'), 'PHP Max Execution Time' => $block->formatValue($block->getPhpMaxExecutionTime(), ['lt' => 60], 'time'), - 'PHP Execution Time' => $block->formatValue($block->getPhpExecutionTime(), ['gt' => 5], 'time'), + 'PHP Execution Time' => $block->formatValue($block->getPhpExecutionTime(), ['gt' => 5], 'time'), ], 'Session' => [ - 'Mode' => $block->formatValue($block->getSessionMode(), ['neq' => 'redis'], 'text'), + 'Mode' => $block->formatValue($block->getSessionMode(), ['neq' => 'redis'], 'text'), 'Config' => $block->getSessionInfo(), ], ]; $block->addToSummary('Server', 'PHP Memory Used', $sections['Server']['PHP Memory Used']); $block->addToSummary('Server', 'PHP Execution Time', $sections['Server']['PHP Execution Time']); +?> -echo $block->displaySections($sections); +displaySections($sections) ?> diff --git a/view/base/templates/zone/layout.phtml b/view/base/templates/zone/layout.phtml index 7869581..dc9be9f 100644 --- a/view/base/templates/zone/layout.phtml +++ b/view/base/templates/zone/layout.phtml @@ -6,17 +6,15 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Layout $block */ +use Smile\DebugToolbar\Block\Zone\Layout; +/** @var Layout $block */ $sections = [ 'Handles' => $block->getHandles() ]; - -echo $block->displaySections($sections); ?> + +displaySections($sections) ?>
Method Type
@@ -29,6 +27,6 @@ echo $block->displaySections($sections); -displayLayoutTable() ?> + displayLayoutTable() ?>
diff --git a/view/base/templates/zone/mysql.phtml b/view/base/templates/zone/mysql.phtml index 7765ff2..8ea77c6 100644 --- a/view/base/templates/zone/mysql.phtml +++ b/view/base/templates/zone/mysql.phtml @@ -6,77 +6,82 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Mysql $block */ +use Magento\Framework\Escaper; +use Smile\DebugToolbar\Block\Zone\Mysql; +/** @var Mysql $block */ +/** @var Escaper $escaper */ try { $list = $block->getQueries(); } catch (\Exception $e) { echo '

PROFILER ERROR

'; - echo $e->getMessage(); + echo $escaper->escapeHtml($e->getMessage()); return; } foreach ($list as $key => $row) { - $row['id'] = $block->formatValue($row['id'], [], 'number'); - $row['type'] = $block->formatValue($row['type'], [], 'center'); - $row['time'] = $block->formatValue($row['time'], ['gt' => 0.05], 'time_ms'); + $row['id'] = $block->formatValue($row['id'], [], 'number'); + $row['type'] = $block->formatValue($row['type'], [], 'center'); + $row['time'] = $block->formatValue($row['time'], ['gt' => 0.05], 'time_ms'); $row['query'] = $block->formatValue($row['query'], [], 'code_sql'); - $row['html_info'] = $block->buildHtmlInfo($row['params'], $row['trace']); + $row['html_info'] = $block->buildHtmlInfo($row['params'], $row['trace']); $list[$key] = $row; } +?> -echo $block->displayTable( +displayTable( 'MySQL Queries', $list, [ - 'id' => ['label' => 'Id', 'width' => '60px'], - 'type' => ['label' => 'Type', 'width' => '100px'], - 'time' => ['label' => 'Time', 'width' => '100px'], + 'id' => ['label' => 'Id', 'width' => '60px'], + 'type' => ['label' => 'Type', 'width' => '100px'], + 'time' => ['label' => 'Time', 'width' => '100px'], 'query' => ['label' => 'Query', 'width' => ''], ], 'html_info' -); +) ?> + $block->getCountPerTypes(), - 'Time' => $block->getTimePerTypes(), + 'Time' => $block->getTimePerTypes(), ]; $sections['Time'] = [ - 'total' => $block->formatValue($sections['Time']['total'], ['gt' => 1.], 'time'), - 'select' => $block->formatValue($sections['Time']['select'], ['gt' => 1.], 'time'), - 'insert' => $block->formatValue($sections['Time']['insert'], ['gt' => 0.5], 'time'), - 'update' => $block->formatValue($sections['Time']['update'], ['gt' => 0.5], 'time'), - 'delete' => $block->formatValue($sections['Time']['delete'], ['gt' => 0.5], 'time'), - 'query' => $block->formatValue($sections['Time']['query'], ['gt' => 0.5], 'time'), + 'total' => $block->formatValue($sections['Time']['total'], ['gt' => 1.], 'time'), + 'select' => $block->formatValue($sections['Time']['select'], ['gt' => 1.], 'time'), + 'insert' => $block->formatValue($sections['Time']['insert'], ['gt' => 0.5], 'time'), + 'update' => $block->formatValue($sections['Time']['update'], ['gt' => 0.5], 'time'), + 'delete' => $block->formatValue($sections['Time']['delete'], ['gt' => 0.5], 'time'), + 'query' => $block->formatValue($sections['Time']['query'], ['gt' => 0.5], 'time'), 'transaction' => $block->formatValue($sections['Time']['transaction'], ['gt' => 0.5], 'time'), - 'connect' => $block->formatValue($sections['Time']['connect'], ['gt' => 0.01], 'time'), + 'connect' => $block->formatValue($sections['Time']['connect'], ['gt' => 0.01], 'time'), ]; $sections['Number'] = [ - 'total' => $block->formatValue($sections['Number']['total'], ['gt' => 200], 'number'), - 'select' => $block->formatValue($sections['Number']['select'], ['gt' => 200], 'number'), - 'insert' => $block->formatValue($sections['Number']['insert'], ['gt' => 15], 'number'), - 'update' => $block->formatValue($sections['Number']['update'], ['gt' => 15], 'number'), - 'delete' => $block->formatValue($sections['Number']['delete'], ['gt' => 15], 'number'), - 'query' => $block->formatValue($sections['Number']['query'], ['gt' => 15], 'number'), + 'total' => $block->formatValue($sections['Number']['total'], ['gt' => 200], 'number'), + 'select' => $block->formatValue($sections['Number']['select'], ['gt' => 200], 'number'), + 'insert' => $block->formatValue($sections['Number']['insert'], ['gt' => 15], 'number'), + 'update' => $block->formatValue($sections['Number']['update'], ['gt' => 15], 'number'), + 'delete' => $block->formatValue($sections['Number']['delete'], ['gt' => 15], 'number'), + 'query' => $block->formatValue($sections['Number']['query'], ['gt' => 15], 'number'), 'transaction' => $block->formatValue($sections['Number']['transaction'], ['gt' => 15], 'number'), - 'connect' => $block->formatValue($sections['Number']['connect'], ['gt' => 1], 'number'), + 'connect' => $block->formatValue($sections['Number']['connect'], ['gt' => 1], 'number'), ]; $block->addToSummary('Mysql', 'Number', $sections['Number']['total']); $block->addToSummary('Mysql', 'Time', $sections['Time']['total']); +?> -echo $block->displaySectionsGrouped($sections); +displaySectionsGrouped($sections) ?> + [ 'Version' => $block->getMysqlVersion(), ], ]; +?> -echo $block->displaySections($sections); +displaySections($sections) ?> diff --git a/view/base/templates/zone/observer.phtml b/view/base/templates/zone/observer.phtml index 799846b..0ff60a5 100644 --- a/view/base/templates/zone/observer.phtml +++ b/view/base/templates/zone/observer.phtml @@ -6,23 +6,21 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Observer $block */ +use Smile\DebugToolbar\Block\Zone\Observer; +/** @var Observer $block */ $stats = $block->getObserverStats(); $sections = [ 'Used Events' => [ - 'Number' => 0, - 'Called' => 0, - 'Time' => 0, + 'Number' => 0, + 'Called' => 0, + 'Time' => 0, ], 'Unused Events' => [ - 'Number' => 0, - 'Called' => 0, - 'Time' => 0, + 'Number' => 0, + 'Called' => 0, + 'Time' => 0, ], ]; @@ -31,68 +29,71 @@ $unused = []; foreach ($stats as $event) { $section = &$sections['Unused Events']; $list = &$unused; - if ($event['nb_observers'] > 0 ) { + if ($event['nb_observers'] > 0) { $section = &$sections['Used Events']; $list = &$used; $event['html_info'] = $block->buildHtmlInfo($event['observers']); } $section['Number']++; - $section['Called']+= $event['nb_call']; - $section['Time'] += $event['time_total']; + $section['Called'] += $event['nb_call']; + $section['Time'] += $event['time_total']; - $event['id'] = $block->formatValue(count($list)+1, [], 'number'); - $event['event_name'] = $block->formatValue($event['event_name'], [], 'text'); - $event['nb_call'] = $block->formatValue($event['nb_call'], ['gt' => 200], 'number'); - $event['time_total'] = $block->formatValue($event['time_total'], ['gt' => 0.5], 'time_ms'); - $event['time_mean'] = $block->formatValue($event['time_mean'], ['gt' => 0.5], 'time_ms'); + $event['id'] = $block->formatValue(count($list) + 1, [], 'number'); + $event['event_name'] = $block->formatValue($event['event_name'], [], 'text'); + $event['nb_call'] = $block->formatValue($event['nb_call'], ['gt' => 200], 'number'); + $event['time_total'] = $block->formatValue($event['time_total'], ['gt' => 0.5], 'time_ms'); + $event['time_mean'] = $block->formatValue($event['time_mean'], ['gt' => 0.5], 'time_ms'); $event['nb_observers'] = $block->formatValue($event['nb_observers'], ['gt' => 20], 'number'); $list[] = $event; } unset($stats); +?> -echo $block->displayTable( +displayTable( 'Used Events', $used, [ - 'id' => ['label' => 'Id', 'width' => '60px'], - 'event_name' => ['label' => 'Name', 'width' => ''], - 'nb_call' => ['label' => 'Nb Call', 'width' => '100px'], - 'time_total' => ['label' => 'Total Time', 'width' => '120px'], - 'time_mean' => ['label' => 'Mean Time', 'width' => '120px'], - 'nb_observers' => ['label' => 'Observers', 'width' => '130px'], + 'id' => ['label' => 'Id', 'width' => '60px'], + 'event_name' => ['label' => 'Name', 'width' => ''], + 'nb_call' => ['label' => 'Nb Call', 'width' => '100px'], + 'time_total' => ['label' => 'Total Time', 'width' => '120px'], + 'time_mean' => ['label' => 'Mean Time', 'width' => '120px'], + 'nb_observers' => ['label' => 'Observers', 'width' => '130px'], ], 'html_info' -); +) ?> -echo $block->displayTable( +displayTable( 'Unused Events', $unused, [ - 'id' => ['label' => 'Id', 'width' => '60px'], - 'event_name' => ['label' => 'Name', 'width' => ''], - 'nb_call' => ['label' => 'Nb Call', 'width' => '100px'], - 'time_total' => ['label' => 'Total Time', 'width' => '120px'], - 'time_mean' => ['label' => 'Mean Time', 'width' => '120px'], + 'id' => ['label' => 'Id', 'width' => '60px'], + 'event_name' => ['label' => 'Name', 'width' => ''], + 'nb_call' => ['label' => 'Nb Call', 'width' => '100px'], + 'time_total' => ['label' => 'Total Time', 'width' => '120px'], + 'time_mean' => ['label' => 'Mean Time', 'width' => '120px'], ] -); +)?> + [ 'Number' => $block->formatValue($sections['Used Events']['Number'], ['gt' => 100], 'number'), 'Called' => $block->formatValue($sections['Used Events']['Called'], ['gt' => 1000], 'number'), - 'Time' => $block->formatValue($sections['Used Events']['Time'], ['gt' => 1.000], 'time'), + 'Time' => $block->formatValue($sections['Used Events']['Time'], ['gt' => 1.000], 'time'), ], 'Unused Events' => [ 'Number' => $block->formatValue($sections['Unused Events']['Number'], [], 'number'), 'Called' => $block->formatValue($sections['Unused Events']['Called'], [], 'number'), - 'Time' => $block->formatValue($sections['Unused Events']['Time'], ['gt' => 0.5], 'time'), + 'Time' => $block->formatValue($sections['Unused Events']['Time'], ['gt' => 0.5], 'time'), ], ]; $block->addToSummary('Observers', 'Used Events', $sections['Used Events']['Number']); $block->addToSummary('Observers', 'Called Events', $sections['Used Events']['Called']); $block->addToSummary('Observers', 'Time', $sections['Used Events']['Time']); +?> -echo $block->displaySectionsGrouped($sections); +displaySectionsGrouped($sections) ?> diff --git a/view/base/templates/zone/preference.phtml b/view/base/templates/zone/preference.phtml index 9b77e4a..b3b0c19 100644 --- a/view/base/templates/zone/preference.phtml +++ b/view/base/templates/zone/preference.phtml @@ -6,62 +6,64 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Preference $block */ +use Smile\DebugToolbar\Block\Zone\Preference; +/** @var Preference $block */ $list = $block->getPreferenceStats(); $preferences = []; foreach ($list as $original => $final) { $preferences[] = [ 'original' => $block->formatValue($original, [], 'text'), - 'final' => $block->formatValue($final, [], 'text'), + 'final' => $block->formatValue($final, [], 'text'), ]; } unset($list); +?> -echo $block->displayTable( +displayTable( 'Preferences', $preferences, [ - 'original' => ['label' => 'For', 'width' => ''], - 'final' => ['label' => 'Class', 'width' => ''], + 'original' => ['label' => 'For', 'width' => ''], + 'final' => ['label' => 'Class', 'width' => ''], ] -); +) ?> +getPluginStats(); foreach ($plugins as $key => $row) { $classesWithPlugins[$row['main_classname']] = true; - $row['main_classname'] = $block->formatValue($row['main_classname'], [], 'text'); - $row['nb_plugins'] = $block->formatValue($row['nb_plugins'], ['gt' => 15], 'center'); - $row['plugin_name'] = $block->formatValue($row['plugin_name'], [], 'text'); - $row['plugin_classname'] = $block->formatValue($row['plugin_classname'], [], 'text'); + $row['main_classname'] = $block->formatValue($row['main_classname'], [], 'text'); + $row['nb_plugins'] = $block->formatValue($row['nb_plugins'], ['gt' => 15], 'center'); + $row['plugin_name'] = $block->formatValue($row['plugin_name'], [], 'text'); + $row['plugin_classname'] = $block->formatValue($row['plugin_classname'], [], 'text'); $row['plugin_nb_methods'] = $block->formatValue($row['plugin_nb_methods'], ['gt' => 10], 'center'); - $row['html_info'] = $block->buildPluginHtmlInfo($row['plugin_methods']); + $row['html_info'] = $block->buildPluginHtmlInfo($row['plugin_methods']); $plugins[$key] = $row; } +?> -echo $block->displayTable( +displayTable( 'Plugins', $plugins, [ - 'main_classname' => ['label' => 'ClassName', 'width' => ''], - 'nb_plugins' => ['label' => 'Nb Plugins', 'width' => '100px'], - 'plugin_name' => ['label' => 'Plugin Name', 'width' => ''], - 'plugin_classname' => ['label' => 'Plugin ClassName', 'width' => ''], - 'plugin_nb_methods' => ['label' => 'Methods', 'width' => '100px'], + 'main_classname' => ['label' => 'ClassName', 'width' => ''], + 'nb_plugins' => ['label' => 'Nb Plugins', 'width' => '100px'], + 'plugin_name' => ['label' => 'Plugin Name', 'width' => ''], + 'plugin_classname' => ['label' => 'Plugin ClassName', 'width' => ''], + 'plugin_nb_methods' => ['label' => 'Methods', 'width' => '100px'], ], 'html_info' -); +)?> + [ 'Classes with plugins' => $block->formatValue(count($classesWithPlugins), [], 'number'), - 'Nb Plugins' => $block->formatValue(count($plugins), [], 'number'), + 'Nb Plugins' => $block->formatValue(count($plugins), [], 'number'), ], 'Preferences' => [ 'Nb Preferences' => $block->formatValue(count($preferences), [], 'number'), @@ -71,5 +73,6 @@ $sections = [ $block->addToSummary('Preferences', 'Nb Preferences', $sections['Preferences']['Nb Preferences']); $block->addToSummary('Preferences', 'Classes with plugins', $sections['Declared Plugins']['Classes with plugins']); $block->addToSummary('Preferences', 'Nb Plugins', $sections['Declared Plugins']['Nb Plugins']); +?> -echo $block->displaySections($sections); +displaySections($sections) ?> diff --git a/view/base/templates/zone/profiler.phtml b/view/base/templates/zone/profiler.phtml index 03de68f..f2faa6b 100644 --- a/view/base/templates/zone/profiler.phtml +++ b/view/base/templates/zone/profiler.phtml @@ -6,77 +6,79 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Profiler $block */ +use Magento\Framework\Escaper; +use Smile\DebugToolbar\Block\Zone\Profiler; +/** @var Profiler $block */ +/** @var Escaper $escaper */ $timers = $block->getTimers(); ?> - - - - - + + + + + - - - - - - - + + + + + + + - $block->formatValue($timer['sum'], [], 'time'), - 'avg' => $block->formatValue($timer['avg'], ['gt' => 3], 'time'), + 'sum' => $block->formatValue($timer['sum'], [], 'time'), + 'avg' => $block->formatValue($timer['avg'], ['gt' => 3], 'time'), 'count' => $block->formatValue($timer['count'], [], 'number'), - 'mem' => $block->formatValue($timer['mem'], [], 'size_mo'), + 'mem' => $block->formatValue($timer['mem'], [], 'size_mo'), ]; -?> + ?> - - - - + + + - +
TimerTotalAVGNBMem
TimerTotalAVGNBMem
-0): ?> - + - -   - - + 0) : ?> + + + +   + + escapeHtml($timer['label']) ?> -
- +
+
+ escapeHtml($row['sum']['value']) ?>
escapeHtml($row['avg']['value']) ?>escapeHtml($row['count']['value']) ?>escapeHtml($row['mem']['value']) ?>
formatValue($block->getHelperData()->getTimer('profiler_build'), ['gt' => 3], 'time'); +$buildIn = $block->formatValue($block->getHelperData()->getTimer('profiler_build'), ['gt' => 3], 'time'); ?> diff --git a/view/base/templates/zone/request.phtml b/view/base/templates/zone/request.phtml index d0864fd..5a9783d 100644 --- a/view/base/templates/zone/request.phtml +++ b/view/base/templates/zone/request.phtml @@ -6,41 +6,40 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Request $block */ +use Smile\DebugToolbar\Block\Zone\Request; +/** @var Request $block */ $info = $block->getRequest(); $sections = [ 'HTTP' => [ 'Version' => $info->getVersion(), - 'Scheme' => $info->getScheme(), - 'Method' => $info->getMethod(), - 'IP' => $info->getClientIp(), - 'URL' => $info->getUriString(), + 'Scheme' => $info->getScheme(), + 'Method' => $info->getMethod(), + 'IP' => $info->getClientIp(), + 'URL' => $info->getUriString(), ], 'Action' => [ - 'Path Info' => $info->getPathInfo(), + 'Path Info' => $info->getPathInfo(), 'Full Action' => $info->getFullActionName(), - 'Module' => $info->getModuleName(), - 'Group' => $info->getControllerName(), - 'Action' => $info->getActionName(), + 'Module' => $info->getModuleName(), + 'Group' => $info->getControllerName(), + 'Action' => $info->getActionName(), ], 'Route' => [ - 'Module' => $info->getControllerModule(), + 'Module' => $info->getControllerModule(), 'Route Name' => $info->getRouteName(), 'Front Name' => $info->getFrontName(), 'Controller' => $block->getControllerClassName(), ], - 'User Params' => (array) $info->getUserParams(), - 'Get' => (array) $info->getQuery(), - 'Post' => (array) $info->getPost(), - 'Files' => (array) $info->getFiles(), - 'Env' => array_merge((array) $info->getEnv(), (array) $info->getServer()), - 'Headers' => [], - 'Cookies' => $_COOKIE, + 'User Params' => (array)$info->getUserParams(), + 'Get' => (array)$info->getQuery(), + 'Post' => (array)$info->getPost(), + 'Files' => (array)$info->getFiles(), + 'Env' => array_merge((array)$info->getEnv(), (array)$info->getServer()), + 'Headers' => [], + // phpcs:ignore + 'Cookies' => $_COOKIE, ]; foreach ($info->getHeaders() as $header) { @@ -53,5 +52,6 @@ $block->addToSummary('Request', 'Url', $sections['HTTP']['URL']); $block->addToSummary('Request', 'Method', $sections['HTTP']['Method']); $block->addToSummary('Request', 'Path Info', $sections['Action']['Path Info']); $block->addToSummary('Request', 'Full Action', $sections['Action']['Full Action']); +?> -echo $block->displaySections($sections); +displaySections($sections) ?> diff --git a/view/base/templates/zone/response.phtml b/view/base/templates/zone/response.phtml index ae47f20..03cb59e 100644 --- a/view/base/templates/zone/response.phtml +++ b/view/base/templates/zone/response.phtml @@ -6,11 +6,9 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile - -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Response $block */ +use Smile\DebugToolbar\Block\Zone\Response; +/** @var Response $block */ $response = $block->getResponse(); $length = mb_strlen($response->getContent()); @@ -31,23 +29,23 @@ $esi = $block->getEsiUrlList(); $sections = [ 'HTTP' => [ - 'Version' => $block->formatValue($response->getVersion(), [], 'text'), - 'Cookie' => $response->getCookie(), + 'Version' => $block->formatValue($response->getVersion(), [], 'text'), + 'Cookie' => $response->getCookie(), 'Response Code' => $block->formatValue($response->getHttpResponseCode(), ['gt' => 399], 'text'), 'Reason Phrase' => $response->getReasonPhrase(), - 'Status Code' => $block->formatValue($response->getStatusCode(), ['gt' => 399], 'text'), + 'Status Code' => $block->formatValue($response->getStatusCode(), ['gt' => 399], 'text'), ], 'Headers' => $headers, 'Response' => [ 'Date' => date('Y-m-d H:i:s'), - 'Size' => $block->formatValue($length, ['gt' => 512*1024], 'size'), + 'Size' => $block->formatValue($length, ['gt' => 512 * 1024], 'size'), ], 'Full Page Cache' => [ - 'Mode' => $block->formatValue($block->getFullPageCacheMode(), ['neq' => 'varnish'], 'text'), + 'Mode' => $block->formatValue($block->getFullPageCacheMode(), ['neq' => 'varnish'], 'text'), 'Nb Tags' => $block->formatValue(count($tags), ['gt' => 50], 'number'), - 'Nb ESI' => $block->formatValue(count($esi), ['gt' => 4], 'number'), - 'Tags' => $tags, - 'ESI' => $esi, + 'Nb ESI' => $block->formatValue(count($esi), ['gt' => 4], 'number'), + 'Tags' => $tags, + 'ESI' => $esi, ], ]; @@ -56,5 +54,6 @@ $block->addToSummary('Response', 'Size', $sections['Response']['Size']); $block->addToSummary('Response', 'FPC Mode', $sections['Full Page Cache']['Mode']); $block->addToSummary('Response', 'FPC Tags', $sections['Full Page Cache']['Nb Tags']); $block->addToSummary('Response', 'ESI Tags', $sections['Full Page Cache']['Nb ESI']); +?> -echo $block->displaySections($sections); +displaySections($sections) ?> diff --git a/view/base/templates/zone/summary.phtml b/view/base/templates/zone/summary.phtml index 80c6f02..d4ab4d7 100644 --- a/view/base/templates/zone/summary.phtml +++ b/view/base/templates/zone/summary.phtml @@ -6,9 +6,9 @@ * to newer versions in the future. */ -// @codingStandardsIgnoreFile +use Smile\DebugToolbar\Block\Zone\Summary; -/** @var \Magento\Framework\View\TemplateEngine\Php $this */ -/** @var \Smile\DebugToolbar\Block\Zone\Summary $block */ +/** @var Summary $block */ +?> -echo $block->displaySections($block->getSummarySections()); +displaySections($block->getSummarySections()) ?>