improve code style

This commit is contained in:
Daniel Seifert 2025-03-25 09:20:39 +01:00
parent 153ce3f5ec
commit b58391c02c
26 changed files with 178 additions and 107 deletions

View File

@ -1,13 +1,35 @@
<?php <?php
$finder = PhpCsFixer\Finder::create() declare(strict_types=1);
->in(__DIR__)
; $finder = PhpCsFixer\Finder::create()->in(__DIR__);
$header = <<<EOF
Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
For the full copyright and license information, please view
the LICENSE file that was distributed with this source code.
https://www.d3data.de
@copyright (C) D3 Data Development (Inh. Thomas Dartsch)
@author D3 Data Development - Daniel Seifert <info@shopmodule.com>
@link https://www.oxidmodule.com
EOF;
$config = new PhpCsFixer\Config(); $config = new PhpCsFixer\Config();
return $config->setRules([ return $config->setRules(
'@PHP73Migration' => true, [
'@PSR12' => true '@PHP80Migration' => true,
]) '@PSR12' => true,
->setFinder($finder) 'header_comment' => [
; 'comment_type' => 'PHPDoc',
'header' => $header,
'location' => 'after_open',
'separate' => 'both',
],
'php_unit_test_class_requires_covers' => true,
'doctrine_annotation_indentation' => true,
]
)
->setFinder($finder);

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *
@ -89,11 +91,11 @@ class OxidConfigCollector extends DataCollector implements Renderable
$search = array_merge($generic, $specific); $search = array_merge($generic, $specific);
foreach ($this->configVars as $group => $values) { foreach ($this->configVars as $group => $values) {
array_walk( $this->configVars[$group], function( $item, $key ) use ( $group, $search ) { array_walk($this->configVars[$group], function ($item, $key) use ($group, $search) {
if ( in_array( $key, $search ) ) { if (in_array($key, $search)) {
$this->configVars[$group][ $key ] = self::HIDDEN_TEXT; $this->configVars[$group][ $key ] = self::HIDDEN_TEXT;
} }
} ); });
} }
} }

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,12 +1,13 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *
* @copyright (c) 2016 Dmitry Kosenkov
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch) * @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com> * @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *
@ -19,8 +21,7 @@ use DebugBar\DataCollector\TimeDataCollector;
class TimeDataCollectorHandler class TimeDataCollectorHandler
{ {
/** @var TimeDataCollector */ private static TimeDataCollector|null $instance = null;
private static $instance = null;
/** /**
* @return TimeDataCollector * @return TimeDataCollector

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *
@ -52,20 +54,14 @@ class DebugBarErrorHandler
[ $file, $line ] = $smartyTemplate; [ $file, $line ] = $smartyTemplate;
} }
switch ($severity) { throw match ($severity) {
case E_CORE_ERROR: E_CORE_ERROR => new CoreErrorException($message, 0, $severity, $file, $line),
throw new CoreErrorException($message, 0, $severity, $file, $line); E_COMPILE_ERROR => new CompileErrorException($message, 0, $severity, $file, $line),
case E_COMPILE_ERROR: E_USER_ERROR => new UserErrorException($message, 0, $severity, $file, $line),
throw new CompileErrorException($message, 0, $severity, $file, $line); E_PARSE => new ParseException($message, 0, $severity, $file, $line),
case E_USER_ERROR: E_ERROR => new ErrorException($message, 0, $severity, $file, $line),
throw new UserErrorException($message, 0, $severity, $file, $line); default => $this->handleUnregisteredErrorTypes($message, $severity, $file, $line),
case E_PARSE: };
throw new ParseException($message, 0, $severity, $file, $line);
case E_ERROR:
throw new ErrorException($message, 0, $severity, $file, $line);
default:
$this->handleUnregisteredErrorTypes($message, $severity, $file, $line);
}
} }
/** /**
@ -75,7 +71,7 @@ class DebugBarErrorHandler
protected function getSmartyTemplateLocationFromError(string $messsage): ?array protected function getSmartyTemplateLocationFromError(string $messsage): ?array
{ {
if (stristr($messsage, 'Smarty error: [in ')) { if (stristr($messsage, 'Smarty error: [in ')) {
$start = strpos($messsage, '[')+1; $start = strpos($messsage, '[') + 1;
$end = strpos($messsage, ']'); $end = strpos($messsage, ']');
$parts = explode(' ', substr($messsage, $start, $end - $start)); $parts = explode(' ', substr($messsage, $start, $end - $start));
return [Registry::getConfig()->getTemplateDir(isAdmin()).$parts[1], (int) $parts[3]]; return [Registry::getConfig()->getTemplateDir(isAdmin()).$parts[1], (int) $parts[3]];

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *
@ -20,11 +22,10 @@ use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Application\Models\Exceptions\UnavailableException; use D3\DebugBar\Application\Models\Exceptions\UnavailableException;
use DebugBar\DataCollector\ExceptionsCollector; use DebugBar\DataCollector\ExceptionsCollector;
use DebugBar\DebugBarException; use DebugBar\DebugBarException;
use OxidEsales\Eshop\Core\ConfigFile;
use OxidEsales\Eshop\Core\Exception\ExceptionHandler;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Framework\Logger\LoggerServiceFactory; use OxidEsales\EshopCommunity\Internal\Framework\Logger\LoggerServiceFactory;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\Context; use OxidEsales\EshopCommunity\Internal\Transition\Utility\Context;
use ReflectionException;
use Throwable; use Throwable;
class DebugBarExceptionHandler class DebugBarExceptionHandler
@ -33,27 +34,25 @@ class DebugBarExceptionHandler
* Handler for uncaught exceptions. * Handler for uncaught exceptions.
* *
* @param Throwable $exception exception object * @param Throwable $exception exception object
*
* @return void * @return void
* @throws ReflectionException
*/ */
public function handleUncaughtException(Throwable $exception): void public function handleUncaughtException(Throwable $exception): void
{ {
try { try {
/** @var int $debugMode */ Registry::getLogger()->error(
$debugMode = Registry::get(ConfigFile::class)->getVar('iDebug'); $exception->getMessage(),
$defaultExceptionHandler = new ExceptionHandler($debugMode); [$exception]
$defaultExceptionHandler->writeExceptionToLog($exception); );
} catch (Throwable $loggerException) { } catch (Throwable) {
/** /**
* It's not possible to get the logger from the DI container. * It's not possible to get the logger from the DI container.
* Try again to log original exception (without DI container) in order to show the root cause of a problem. * Try again to log original exception (without DI container) in order to show the root cause of a problem.
*/ */
try { $loggerServiceFactory = new LoggerServiceFactory(new Context());
$loggerServiceFactory = new LoggerServiceFactory(new Context()); $logger = $loggerServiceFactory->getLogger();
$logger = $loggerServiceFactory->getLogger(); $logger->error($exception);
$logger->error($exception->getTraceAsString());
} catch (Throwable $throwableWithoutPossibilityToWriteToLogFile) {
// It's not possible to log because e.g. the log file is not writable.
}
} }
if (AvailabilityCheck::isAvailable() && AvailabilityCheck::ifDebugBarNotSet()) { if (AvailabilityCheck::isAvailable() && AvailabilityCheck::ifDebugBarNotSet()) {
@ -66,23 +65,23 @@ class DebugBarExceptionHandler
$excCollector->addThrowable($exception); $excCollector->addThrowable($exception);
echo <<<HTML echo <<<HTML
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title></title> <title></title>
HTML; HTML;
echo $debugBarComponent->getRenderer()->renderHead(); echo $debugBarComponent->getRenderer()->renderHead();
$debugBarComponent->addTimelineMeasures(); $debugBarComponent->addTimelineMeasures();
echo <<<HTML echo <<<HTML
</head> </head>
<body> <body>
HTML; HTML;
AvailabilityCheck::markDebugBarAsSet(); AvailabilityCheck::markDebugBarAsSet();
echo $debugBarComponent->getRenderer()->render(); echo $debugBarComponent->getRenderer()->render();
echo <<<HTML echo <<<HTML
</body> </body>
</html> </html>
HTML; HTML;
} catch (DebugBarException|UnavailableException $e) { } catch (DebugBarException|UnavailableException $e) {
Registry::getLogger()->error($e->getMessage()); Registry::getLogger()->error($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e); Registry::getUtilsView()->addErrorToDisplay($e);

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *
@ -18,9 +20,11 @@ namespace D3\DebugBar\Modules\Core;
use D3\DebugBar\Application\Component\DebugBarComponent; use D3\DebugBar\Application\Component\DebugBarComponent;
use D3\DebugBar\Application\Models\AvailabilityCheck; use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Application\Models\DebugBarHandler; use D3\DebugBar\Application\Models\DebugBarHandler;
use D3\DebugBar\Application\Models\Exceptions\UnavailableException;
use D3\DebugBar\Core\DebugBarExceptionHandler; use D3\DebugBar\Core\DebugBarExceptionHandler;
use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use ReflectionException;
use Throwable; use Throwable;
class ShopControl_DebugBar extends ShopControl_DebugBar_parent class ShopControl_DebugBar extends ShopControl_DebugBar_parent
@ -39,8 +43,11 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
/** /**
* @param string|null $controllerKey * @param string|null $controllerKey
* @param string|null $function * @param string|null $function
* @param array $parameters * @param array|null $parameters
* @param array $viewsChain * @param array|null $viewsChain
*
* @throws UnavailableException
* @throws ReflectionException
*/ */
public function start($controllerKey = null, $function = null, $parameters = null, $viewsChain = null) public function start($controllerKey = null, $function = null, $parameters = null, $viewsChain = null)
{ {
@ -63,7 +70,9 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
/** /**
* @param Throwable $exception * @param Throwable $exception
*
* @return void * @return void
* @throws ReflectionException
*/ */
protected function debugBarHandleException(Throwable $exception): void protected function debugBarHandleException(Throwable $exception): void
{ {
@ -73,6 +82,8 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
/** /**
* @param StandardException $exception * @param StandardException $exception
*
* @throws ReflectionException
*/ */
protected function _handleSystemException($exception) protected function _handleSystemException($exception)
{ {
@ -81,6 +92,8 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
/** /**
* @param StandardException $exception * @param StandardException $exception
*
* @throws ReflectionException
*/ */
protected function _handleCookieException($exception) protected function _handleCookieException($exception)
{ {
@ -89,6 +102,8 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
/** /**
* @param StandardException $exception * @param StandardException $exception
*
* @throws ReflectionException
*/ */
protected function _handleBaseException($exception) protected function _handleBaseException($exception)
{ {

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *
@ -81,7 +83,7 @@ function stopProfile(string $sProfileName): void
* @throws DebugBarException * @throws DebugBarException
* @return void * @return void
*/ */
function debugVar($mVar, bool $blToFile = false): void function debugVar(mixed $mVar, bool $blToFile = false): void
{ {
if ($blToFile) { if ($blToFile) {
$out = var_export($mVar, true); $out = var_export($mVar, true);
@ -106,10 +108,9 @@ function debugVar($mVar, bool $blToFile = false): void
/** @var MessagesCollector $messages */ /** @var MessagesCollector $messages */
$messages = $debugBarComponent->getDebugBar()->getCollector('messages'); $messages = $debugBarComponent->getDebugBar()->getCollector('messages');
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
//$location = $trace[1]['class'] . '::' . $trace[1]['function']. '(' . $trace[0]['line'] . ')';
$location = $trace[1]['class'] . '::' . $trace[1]['function']; $location = $trace[1]['class'] . '::' . $trace[1]['function'];
$messages->addMessage($mVar, $location); $messages->addMessage($mVar, $location);
} catch (UnavailableException $e) { } catch (UnavailableException) {
dumpVar($mVar, $blToFile); dumpVar($mVar, $blToFile);
} }
} }

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *

View File

@ -2,4 +2,3 @@
- clear tpl cache button - clear tpl cache button
- phpinfo() overview - phpinfo() overview
- automatic switch between Smarty and Twig

View File

@ -40,5 +40,8 @@
"psr-4": { "psr-4": {
"D3\\DebugBar\\": "" "D3\\DebugBar\\": ""
} }
},
"scripts": {
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config=vendor/d3/oxid-debugbar/.php-cs-fixer.php"
} }
} }

View File

@ -1,8 +1,10 @@
<?php <?php
/** /**
* For the full copyright and license information, please view the LICENSE * Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
* file that was distributed with this source code. *
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
* *
* https://www.d3data.de * https://www.d3data.de
* *