From e8c572a6e3acd08ddc38f7205cf85861052dd7b2 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Thu, 1 Aug 2024 22:40:20 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20add=20compat=20for=20TYPO3=2013?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tasks.yml | 11 +- .../DataProcessor/TrackingDataProcessor.php | 2 +- Classes/ServiceProvider.php | 19 +- Classes/SqlLogging/LoggingConnection.php | 79 +++--- Classes/SqlLogging/LoggingDriver.php | 40 ++- Classes/SqlLogging/LoggingMiddleware.php | 31 ++- Classes/SqlLogging/LoggingStatement.php | 49 ++-- Classes/SqlLogging/SqlLoggerCore11.php | 5 + Classes/Utility/GuzzleUtility.php | 6 +- Classes/Utility/TimingUtility.php | 35 ++- Tests/TimingUtilityTest.php | 13 +- composer.json | 18 +- ext_emconf.php | 4 - ext_localconf.php | 14 +- infection.json | 2 +- phpstan-baseline.neon | 245 ++++++++++++++++++ phpstan.neon | 2 + rector.php | 16 +- 18 files changed, 443 insertions(+), 148 deletions(-) diff --git a/.github/workflows/tasks.yml b/.github/workflows/tasks.yml index 78afb3f..c8c6987 100644 --- a/.github/workflows/tasks.yml +++ b/.github/workflows/tasks.yml @@ -1,6 +1,6 @@ name: Tasks -on: [push, pull_request] +on: push jobs: lint-php: @@ -10,8 +10,15 @@ jobs: fail-fast: false matrix: php: [ '8.1', '8.2', '8.3' ] - typo3: [ '11', '12' ] + typo3: [ '11', '12', '13' ] sentry: [ false, true ] + exclude: + - php: '8.1' + typo3: '13' + sentry: true + - php: '8.1' + typo3: '13' + sentry: false steps: - name: Setup PHP with PECL extension uses: shivammathur/setup-php@v2 diff --git a/Classes/DataProcessor/TrackingDataProcessor.php b/Classes/DataProcessor/TrackingDataProcessor.php index 7653ebf..bf36d8a 100644 --- a/Classes/DataProcessor/TrackingDataProcessor.php +++ b/Classes/DataProcessor/TrackingDataProcessor.php @@ -21,7 +21,7 @@ final class TrackingDataProcessor implements DataProcessorInterface, SingletonIn * @param array $processedData * @return array */ - public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) + public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array { $id = (string)$processorConfiguration['id']; $stopWatch = $this->stopWatches[$id] ?? null; diff --git a/Classes/ServiceProvider.php b/Classes/ServiceProvider.php index 8d10ac7..9a8e3b2 100644 --- a/Classes/ServiceProvider.php +++ b/Classes/ServiceProvider.php @@ -4,6 +4,7 @@ namespace Kanti\ServerTiming; +use Closure; use Kanti\ServerTiming\Middleware\XClassMiddlewareDispatcher; use Psr\Container\ContainerInterface; use TYPO3\CMS\Backend\Http\Application as ApplicationBE; @@ -18,7 +19,7 @@ final class ServiceProvider extends AbstractServiceProvider { - public static function getPackagePath(): string + protected static function getPackagePath(): string { return __DIR__ . '/../'; } @@ -29,7 +30,7 @@ public static function getPackageName(): string } /** - * @return array + * @return array */ public function getFactories(): array { @@ -46,6 +47,13 @@ public static function getApplicationFE(ContainerInterface $container): Applicat $container->get('frontend.middlewares'), $container, ); + if (version_compare((new Typo3Version())->getBranch(), '13.0', '>=')) { + return new ApplicationFE( + $requestHandler, + $container->get(Context::class), + ); + } + if (version_compare((new Typo3Version())->getBranch(), '12.0', '>=') && class_exists(BackendEntryPointResolver::class)) { return new ApplicationFE( $requestHandler, @@ -69,6 +77,13 @@ public static function getApplicationBE(ContainerInterface $container): Applicat $container->get('backend.middlewares'), $container, ); + if (version_compare((new Typo3Version())->getBranch(), '13.0', '>=')) { + return new ApplicationBE( + $requestHandler, + $container->get(Context::class), + ); + } + if (version_compare((new Typo3Version())->getBranch(), '12.0', '>=') && class_exists(BackendEntryPointResolver::class)) { return new ApplicationBE( $requestHandler, diff --git a/Classes/SqlLogging/LoggingConnection.php b/Classes/SqlLogging/LoggingConnection.php index 4ae45bc..e525f91 100644 --- a/Classes/SqlLogging/LoggingConnection.php +++ b/Classes/SqlLogging/LoggingConnection.php @@ -6,43 +6,42 @@ namespace Kanti\ServerTiming\SqlLogging; -// -//use Doctrine\DBAL\Driver\Connection as ConnectionInterface; -//use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware; -//use Doctrine\DBAL\Driver\Result; -//use Doctrine\DBAL\Driver\Statement as DriverStatement; -// -//if (!class_exists(AbstractConnectionMiddleware::class)) { -// return; -//} -// -//final class LoggingConnection extends AbstractConnectionMiddleware -//{ -// public function __construct(ConnectionInterface $connection, private readonly DoctrineSqlLogger $logger) -// { -// parent::__construct($connection); -// } -// -// public function prepare(string $sql): DriverStatement -// { -// return new LoggingStatement(parent::prepare($sql), $this->logger, $sql); -// } -// -// public function query(string $sql): Result -// { -// $this->logger->startQuery($sql); -// $query = parent::query($sql); -// $this->logger->stopQuery(); -// -// return $query; -// } -// -// public function exec(string $sql): int -// { -// $this->logger->startQuery($sql); -// $query = parent::exec($sql); -// $this->logger->stopQuery(); -// -// return $query; -// } -//} +use Doctrine\DBAL\Driver\Connection as ConnectionInterface; +use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware; +use Doctrine\DBAL\Driver\Result; +use Doctrine\DBAL\Driver\Statement as DriverStatement; + +if (!class_exists(AbstractConnectionMiddleware::class)) { + return; +} + +final class LoggingConnection extends AbstractConnectionMiddleware +{ + public function __construct(ConnectionInterface $connection, private readonly DoctrineSqlLogger $logger) + { + parent::__construct($connection); + } + + public function prepare(string $sql): DriverStatement + { + return new LoggingStatement(parent::prepare($sql), $this->logger, $sql); + } + + public function query(string $sql): Result + { + $this->logger->startQuery($sql); + $query = parent::query($sql); + $this->logger->stopQuery(); + + return $query; + } + + public function exec(string $sql): int + { + $this->logger->startQuery($sql); + $query = parent::exec($sql); + $this->logger->stopQuery(); + + return (int)$query; + } +} diff --git a/Classes/SqlLogging/LoggingDriver.php b/Classes/SqlLogging/LoggingDriver.php index bda8de4..c9672ec 100644 --- a/Classes/SqlLogging/LoggingDriver.php +++ b/Classes/SqlLogging/LoggingDriver.php @@ -6,24 +6,22 @@ namespace Kanti\ServerTiming\SqlLogging; -// -//use Doctrine\DBAL\Driver as DriverInterface; -//use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware; -//use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; -// -//if (!class_exists(AbstractDriverMiddleware::class)) { -// return; -//} -// -//final class LoggingDriver extends AbstractDriverMiddleware -//{ -// public function __construct(DriverInterface $driver, private readonly DoctrineSqlLogger $logger) -// { -// parent::__construct($driver); -// } -// -// public function connect(array $params) -// { -// return new LoggingConnection(parent::connect($params), $this->logger); -// } -//} +use Doctrine\DBAL\Driver as DriverInterface; +use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; + +if (!class_exists(AbstractDriverMiddleware::class)) { + return; +} + +final class LoggingDriver extends AbstractDriverMiddleware +{ + public function __construct(DriverInterface $driver, private readonly DoctrineSqlLogger $logger) + { + parent::__construct($driver); + } + + public function connect(array $params): DriverInterface\Connection + { + return new LoggingConnection(parent::connect($params), $this->logger); + } +} diff --git a/Classes/SqlLogging/LoggingMiddleware.php b/Classes/SqlLogging/LoggingMiddleware.php index 21b9ab1..43e5706 100644 --- a/Classes/SqlLogging/LoggingMiddleware.php +++ b/Classes/SqlLogging/LoggingMiddleware.php @@ -6,19 +6,18 @@ namespace Kanti\ServerTiming\SqlLogging; -// -//use Doctrine\DBAL\Driver as DriverInterface; -//use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface; -//use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; -// -//if (!interface_exists(MiddlewareInterface::class)) { -// return; -//} -// -//final class LoggingMiddleware implements MiddlewareInterface -//{ -// public function wrap(DriverInterface $driver): DriverInterface -// { -// return new LoggingDriver($driver, new DoctrineSqlLogger()); -// } -//} +use Doctrine\DBAL\Driver as DriverInterface; +use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface; +use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; + +if (!interface_exists(MiddlewareInterface::class)) { + return; +} + +final class LoggingMiddleware implements MiddlewareInterface +{ + public function wrap(DriverInterface $driver): DriverInterface + { + return new LoggingDriver($driver, new DoctrineSqlLogger()); + } +} diff --git a/Classes/SqlLogging/LoggingStatement.php b/Classes/SqlLogging/LoggingStatement.php index 3c3dade..da5c458 100644 --- a/Classes/SqlLogging/LoggingStatement.php +++ b/Classes/SqlLogging/LoggingStatement.php @@ -6,28 +6,27 @@ namespace Kanti\ServerTiming\SqlLogging; -// -//use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware; -//use Doctrine\DBAL\Driver\Result as ResultInterface; -//use Doctrine\DBAL\Driver\Statement as StatementInterface; -// -//if (!class_exists(AbstractStatementMiddleware::class)) { -// return; -//} -// -//final class LoggingStatement extends AbstractStatementMiddleware -//{ -// public function __construct(StatementInterface $statement, private readonly DoctrineSqlLogger $logger, private readonly string $sql) -// { -// parent::__construct($statement); -// } -// -// public function execute($params = null): ResultInterface -// { -// $this->logger->startQuery($this->sql); -// $result = parent::execute($params); -// $this->logger->stopQuery(); -// -// return $result; -// } -//} +use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware; +use Doctrine\DBAL\Driver\Result as ResultInterface; +use Doctrine\DBAL\Driver\Statement as StatementInterface; + +if (!class_exists(AbstractStatementMiddleware::class)) { + return; +} + +final class LoggingStatement extends AbstractStatementMiddleware +{ + public function __construct(StatementInterface $statement, private readonly DoctrineSqlLogger $logger, private readonly string $sql) + { + parent::__construct($statement); + } + + public function execute($params = null): ResultInterface + { + $this->logger->startQuery($this->sql); + $result = parent::execute($params); + $this->logger->stopQuery(); + + return $result; + } +} diff --git a/Classes/SqlLogging/SqlLoggerCore11.php b/Classes/SqlLogging/SqlLoggerCore11.php index 465b75a..b93b847 100644 --- a/Classes/SqlLogging/SqlLoggerCore11.php +++ b/Classes/SqlLogging/SqlLoggerCore11.php @@ -8,6 +8,7 @@ use Kanti\ServerTiming\Dto\StopWatch; use Kanti\ServerTiming\Utility\TimingUtility; use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -20,6 +21,10 @@ final class SqlLoggerCore11 */ public static function registerSqlLogger(): void { + if (version_compare((new Typo3Version())->getBranch(), '12.3', '>=')) { + return; + } + $doctrineSqlLogger = new DoctrineSqlLogger(); $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); diff --git a/Classes/Utility/GuzzleUtility.php b/Classes/Utility/GuzzleUtility.php index fe6c0cb..e293915 100644 --- a/Classes/Utility/GuzzleUtility.php +++ b/Classes/Utility/GuzzleUtility.php @@ -4,6 +4,8 @@ namespace Kanti\ServerTiming\Utility; +use LogicException; +use Throwable; use Closure; use GuzzleHttp\Exception\RequestException as GuzzleRequestException; use GuzzleHttp\Promise\PromiseInterface; @@ -28,7 +30,7 @@ public static function getHandler(): ?Closure return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($handler): PromiseInterface { try { GeneralUtility::getContainer(); - } catch (\LogicException) { + } catch (LogicException) { // container not found: // than we are most likely in a subprocess (spatie/async) // and we don't want to initialize the container here! @@ -52,7 +54,7 @@ public static function getHandler(): ?Closure $stop->info = $request->getMethod() . ' ' . $response->getStatusCode() . ' ' . $request->getUri()->__toString(); } - if ($responseOrException instanceof \Throwable) { + if ($responseOrException instanceof Throwable) { throw $responseOrException; } diff --git a/Classes/Utility/TimingUtility.php b/Classes/Utility/TimingUtility.php index e1cf9ee..984532c 100644 --- a/Classes/Utility/TimingUtility.php +++ b/Classes/Utility/TimingUtility.php @@ -20,6 +20,8 @@ final class TimingUtility implements SingletonInterface { + public const MAX_SINGLE_HEADER_SIZE = 2 ** 12; + private static ?TimingUtility $instance = null; private bool $registered = false; @@ -163,19 +165,23 @@ public function shutdown(ScriptResult $result): ?ResponseInterface } - $headerString = implode(',', $timings); if (!$timings) { return $response; } + $chunks = $this->chunkStringArray($timings, self::MAX_SINGLE_HEADER_SIZE - strlen('Server-Timing: ')); + $memoryUsage = $this->humanReadableFileSize(memory_get_peak_usage()); if ($response) { return $response - ->withAddedHeader('Server-Timing', $headerString) + ->withAddedHeader('Server-Timing', $chunks) ->withAddedHeader('X-Max-Memory-Usage', $memoryUsage); } - header('Server-Timing: ' . $headerString, false); + foreach ($chunks as $chunk) { + header('Server-Timing: ' . $chunk, false); + } + header('X-Max-Memory-Usage: ' . $memoryUsage, false); return $response; } @@ -284,4 +290,27 @@ private function isBackendUser(): bool { return (bool)GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('backend.user', 'isLoggedIn'); } + + /** + * @param list $timings + * @return list + */ + private function chunkStringArray(array $timings, int $maxLength): array + { + $result = []; + $length = 0; + $index = 0; + foreach ($timings as $timing) { + $length += 1 + strlen($timing); + if ($length > $maxLength) { + $index++; + $length = strlen($timing); + } + + $result[$index] ??= ''; + $result[$index] .= ($result[$index] ? ',' : '') . $timing; + } + + return $result; + } } diff --git a/Tests/TimingUtilityTest.php b/Tests/TimingUtilityTest.php index 907dcc3..effe705 100644 --- a/Tests/TimingUtilityTest.php +++ b/Tests/TimingUtilityTest.php @@ -412,6 +412,17 @@ public function shouldTrack(): void self::assertFalse($timingUtility->shouldTrack()); } + #[Test] + public function chunkStringArray(): void + { + $reflection = new ReflectionClass(TimingUtility::class); + $reflectionMethod = $reflection->getMethod('chunkStringArray'); + $reflectionMethod->setAccessible(true); + + $result = $reflectionMethod->invoke($this->getTestInstance(), ['a', 'b', 'c', 'd', 'e', 'f'], 4); + self::assertSame(['a,b', 'c,d', 'e,f'], $result); + } + /** * @param StopWatch[] $stopWatches */ @@ -419,7 +430,7 @@ private function getTestInstance(array $stopWatches = []): TimingUtility { $timingUtility = new TimingUtility(new RegisterShutdownFunctionNoop(), new ConfigService()); $timingUtility::$isTesting = true; - $reflection = new \ReflectionClass($timingUtility); + $reflection = new ReflectionClass($timingUtility); $reflection->getProperty('order')->setValue($timingUtility, $stopWatches); return $timingUtility; } diff --git a/composer.json b/composer.json index 6018a7c..78fde37 100644 --- a/composer.json +++ b/composer.json @@ -12,20 +12,18 @@ "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "composer-runtime-api": "^2.0.0", - "typo3/cms-core": "^11.0 || ^12.0", - "typo3/cms-extbase": "^11.0 || ^12.0" + "typo3/cms-core": "^11.0 || ^12.0 || ^13.0", + "typo3/cms-extbase": "^11.0 || ^12.0 || ^13.0" }, "require-dev": { - "andersundsehr/resource-watcher": "dev-master", - "infection/infection": "^0.26.13", + "infection/infection": "^0.26.13 || ^0.27.11", "phpstan/extension-installer": "^1.1", - "phpunit/phpunit": "^10", - "pluswerk/grumphp-config": "^6.8.0", - "saschaegerer/phpstan-typo3": "^1.1", + "phpunit/phpunit": "^10 || ^11", + "pluswerk/grumphp-config": "^7", + "saschaegerer/phpstan-typo3": "^1.10.1", "sentry/sdk": "^3.5", - "spatie/phpunit-watcher": "^1.23", - "ssch/typo3-rector": "^1.1.3", - "typo3/cms-adminpanel": "^11.0 || ^12.0" + "ssch/typo3-rector": "^2.6.4", + "typo3/cms-adminpanel": "^11.0 || ^12.0 || ^13.0" }, "minimum-stability": "stable", "autoload": { diff --git a/ext_emconf.php b/ext_emconf.php index 0536b83..4768beb 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -10,10 +10,6 @@ 'author' => 'Matthias Vogel', 'author_email' => 'git@kanti.de', 'state' => 'stable', - 'internal' => '', - 'uploadfolder' => '0', - 'createDirs' => '', - 'clearCacheOnLoad' => 0, 'version' => InstalledVersions::getPrettyVersion('kanti/server-timing'), 'constraints' => [ 'depends' => [ diff --git a/ext_localconf.php b/ext_localconf.php index 8952616..2adf8ce 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -11,13 +11,13 @@ use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor; // can be used instead after TYPO3 support is set to >=12 -//if (version_compare((new Typo3Version())->getBranch(), '12.3', '>=')) { -// $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driverMiddlewares']['server_timing_logging'] = LoggingMiddleware::class; -//} else { -$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][SqlLogging::class] = [ - 'className' => AdminpanelSqlLoggingMiddleware::class, -]; -//} +if (version_compare((new Typo3Version())->getBranch(), '12.3', '>=')) { + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driverMiddlewares']['server_timing_logging'] = LoggingMiddleware::class; +} else { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][SqlLogging::class] = [ + 'className' => AdminpanelSqlLoggingMiddleware::class, + ]; +} $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][Dispatcher::class] = [ 'className' => XClassExtbaseDispatcher::class, diff --git a/infection.json b/infection.json index 150c7f7..9b166af 100644 --- a/infection.json +++ b/infection.json @@ -12,7 +12,7 @@ "text": "Resources/Public/test-result/infection.log", "html": "Resources/Public/test-result/infection.html" }, - "minCoveredMsi": 97, + "minCoveredMsi": 96.8, "initialTestsPhpOptions": "-d pcov.enabled=1", "mutators": { "@default": true diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b1ae905..74a489e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,6 +5,46 @@ parameters: count: 1 path: Classes/Middleware/AdminpanelSqlLoggingMiddleware.php + - + message: "#^Using nullsafe method call on non\\-nullable type Kanti\\\\ServerTiming\\\\Dto\\\\StopWatch\\. Use \\-\\> instead\\.$#" + count: 1 + path: Classes/Middleware/WrapMiddleware.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor invoked with 2 parameters, 4 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor invoked with 3 parameters, 4 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor invoked with 2 parameters, 4 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor invoked with 3 parameters, 4 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Parameter \\#2 \\$configurationManager of class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor expects TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\ConfigurationManager, TYPO3\\\\CMS\\\\Core\\\\Context\\\\Context given\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Parameter \\#2 \\$configurationManager of class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor expects TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\ConfigurationManager, TYPO3\\\\CMS\\\\Core\\\\Context\\\\Context given\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Parameter \\#1 \\$loggers of class Doctrine\\\\DBAL\\\\Logging\\\\LoggerChain constructor expects iterable\\, array\\ given\\.$#" + count: 1 + path: Classes/Middleware/AdminpanelSqlLoggingMiddleware.php + - message: "#^Call to method getMessage\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Mail\\\\Event\\\\BeforeMailerSentMessageEvent\\.$#" count: 1 @@ -224,3 +264,208 @@ parameters: message: "#^Used function Sentry\\\\getTraceparent not found\\.$#" count: 1 path: Classes/Service/SentryService.php + + - + message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Configuration\\:\\:getSQLLogger\\(\\)\\.$#" + count: 1 + path: Classes/Middleware/AdminpanelSqlLoggingMiddleware.php + + - + message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Configuration\\:\\:setSQLLogger\\(\\)\\.$#" + count: 1 + path: Classes/Middleware/AdminpanelSqlLoggingMiddleware.php + + - + message: "#^Instantiated class Doctrine\\\\DBAL\\\\Logging\\\\LoggerChain not found\\.$#" + count: 1 + path: Classes/Middleware/AdminpanelSqlLoggingMiddleware.php + + - + message: "#^Using nullsafe method call on non\\-nullable type Kanti\\\\ServerTiming\\\\Dto\\\\StopWatch\\. Use \\-\\> instead\\.$#" + count: 1 + path: Classes/Middleware/WrapMiddleware.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor invoked with 3 parameters, 2 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor invoked with 4 parameters, 2 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor invoked with 3 parameters, 2 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor invoked with 4 parameters, 2 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Parameter \\#2 \\$context of class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor expects TYPO3\\\\CMS\\\\Core\\\\Context\\\\Context, TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\ConfigurationManager given\\.$#" + count: 2 + path: Classes/ServiceProvider.php + + - + message: "#^Parameter \\#2 \\$context of class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor expects TYPO3\\\\CMS\\\\Core\\\\Context\\\\Context, TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\ConfigurationManager given\\.$#" + count: 2 + path: Classes/ServiceProvider.php + + - + message: "#^Method Doctrine\\\\DBAL\\\\Driver\\\\Middleware\\\\AbstractStatementMiddleware\\:\\:execute\\(\\) invoked with 1 parameter, 0 required\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingStatement.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement\\:\\:execute\\(\\) has parameter \\$params with no type specified\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingStatement.php + + - + message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Configuration\\:\\:setSQLLogger\\(\\)\\.$#" + count: 1 + path: Classes/SqlLogging/SqlLoggerCore11.php + + - + message: "#^Method class@anonymous/Classes/SqlLogging/SqlLoggerCore11\\.php\\:33\\:\\:startQuery\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#" + count: 1 + path: Classes/SqlLogging/SqlLoggerCore11.php + + - + message: "#^Method class@anonymous/Classes/SqlLogging/SqlLoggerCore11\\.php\\:33\\:\\:startQuery\\(\\) has parameter \\$sql with no type specified\\.$#" + count: 1 + path: Classes/SqlLogging/SqlLoggerCore11.php + + - + message: "#^Method class@anonymous/Classes/SqlLogging/SqlLoggerCore11\\.php\\:33\\:\\:startQuery\\(\\) has parameter \\$types with no value type specified in iterable type array\\.$#" + count: 1 + path: Classes/SqlLogging/SqlLoggerCore11.php + + - + message: "#^Call to method getMessage\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Mail\\\\Event\\\\BeforeMailerSentMessageEvent\\.$#" + count: 1 + path: Classes/EventListener/MailEventListener.php + + - + message: "#^Parameter \\$event of method Kanti\\\\ServerTiming\\\\EventListener\\\\MailEventListener\\:\\:start\\(\\) has invalid type TYPO3\\\\CMS\\\\Core\\\\Mail\\\\Event\\\\BeforeMailerSentMessageEvent\\.$#" + count: 1 + path: Classes/EventListener/MailEventListener.php + + - + message: "#^Parameter \\$event of method Kanti\\\\ServerTiming\\\\EventListener\\\\MailEventListener\\:\\:stop\\(\\) has invalid type TYPO3\\\\CMS\\\\Core\\\\Mail\\\\Event\\\\AfterMailerSentMessageEvent\\.$#" + count: 1 + path: Classes/EventListener/MailEventListener.php + + - + message: "#^Using nullsafe method call on non\\-nullable type Kanti\\\\ServerTiming\\\\Dto\\\\StopWatch\\. Use \\-\\> instead\\.$#" + count: 1 + path: Classes/Middleware/WrapMiddleware.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor invoked with 2 parameters, 3 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor invoked with 4 parameters, 3 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor invoked with 2 parameters, 3 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor invoked with 4 parameters, 3 required\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Parameter \\#2 \\$configurationManager of class TYPO3\\\\CMS\\\\Backend\\\\Http\\\\Application constructor expects TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\ConfigurationManager, TYPO3\\\\CMS\\\\Core\\\\Context\\\\Context given\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Parameter \\#2 \\$configurationManager of class TYPO3\\\\CMS\\\\Frontend\\\\Http\\\\Application constructor expects TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\ConfigurationManager, TYPO3\\\\CMS\\\\Core\\\\Context\\\\Context given\\.$#" + count: 1 + path: Classes/ServiceProvider.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection\\:\\:__construct\\(\\) calls parent\\:\\:__construct\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingConnection.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection\\:\\:exec\\(\\) calls parent\\:\\:exec\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingConnection.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection\\:\\:prepare\\(\\) calls parent\\:\\:prepare\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingConnection.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection\\:\\:query\\(\\) calls parent\\:\\:query\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingConnection.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection\\:\\:prepare\\(\\) return type has no value type specified in iterable type Doctrine\\\\DBAL\\\\Driver\\\\Statement\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingConnection.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection\\:\\:prepare\\(\\) should return Doctrine\\\\DBAL\\\\Driver\\\\Statement but returns Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingConnection.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingDriver\\:\\:__construct\\(\\) calls parent\\:\\:__construct\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingDriver does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingDriver.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingDriver\\:\\:connect\\(\\) calls parent\\:\\:connect\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingDriver does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingDriver.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingDriver\\:\\:connect\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingDriver.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingDriver\\:\\:connect\\(\\) should return Doctrine\\\\DBAL\\\\Driver\\\\Connection but returns Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingConnection\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingDriver.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingMiddleware\\:\\:wrap\\(\\) should return Doctrine\\\\DBAL\\\\Driver but returns Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingDriver\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingMiddleware.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement\\:\\:__construct\\(\\) calls parent\\:\\:__construct\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingStatement.php + + - + message: "#^Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement\\:\\:execute\\(\\) calls parent\\:\\:execute\\(\\) but Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement does not extend any class\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingStatement.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement\\:\\:__construct\\(\\) has parameter \\$statement with no value type specified in iterable type Doctrine\\\\DBAL\\\\Driver\\\\Statement\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingStatement.php + + - + message: "#^Method Kanti\\\\ServerTiming\\\\SqlLogging\\\\LoggingStatement\\:\\:execute\\(\\) has parameter \\$params with no type specified\\.$#" + count: 1 + path: Classes/SqlLogging/LoggingStatement.php diff --git a/phpstan.neon b/phpstan.neon index a6f86c2..bdc951d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,3 +8,5 @@ parameters: typo3: requestGetAttributeMapping: middleware.in.total: Kanti\ServerTiming\Dto\StopWatch|null + excludePaths: + - Classes/SqlLogging/SqlLoggerCore11.php diff --git a/rector.php b/rector.php index 5c2a868..88f9c93 100644 --- a/rector.php +++ b/rector.php @@ -2,12 +2,10 @@ declare(strict_types=1); -use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; -use Rector\PHPUnit\Set\PHPUnitLevelSetList; use PLUS\GrumPHPConfig\RectorSettings; use Rector\Config\RectorConfig; use Rector\Caching\ValueObject\Storage\FileCacheStorage; -use Rector\PHPUnit\Set\PHPUnitSetList; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodParameterRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->parallel(); @@ -17,7 +15,7 @@ $rectorConfig->cacheDirectory('./var/cache/rector'); $rectorConfig->paths( - array_filter(explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep -E '\.(php|html|typoscript)$'"))) + array_filter(explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep -E '\.(php)$'"))) ); // define sets of rules @@ -25,13 +23,6 @@ [ ...RectorSettings::sets(true), ...RectorSettings::setsTypo3(false), - PHPUnitLevelSetList::UP_TO_PHPUNIT_100, - PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, - PHPUnitSetList::PHPUNIT_CODE_QUALITY, - PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER, - PHPUnitSetList::PHPUNIT_EXCEPTION, - PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, - PHPUnitSetList::REMOVE_MOCKS, ] ); @@ -42,11 +33,10 @@ ...RectorSettings::skip(), ...RectorSettings::skipTypo3(), - MakeInheritedMethodVisibilitySameAsParentRector::class - /** * rector should not touch these files */ + RemoveUnusedPublicMethodParameterRector::class, //__DIR__ . '/src/Example', //__DIR__ . '/src/Example.php', ]