diff --git a/Application/Models/Collectors/OxidConfigCollector.php b/Application/Models/Collectors/OxidConfigCollector.php index 320deff..7dd36aa 100644 --- a/Application/Models/Collectors/OxidConfigCollector.php +++ b/Application/Models/Collectors/OxidConfigCollector.php @@ -36,6 +36,11 @@ class OxidConfigCollector extends DataCollector implements Renderable */ protected $useHtmlVarDumper = false; + /** + * @param Config $config + * + * @throws ReflectionException + */ public function __construct(Config $config) { $config->init(); @@ -111,9 +116,9 @@ class OxidConfigCollector extends DataCollector implements Renderable * Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable * rendering. * - * @return mixed + * @return bool */ - public function isHtmlVarDumperUsed() + public function isHtmlVarDumperUsed(): bool { return $this->useHtmlVarDumper; } diff --git a/Application/Models/Collectors/OxidShopCollector.php b/Application/Models/Collectors/OxidShopCollector.php index d7f7654..5c66a7d 100644 --- a/Application/Models/Collectors/OxidShopCollector.php +++ b/Application/Models/Collectors/OxidShopCollector.php @@ -18,13 +18,17 @@ namespace D3\DebugBar\Application\Models\Collectors; use Composer\InstalledVersions; use DebugBar\DataCollector\DataCollector; use DebugBar\DataCollector\Renderable; +use Exception; use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Module\Module; use OxidEsales\Eshop\Core\ShopVersion; use OxidEsales\Eshop\Core\Theme; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridge; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface; use OxidEsales\Facts\Facts; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class OxidShopCollector extends DataCollector implements Renderable { @@ -39,11 +43,18 @@ class OxidShopCollector extends DataCollector implements Renderable */ protected $useHtmlVarDumper = true; + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws Exception + */ public function __construct() { $facts = new Facts(); $theme = new Theme(); - $parentThemeId = $theme->getParent() ? $theme->getParent()->getId() : '--'; + /** @var Theme|null $parent */ + $parent = $theme->getParent(); + $parentThemeId = $parent ? $parent->getId() : '--'; $moduleList = $this->getInstalledModules(); array_walk( @@ -60,7 +71,7 @@ class OxidShopCollector extends DataCollector implements Renderable 'CE Version:' => InstalledVersions::getVersion('oxid-esales/oxideshop-ce'), 'Theme:' => $theme->getActiveThemeId(), 'Parent Theme:' => $parentThemeId, - 'Modules:' => implode(chr(10), $moduleList) + 'Modules:' => implode(chr(10), $moduleList), ]; } @@ -96,9 +107,9 @@ class OxidShopCollector extends DataCollector implements Renderable * Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable * rendering. * - * @return mixed + * @return bool */ - public function isHtmlVarDumperUsed() + public function isHtmlVarDumperUsed(): bool { return $this->useHtmlVarDumper; } @@ -121,10 +132,17 @@ class OxidShopCollector extends DataCollector implements Renderable ]; } + /** + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ protected function getInstalledModules(): array { $container = ContainerFactory::getInstance()->getContainer(); - $shopConfiguration = $container->get(ShopConfigurationDaoBridgeInterface::class)->get(); + /** @var ShopConfigurationDaoBridge $shopConfigurationDaoBridge */ + $shopConfigurationDaoBridge = $container->get(ShopConfigurationDaoBridgeInterface::class); + $shopConfiguration = $shopConfigurationDaoBridge->get(); $modules = []; diff --git a/Application/Models/Collectors/OxidVersionCollector.php b/Application/Models/Collectors/OxidVersionCollector.php index c14f4d1..4175720 100644 --- a/Application/Models/Collectors/OxidVersionCollector.php +++ b/Application/Models/Collectors/OxidVersionCollector.php @@ -1,4 +1,5 @@ getParent() ? $theme->getParent()->getId() : '--'; - return array( - 'version' => $facts->getEdition().' '.ShopVersion::getVersion() - ); + return [ + 'version' => $facts->getEdition().' '.ShopVersion::getVersion(), + ]; } /** - * {@inheritDoc} + * @return string[][] */ - public function getWidgets() + public function getWidgets(): array { - $collect = $this->collect(); - return [ "oxidversion" => [ "icon" => "shopping-cart", "tooltip" => 'OXID Version', "map" => $this->getName().".version", - "default" => "" + "default" => "", ], ]; } diff --git a/Application/Models/Collectors/SmartyCollector.php b/Application/Models/Collectors/SmartyCollector.php index 5af0e78..b223159 100644 --- a/Application/Models/Collectors/SmartyCollector.php +++ b/Application/Models/Collectors/SmartyCollector.php @@ -38,7 +38,7 @@ class SmartyCollector extends DataCollector implements Renderable * @param bool $value * @return $this */ - public function useHtmlVarDumper($value = true) + public function useHtmlVarDumper(bool $value = true): SmartyCollector { $this->useHtmlVarDumper = $value; @@ -49,9 +49,9 @@ class SmartyCollector extends DataCollector implements Renderable * Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable * rendering. * - * @return mixed + * @return bool */ - public function isHtmlVarDumperUsed() + public function isHtmlVarDumperUsed(): bool { return $this->useHtmlVarDumper; } @@ -69,7 +69,7 @@ class SmartyCollector extends DataCollector implements Renderable */ public function collect(): array { - $data = []; + $data = ['current view template' => Registry::getConfig()->getTopActiveView()->getTemplateName()]; $vars = $this->smarty->get_template_vars(); diff --git a/Application/Models/DebugBarHandler.php b/Application/Models/DebugBarHandler.php index 3a1ee7c..0040e3a 100644 --- a/Application/Models/DebugBarHandler.php +++ b/Application/Models/DebugBarHandler.php @@ -28,13 +28,12 @@ class DebugBarHandler public function setErrorHandler(): void { if ($this->d3CanActivateDebugBar()) { - set_error_handler( - [ - new DebugBarErrorHandler(), - 'callback' - ], - $this->getHandledErrorTypes() - ); + /** @var callable $callable */ + $callable = [ + new DebugBarErrorHandler(), + 'callback', + ]; + set_error_handler($callable, $this->getHandledErrorTypes()); } } @@ -52,10 +51,10 @@ class DebugBarHandler public function setExceptionHandler(): void { if ($this->d3CanActivateDebugBar()) { - set_exception_handler( [ + set_exception_handler([ new DebugBarExceptionHandler(), - 'handleUncaughtException' - ] ); + 'handleUncaughtException', + ]); } } @@ -65,17 +64,17 @@ class DebugBarHandler public function addDebugBarComponent(): void { if ($this->d3CanActivateDebugBar()) { - $userComponentNames = Registry::getConfig()->getConfigParam( 'aUserComponentNames' ); + $userComponentNames = Registry::getConfig()->getConfigParam('aUserComponentNames'); $d3CmpName = DebugBarComponent::class; $blDontUseCache = 1; - if ( ! is_array( $userComponentNames ) ) { + if (! is_array($userComponentNames)) { $userComponentNames = []; } - if ( ! in_array( $d3CmpName, array_keys( $userComponentNames ) ) ) { + if (! in_array($d3CmpName, array_keys($userComponentNames))) { $userComponentNames[ $d3CmpName ] = $blDontUseCache; - Registry::getConfig()->setConfigParam( 'aUserComponentNames', $userComponentNames ); + Registry::getConfig()->setConfigParam('aUserComponentNames', $userComponentNames); } } } @@ -87,4 +86,4 @@ class DebugBarHandler { return false === isAdmin(); } -} \ No newline at end of file +} diff --git a/Application/Models/Exceptions/CompileErrorException.php b/Application/Models/Exceptions/CompileErrorException.php index 94e0d28..b8bd340 100644 --- a/Application/Models/Exceptions/CompileErrorException.php +++ b/Application/Models/Exceptions/CompileErrorException.php @@ -19,4 +19,4 @@ use ErrorException; class CompileErrorException extends ErrorException { -} \ No newline at end of file +} diff --git a/Application/Models/Exceptions/CoreErrorException.php b/Application/Models/Exceptions/CoreErrorException.php index ef94370..d087f59 100644 --- a/Application/Models/Exceptions/CoreErrorException.php +++ b/Application/Models/Exceptions/CoreErrorException.php @@ -19,4 +19,4 @@ use ErrorException; class CoreErrorException extends ErrorException { -} \ No newline at end of file +} diff --git a/Application/Models/Exceptions/ParseException.php b/Application/Models/Exceptions/ParseException.php index 28a6ca8..ffe4577 100644 --- a/Application/Models/Exceptions/ParseException.php +++ b/Application/Models/Exceptions/ParseException.php @@ -19,4 +19,4 @@ use ErrorException; class ParseException extends ErrorException { -} \ No newline at end of file +} diff --git a/Application/Models/Exceptions/UserErrorException.php b/Application/Models/Exceptions/UserErrorException.php index d4e62a8..b34d933 100644 --- a/Application/Models/Exceptions/UserErrorException.php +++ b/Application/Models/Exceptions/UserErrorException.php @@ -19,4 +19,4 @@ use ErrorException; class UserErrorException extends ErrorException { -} \ No newline at end of file +} diff --git a/Core/DebugBarErrorHandler.php b/Core/DebugBarErrorHandler.php index dd93849..1427f61 100644 --- a/Core/DebugBarErrorHandler.php +++ b/Core/DebugBarErrorHandler.php @@ -25,10 +25,10 @@ use OxidEsales\Eshop\Core\Registry; class DebugBarErrorHandler { /** - * @param $severity - * @param $message - * @param $file - * @param $line + * @param int $severity + * @param string $message + * @param string $file + * @param int $line * * @return void|false * @throws CompileErrorException @@ -37,22 +37,22 @@ class DebugBarErrorHandler * @throws ParseException * @throws UserErrorException */ - public function callback( $severity, $message, $file, $line ) + public function callback(int $severity, string $message, string $file, int $line) { global $debugBarErrorOccured; $debugBarErrorOccured = 1; - if ( 0 === error_reporting() || !( error_reporting() & $severity ) ) { + if (0 === error_reporting() || !(error_reporting() & $severity)) { // This error code is not included in error_reporting. return false; } - $smartyTemplate = $this->getSmartyTemplateLocationFromError( $message ); - if ( is_array( $smartyTemplate ) ) { + $smartyTemplate = $this->getSmartyTemplateLocationFromError($message); + if (is_array($smartyTemplate)) { [ $file, $line ] = $smartyTemplate; } - switch($severity) { + switch ($severity) { case E_CORE_ERROR: throw new CoreErrorException($message, 0, $severity, $file, $line); case E_COMPILE_ERROR: @@ -69,10 +69,10 @@ class DebugBarErrorHandler } /** - * @param $messsage + * @param string $messsage * @return array|null */ - protected function getSmartyTemplateLocationFromError($messsage): ?array + protected function getSmartyTemplateLocationFromError(string $messsage): ?array { if (stristr($messsage, 'Smarty error: [in ')) { $start = strpos($messsage, '[')+1; @@ -85,15 +85,20 @@ class DebugBarErrorHandler } /** - * @param string $message - * @param int|null $severity - * @param string|null $file - * @param int|null $line + * @param string $message + * @param int $severity + * @param string $file + * @param int $line + * @return void * * @throws ErrorException */ - protected function handleUnregisteredErrorTypes(string $message = '', int $severity = null, string $file = null, int $line = null) - { + protected function handleUnregisteredErrorTypes( + string $message = '', + int $severity = 1, + string $file = __FILE__, + int $line = __LINE__ + ): void { throw new ErrorException($message, 0, $severity, $file, $line); } -} \ No newline at end of file +} diff --git a/Core/DebugBarExceptionHandler.php b/Core/DebugBarExceptionHandler.php index dbfda52..2a962f1 100644 --- a/Core/DebugBarExceptionHandler.php +++ b/Core/DebugBarExceptionHandler.php @@ -31,11 +31,13 @@ class DebugBarExceptionHandler * Handler for uncaught exceptions. * * @param Throwable $exception exception object + * @return void */ - public function handleUncaughtException(Throwable $exception) + public function handleUncaughtException(Throwable $exception): void { try { - $debugMode = (bool) Registry::get( ConfigFile::class)->getVar( 'iDebug'); + /** @var int $debugMode */ + $debugMode = Registry::get(ConfigFile::class)->getVar('iDebug'); $defaultExceptionHandler = new ExceptionHandler($debugMode); $defaultExceptionHandler->writeExceptionToLog($exception); } catch (Throwable $loggerException) { @@ -57,14 +59,14 @@ class DebugBarExceptionHandler if ($debugBarSet !== 1 && false === isAdmin()) { try { /** @var DebugBarComponent $debugBarComponent */ - $debugBarComponent = oxNew( DebugBarComponent::class ); + $debugBarComponent = oxNew(DebugBarComponent::class); /** @var ExceptionsCollector $excCollector */ - $excCollector = $debugBarComponent->getDebugBar()->getCollector( 'exceptions' ); - $excCollector->addThrowable( $exception ); + $excCollector = $debugBarComponent->getDebugBar()->getCollector('exceptions'); + $excCollector->addThrowable($exception); echo << +