improve code quality
This commit is contained in:
parent
e47817b95d
commit
1aac154bcb
@ -8,6 +8,9 @@
|
||||
"nilportugues/sql-query-formatter": "^1.2.2",
|
||||
"firephp/firephp-core": "^0.5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.10"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -27,5 +30,8 @@
|
||||
"email": "info@shopmodule.com",
|
||||
"homepage": "https://www.d3data.de"
|
||||
}
|
||||
]
|
||||
],
|
||||
"scripts": {
|
||||
"phpstan": "./vendor/bin/phpstan --configuration=vendor/d3/oxid-sql-logger/phpstan.neon analyse"
|
||||
}
|
||||
}
|
||||
|
14
phpstan.neon
Normal file
14
phpstan.neon
Normal file
@ -0,0 +1,14 @@
|
||||
parameters:
|
||||
scanFiles:
|
||||
- ../../oxid-esales/oxideshop-ce/source/bootstrap.php
|
||||
- ../../oxid-esales/oxideshop-ce/source/oxfunctions.php
|
||||
- ../../oxid-esales/oxideshop-ce/source/overridablefunctions.php
|
||||
paths:
|
||||
- ./src
|
||||
- ./example
|
||||
level: 9
|
||||
phpVersion: 80300
|
||||
checkMissingIterableValueType: false
|
||||
treatPhpDocTypesAsCertain: false
|
||||
featureToggles:
|
||||
disableRuntimeReflectionProvider: true
|
@ -68,7 +68,7 @@ class d3FirePHP extends FirePHP
|
||||
*
|
||||
* @see FirePHP::TRACE
|
||||
* @param string $label
|
||||
* @return true
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function trace($label): bool
|
||||
|
@ -10,16 +10,18 @@ declare(strict_types=1);
|
||||
namespace D3\OxidSqlLogger;
|
||||
|
||||
use Monolog;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
class LoggerFactory
|
||||
{
|
||||
/**
|
||||
* @param $name
|
||||
* @return Monolog\Logger
|
||||
* @param string $name
|
||||
*
|
||||
* @return Logger
|
||||
*/
|
||||
public function create($name): Monolog\Logger
|
||||
public function create(string $name): Monolog\Logger
|
||||
{
|
||||
return new Monolog\Logger($name, $this->getHandlers(), $this->getProcessors());
|
||||
}
|
||||
@ -52,17 +54,17 @@ class LoggerFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $classNames
|
||||
* @param iterable $classNames
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getInstancesFromHandlerList(array $classNames): array
|
||||
private function getInstancesFromHandlerList(iterable $classNames): array
|
||||
{
|
||||
return array_map(
|
||||
function($className){
|
||||
return new $className();
|
||||
},
|
||||
$classNames
|
||||
(array) $classNames
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ use Doctrine\DBAL\Configuration;
|
||||
use Doctrine\DBAL\Logging\SQLLogger;
|
||||
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProvider;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@ -32,10 +33,10 @@ class OxidEsalesDatabase extends Database
|
||||
|
||||
$this->d3GetConfiguration()->setSQLLogger(
|
||||
new OxidSQLLogger(
|
||||
$trace[1]['file'] ?? null,
|
||||
(int) $trace[1]['line'] ?? null,
|
||||
$trace[2]['class'] ?? null,
|
||||
$trace[2]['function'] ?? null,
|
||||
$trace[1]['file'] ?? '',
|
||||
array_key_exists('line', $trace[1]) ? (int) $trace[1]['line'] : 0,
|
||||
$trace[2]['class'] ?? '',
|
||||
$trace[2]['function'] ?? '',
|
||||
$message
|
||||
)
|
||||
);
|
||||
@ -61,13 +62,15 @@ class OxidEsalesDatabase extends Database
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Configuration|null
|
||||
* @return Configuration
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function d3GetConfiguration(): ?Configuration
|
||||
protected function d3GetConfiguration(): Configuration
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer()
|
||||
->get(ConnectionProviderInterface::class)->get()->getConfiguration();
|
||||
/** @var ConnectionProvider $connectionProvider */
|
||||
$connectionProvider = ContainerFactory::getInstance()->getContainer()
|
||||
->get(ConnectionProviderInterface::class);
|
||||
return $connectionProvider->get()->getConfiguration();
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class OxidSQLLogger implements SQLLogger
|
||||
Monolog\Registry::addLogger((new LoggerFactory())->create('sql'));
|
||||
}
|
||||
|
||||
$this->message = $message;
|
||||
$this->message = (string) $message;
|
||||
$this->logStartingFile = $file;
|
||||
$this->logStartingLine = $line;
|
||||
$this->logStartingClass = $class;
|
||||
@ -92,6 +92,7 @@ class OxidSQLLogger implements SQLLogger
|
||||
if ($this->SQLQuery) {
|
||||
$formatter = new Formatter();
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
Monolog\Registry::sql()->addDebug(
|
||||
'['.$this->SQLQuery->getReadableElapsedTime().'] ' . ($this->message ?: $this->SQLQuery->getSql()),
|
||||
[
|
||||
|
@ -53,7 +53,7 @@ class SQLQuery
|
||||
|
||||
/**
|
||||
* @param string $sql
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setSql(string $sql): static
|
||||
{
|
||||
@ -72,7 +72,7 @@ class SQLQuery
|
||||
/**
|
||||
* @param array|null $params
|
||||
*
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setParams(array $params = null): static
|
||||
{
|
||||
@ -91,7 +91,7 @@ class SQLQuery
|
||||
/**
|
||||
* @param array|null $types
|
||||
*
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setTypes(array $types = null): static
|
||||
{
|
||||
@ -109,7 +109,7 @@ class SQLQuery
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setLogStartingFile(string $file): static
|
||||
{
|
||||
@ -125,7 +125,7 @@ class SQLQuery
|
||||
/**
|
||||
* @param int $line
|
||||
*
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setLogStartingLine(int $line): static
|
||||
{
|
||||
@ -144,7 +144,7 @@ class SQLQuery
|
||||
/**
|
||||
* @param string $classname
|
||||
*
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setLogStartingClass(string $classname): static
|
||||
{
|
||||
@ -163,7 +163,7 @@ class SQLQuery
|
||||
/**
|
||||
* @param string $functionname
|
||||
*
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setLogStartingFunction(string $functionname): static
|
||||
{
|
||||
@ -174,7 +174,7 @@ class SQLQuery
|
||||
/**
|
||||
* Statement was cancelled prematurely, an error was thrown.
|
||||
*
|
||||
* @return SQLQuery
|
||||
* @return static
|
||||
*/
|
||||
public function setCanceled(): static
|
||||
{
|
||||
@ -227,7 +227,7 @@ class SQLQuery
|
||||
$unit = 'ms';
|
||||
$time = round($microtime*1000);
|
||||
|
||||
$format = preg_replace('/(%.\d+f)/', '%d', $format);
|
||||
$format = (string) preg_replace('/(%.\d+f)/', '%d', $format);
|
||||
}
|
||||
|
||||
return sprintf($format, $time, $unit);
|
||||
|
@ -36,15 +36,17 @@ function D3StopSQLLog(): void
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param string $message
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
function D3AddSQLLogItem($message): void
|
||||
function D3AddSQLLogItem(string $message): void
|
||||
{
|
||||
/** @var OxidEsalesDatabase $database */
|
||||
$database = oxNew( OxidEsalesDatabase::class);
|
||||
$database->d3GetLogger()->startQuery($message);
|
||||
$database->d3GetLogger()->stopQuery();
|
||||
if ($logger = $database->d3GetLogger()) {
|
||||
$logger->startQuery( $message );
|
||||
$logger->stopQuery();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user