improve code

This commit is contained in:
Daniel Seifert 2022-08-03 09:12:45 +02:00
parent a3b0050922
commit f097a58691
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
4 changed files with 41 additions and 14 deletions

View File

@ -22,6 +22,7 @@ use DebugBar\Bridge\MonologCollector;
use DebugBar\DebugBarException; use DebugBar\DebugBarException;
use DebugBar\JavascriptRenderer; use DebugBar\JavascriptRenderer;
use DebugBar\StandardDebugBar; use DebugBar\StandardDebugBar;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Logging\DebugStack;
use Monolog\Logger; use Monolog\Logger;
use OxidEsales\Eshop\Core\Controller\BaseController; use OxidEsales\Eshop\Core\Controller\BaseController;
@ -85,6 +86,7 @@ class DebugBarComponent extends BaseController
{ {
$db = DatabaseProvider::getDb(); $db = DatabaseProvider::getDb();
$debugStack = new DebugStack(); $debugStack = new DebugStack();
/** @var Connection $connection */
$connection = $this->getNonPublicProperty($db, 'connection'); $connection = $this->getNonPublicProperty($db, 'connection');
$connection->getConfiguration()->setSQLLogger($debugStack); $connection->getConfiguration()->setSQLLogger($debugStack);
return new DoctrineCollector($debugStack); return new DoctrineCollector($debugStack);
@ -100,12 +102,13 @@ class DebugBarComponent extends BaseController
} }
/** /**
* @param $object * @param object $object
* @param $propName * @param string $propName
*
* @return mixed * @return mixed
* @throws ReflectionException * @throws ReflectionException
*/ */
protected function getNonPublicProperty($object, $propName) protected function getNonPublicProperty(object $object, string $propName)
{ {
$reflection = new ReflectionClass($object); $reflection = new ReflectionClass($object);
$property = $reflection->getProperty($propName); $property = $reflection->getProperty($propName);

View File

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace D3\DebugBar\Modules\Core; namespace D3\DebugBar\Modules\Core;
use D3\DebugBar\Application\Component\DebugBarComponent; use D3\DebugBar\Application\Component\DebugBarComponent;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
class ShopControl_DebugBar extends ShopControl_DebugBar_parent class ShopControl_DebugBar extends ShopControl_DebugBar_parent
@ -49,11 +50,11 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
public function __destruct() public function __destruct()
{ {
if (!isAdmin()) { if (!isAdmin()) {
/** @var DebugBarComponent $debugBarComponent */ /** @var FrontendController $activeView */
$activeView = Registry::getConfig()->getTopActiveView(); $activeView = Registry::getConfig()->getTopActiveView();
if ($activeView && /** @var DebugBarComponent|null $debugBarComponent */
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class) $debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
) { if ($debugBarComponent) {
echo $debugBarComponent->getRenderer()->renderHead(); echo $debugBarComponent->getRenderer()->renderHead();
$debugBarComponent->addTimelineMessures(); $debugBarComponent->addTimelineMessures();
echo $debugBarComponent->getRenderer()->render(); echo $debugBarComponent->getRenderer()->render();

View File

@ -16,9 +16,14 @@ declare(strict_types=1);
use D3\DebugBar\Application\Component\DebugBarComponent; use D3\DebugBar\Application\Component\DebugBarComponent;
use D3\DebugBar\Application\Models\TimeDataCollectorHandler; use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
use DebugBar\DataCollector\MessagesCollector; use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DebugBarException;
use OxidEsales\Eshop\Core\Registry; 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 = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$trace[0] = $sProfileName; $trace[0] = $sProfileName;
@ -39,7 +44,13 @@ function startProfile($sProfileName)
$aStartTimes[$sProfileName] = microtime(true); $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 = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$trace[0] = $sProfileName; $trace[0] = $sProfileName;
@ -61,13 +72,22 @@ function stopProfile($sProfileName)
$aStartTimes[$sProfileName] = microtime(true); $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) { if ($blToFile) {
$out = var_export($mVar, true); $out = var_export($mVar, true);
$f = fopen(Registry::getConfig()->getConfigParam('sCompileDir') . "/vardump.txt", "a"); $f = fopen(Registry::getConfig()->getConfigParam('sCompileDir') . "/vardump.txt", "a");
fwrite($f, $out); if (is_resource($f)) {
fclose($f); fwrite( $f, $out );
fclose( $f );
}
} else { } else {
if (!isAdmin()) { if (!isAdmin()) {
$activeView = Registry::getConfig()->getTopActiveView(); $activeView = Registry::getConfig()->getTopActiveView();

View File

@ -1,9 +1,12 @@
parameters: parameters:
paths:
- .
scanFiles: scanFiles:
- IntelliSenseHelper.php - IntelliSenseHelper.php
- ../../oxid-esales/oxideshop-ce/source/oxfunctions.php - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php
level: 9 level: 9
phpVersion: 70100 phpVersion: 70300
checkMissingIterableValueType: false checkMissingIterableValueType: false
ignoreErrors: ignoreErrors:
- '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' - '#setConfigParam\(\) expects string, array given.#'
- '#Offset .* does not exist on array{function: .*}.#'