improve code style

This commit is contained in:
Daniel Seifert 2024-02-02 11:39:13 +01:00
parent 1aac154bcb
commit fae28866eb
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
9 changed files with 43 additions and 27 deletions

13
.php-cs-fixer.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PHP80Migration' => true,
'@PSR12' => true
])
->setFinder($finder)
;

View File

@ -9,6 +9,7 @@
"firephp/firephp-core": "^0.5.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~3.13.0",
"phpstan/phpstan": "^1.10"
},
"license": "GPL-3.0",
@ -32,6 +33,8 @@
}
],
"scripts": {
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config=vendor/d3/oxid-sql-logger/.php-cs-fixer.php",
"phpstan": "./vendor/bin/phpstan --configuration=vendor/d3/oxid-sql-logger/phpstan.neon analyse"
}
}

View File

@ -6,9 +6,9 @@ use OxidEsales\Eshop\Core\DatabaseProvider;
require __DIR__ . '/../../../../source/bootstrap.php';
D3StartSQLLog( 'Query for 100 items cheaper than 49,99');
D3StartSQLLog('Query for 100 items cheaper than 49,99');
$db = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC);
$db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
$list = $db->getAll('SELECT * '.PHP_EOL.'FROM oxarticles WHERE oxprice < ? LIMIT 100', [49.99]);
D3StopSQLLog();
@ -17,7 +17,7 @@ D3StopSQLLog();
D3StartSQLLog();
$db = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC);
$db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
$list = $db->getAll('SELECT * FROM oxarticles WHERE oxprice < ? LIMIT 100', [49.99]);
D3StopSQLLog();

View File

@ -73,8 +73,8 @@ class d3FirePHP extends FirePHP
*/
public function trace($label): bool
{
return $this->fb($label, $label, FirePHP::TRACE, array(
'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)
));
return $this->fb($label, $label, FirePHP::TRACE, [
'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),
]);
}
}
}

View File

@ -22,7 +22,7 @@ use OxidEsales\Eshop\Core\Registry;
class d3FirePHPHandler extends AbstractProcessingHandler
{
const ADD_TRACE = 'addTrace';
public const ADD_TRACE = 'addTrace';
/**
* @param array $record
@ -37,14 +37,14 @@ class d3FirePHPHandler extends AbstractProcessingHandler
$fp = d3FirePHP::getInstance(true);
if (in_array(self::ADD_TRACE, $options)) {
$fp->group( $record['message'], [ 'Collapsed' => true ] );
$fp->group($record['message'], [ 'Collapsed' => true ]);
}
$fp->log( $record['formatted'], $record['message']);
$fp->log($record['formatted'], $record['message']);
if (in_array(self::ADD_TRACE, $options)) {
$fp->trace( 'trace');
$fp->trace('trace');
$fp->groupEnd();
}
}
}
}

View File

@ -37,7 +37,7 @@ class LoggerFactory
$handlers = (isset($configuredHandlers) && is_iterable($configuredHandlers)) ?
$this->getInstancesFromHandlerList($configuredHandlers) :
[
$this->getStreamHandler()
$this->getStreamHandler(),
];
} else {
$configuredHandlers = Registry::getConfig()->getConfigParam('SqlLoggerGUIHandlers');
@ -46,7 +46,7 @@ class LoggerFactory
$this->getInstancesFromHandlerList($configuredHandlers) :
[
$this->getBrowserConsoleHandler(),
$this->getFirePHPHandler()
$this->getFirePHPHandler(),
];
}
@ -61,7 +61,7 @@ class LoggerFactory
private function getInstancesFromHandlerList(iterable $classNames): array
{
return array_map(
function($className){
function ($className) {
return new $className();
},
(array) $classNames
@ -122,7 +122,7 @@ class LoggerFactory
[
'D3\\OxidSqlLogger',
'Doctrine\\DBAL\\Connection',
'OxidEsales\\EshopCommunity\\Core\\Database\\Adapter\\Doctrine\\Database'
'OxidEsales\\EshopCommunity\\Core\\Database\\Adapter\\Doctrine\\Database',
]
),
new Monolog\Processor\PsrLogMessageProcessor(),

View File

@ -56,7 +56,7 @@ class OxidSQLLogger implements SQLLogger
$this->stopQuery();
}
$this->getPreparedStatementQuery( $sql, $params ?? [], $types ?? []);
$this->getPreparedStatementQuery($sql, $params ?? [], $types ?? []);
$this->SQLQuery = (new SQLQuery())->setSql($sql)
->setParams($params)

View File

@ -29,13 +29,13 @@ class SQLQuery
private ?array $parameters = null;
private ?array $parameterTypes = null;
private string $logStartingFile;
private int $logStartingLine;
private string $logStartingClass;
private string $logStartingFunction;
public function __construct()
@ -98,7 +98,7 @@ class SQLQuery
$this->parameterTypes = $types;
return $this;
}
/**
* @return string
*/
@ -106,7 +106,7 @@ class SQLQuery
{
return $this->logStartingFile;
}
/**
* @param string $file
* @return static

View File

@ -20,7 +20,7 @@ use Psr\Container\NotFoundExceptionInterface;
function D3StartSQLLog(string $message = null): void
{
/** @var OxidEsalesDatabase $database */
$database = oxNew( OxidEsalesDatabase::class);
$database = oxNew(OxidEsalesDatabase::class);
$database->d3EnableLogger($message);
}
@ -31,7 +31,7 @@ function D3StartSQLLog(string $message = null): void
function D3StopSQLLog(): void
{
/** @var OxidEsalesDatabase $database */
$database = oxNew( OxidEsalesDatabase::class);
$database = oxNew(OxidEsalesDatabase::class);
$database->d3DisableLogger();
}
@ -44,9 +44,9 @@ function D3StopSQLLog(): void
function D3AddSQLLogItem(string $message): void
{
/** @var OxidEsalesDatabase $database */
$database = oxNew( OxidEsalesDatabase::class);
$database = oxNew(OxidEsalesDatabase::class);
if ($logger = $database->d3GetLogger()) {
$logger->startQuery( $message );
$logger->startQuery($message);
$logger->stopQuery();
}
}