diff --git a/Application/Component/DebugBarComponent.php b/Application/Component/DebugBarComponent.php index eafc4cb..228b520 100644 --- a/Application/Component/DebugBarComponent.php +++ b/Application/Component/DebugBarComponent.php @@ -22,6 +22,7 @@ use DebugBar\Bridge\MonologCollector; use DebugBar\DebugBarException; use DebugBar\JavascriptRenderer; use DebugBar\StandardDebugBar; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Logging\DebugStack; use Monolog\Logger; use OxidEsales\Eshop\Core\Controller\BaseController; @@ -85,6 +86,7 @@ class DebugBarComponent extends BaseController { $db = DatabaseProvider::getDb(); $debugStack = new DebugStack(); + /** @var Connection $connection */ $connection = $this->getNonPublicProperty($db, 'connection'); $connection->getConfiguration()->setSQLLogger($debugStack); return new DoctrineCollector($debugStack); @@ -100,12 +102,13 @@ class DebugBarComponent extends BaseController } /** - * @param $object - * @param $propName + * @param object $object + * @param string $propName + * * @return mixed * @throws ReflectionException */ - protected function getNonPublicProperty($object, $propName) + protected function getNonPublicProperty(object $object, string $propName) { $reflection = new ReflectionClass($object); $property = $reflection->getProperty($propName); diff --git a/Modules/Core/ShopControl_DebugBar.php b/Modules/Core/ShopControl_DebugBar.php index f657fbd..2444195 100644 --- a/Modules/Core/ShopControl_DebugBar.php +++ b/Modules/Core/ShopControl_DebugBar.php @@ -16,6 +16,7 @@ declare(strict_types=1); namespace D3\DebugBar\Modules\Core; use D3\DebugBar\Application\Component\DebugBarComponent; +use OxidEsales\Eshop\Application\Controller\FrontendController; use OxidEsales\Eshop\Core\Registry; class ShopControl_DebugBar extends ShopControl_DebugBar_parent @@ -49,11 +50,11 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent public function __destruct() { if (!isAdmin()) { - /** @var DebugBarComponent $debugBarComponent */ + /** @var FrontendController $activeView */ $activeView = Registry::getConfig()->getTopActiveView(); - if ($activeView && - $debugBarComponent = $activeView->getComponent(DebugBarComponent::class) - ) { + /** @var DebugBarComponent|null $debugBarComponent */ + $debugBarComponent = $activeView->getComponent(DebugBarComponent::class); + if ($debugBarComponent) { echo $debugBarComponent->getRenderer()->renderHead(); $debugBarComponent->addTimelineMessures(); echo $debugBarComponent->getRenderer()->render(); diff --git a/Modules/functions.php b/Modules/functions.php index f85513a..70fa3f5 100644 --- a/Modules/functions.php +++ b/Modules/functions.php @@ -16,9 +16,14 @@ declare(strict_types=1); use D3\DebugBar\Application\Component\DebugBarComponent; use D3\DebugBar\Application\Models\TimeDataCollectorHandler; use DebugBar\DataCollector\MessagesCollector; +use DebugBar\DebugBarException; use OxidEsales\Eshop\Core\Registry; -function startProfile($sProfileName) +/** + * @param $sProfileName + * @return void + */ +function startProfile(string $sProfileName): void { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $trace[0] = $sProfileName; @@ -39,7 +44,13 @@ function startProfile($sProfileName) $aStartTimes[$sProfileName] = microtime(true); } -function stopProfile($sProfileName) +/** + * @param string $sProfileName + * + * @return void + * @throws DebugBarException + */ +function stopProfile(string $sProfileName): void { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $trace[0] = $sProfileName; @@ -61,13 +72,22 @@ function stopProfile($sProfileName) $aStartTimes[$sProfileName] = microtime(true); } -function debugVar($mVar, $blToFile = false) +/** + * @param mixed $mVar + * @param bool $blToFile + * + * @throws DebugBarException + * @return void + */ +function debugVar($mVar, bool $blToFile = false): void { if ($blToFile) { $out = var_export($mVar, true); $f = fopen(Registry::getConfig()->getConfigParam('sCompileDir') . "/vardump.txt", "a"); - fwrite($f, $out); - fclose($f); + if (is_resource($f)) { + fwrite( $f, $out ); + fclose( $f ); + } } else { if (!isAdmin()) { $activeView = Registry::getConfig()->getTopActiveView(); diff --git a/phpstan.neon b/phpstan.neon index 35db9d8..3699261 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,12 @@ parameters: + paths: + - . scanFiles: - IntelliSenseHelper.php - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php level: 9 - phpVersion: 70100 + phpVersion: 70300 checkMissingIterableValueType: false ignoreErrors: - - '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' + - '#setConfigParam\(\) expects string, array given.#' + - '#Offset .* does not exist on array{function: .*}.#'