diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..9f6799a --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,13 @@ +in(__DIR__) +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PHP80Migration' => true, + '@PSR12' => true + ]) + ->setFinder($finder) +; \ No newline at end of file diff --git a/composer.json b/composer.json index 3fa6538..337072f 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/example/simple.php b/example/simple.php index dc80829..b1875d9 100644 --- a/example/simple.php +++ b/example/simple.php @@ -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(); diff --git a/src/Extensions/d3FirePHP.php b/src/Extensions/d3FirePHP.php index 79ea60d..0e47995 100644 --- a/src/Extensions/d3FirePHP.php +++ b/src/Extensions/d3FirePHP.php @@ -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), + ]); } -} \ No newline at end of file +} diff --git a/src/Handler/d3FirePHPHandler.php b/src/Handler/d3FirePHPHandler.php index e866647..62be9b1 100644 --- a/src/Handler/d3FirePHPHandler.php +++ b/src/Handler/d3FirePHPHandler.php @@ -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(); } } -} \ No newline at end of file +} diff --git a/src/LoggerFactory.php b/src/LoggerFactory.php index af192ec..53ad7b5 100644 --- a/src/LoggerFactory.php +++ b/src/LoggerFactory.php @@ -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(), diff --git a/src/OxidSQLLogger.php b/src/OxidSQLLogger.php index 48a3a53..6cdaf35 100644 --- a/src/OxidSQLLogger.php +++ b/src/OxidSQLLogger.php @@ -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) diff --git a/src/SQLQuery.php b/src/SQLQuery.php index 2ae5207..45b4028 100644 --- a/src/SQLQuery.php +++ b/src/SQLQuery.php @@ -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 diff --git a/src/functions.php b/src/functions.php index 4483df4..90615c7 100644 --- a/src/functions.php +++ b/src/functions.php @@ -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(); } }