Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check driver is Cake Driver before trying to access #29

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Http/SentryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace CakeSentry\Http;

use Cake\Core\Configure;
use Cake\Database\Driver;
use Cake\Datasource\ConnectionManager;
use Cake\Error\PhpError;
use Cake\Event\Event;
Expand Down Expand Up @@ -53,13 +54,17 @@
$includeSchemaReflection = (bool)Configure::read('CakeSentry.includeSchemaReflection');

foreach ($configs as $name) {
$logger = null;
$connection = ConnectionManager::get($name);
if ($connection->configName() === 'debug_kit') {
continue;
}
/** @var \Cake\Database\Driver $driver */
$driver = $connection->getDriver();
$logger = $driver->getLogger();

if ($driver instanceof Driver) {

Check failure on line 65 in src/Http/SentryClient.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Instanceof between Cake\Database\Driver and Cake\Database\Driver will always evaluate to true.

Check failure on line 65 in src/Http/SentryClient.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

RedundantConditionGivenDocblockType

src/Http/SentryClient.php:65:17: RedundantConditionGivenDocblockType: Docblock-defined type Cake\Database\Driver for $driver is always Cake\Database\Driver (see https://psalm.dev/156)
$logger = $driver->getLogger();
}

if ($logger instanceof CakeSentryLog) {
$logger->setIncludeSchema($includeSchemaReflection);
Expand Down
13 changes: 8 additions & 5 deletions src/Middleware/CakeSentryPerformanceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
namespace CakeSentry\Middleware;

use Cake\Database\Driver;
use Cake\Datasource\ConnectionManager;
use Cake\Event\EventManager;
use Cake\Http\Server;
Expand Down Expand Up @@ -121,11 +122,13 @@
$logger = null;
/** @var \Cake\Database\Driver $driver */
$driver = $connection->getDriver();
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
if ($logger instanceof CakeSentryLog) {
$logger->setPerformanceMonitoring(true);
if ($driver instanceof Driver) {

Check failure on line 125 in src/Middleware/CakeSentryPerformanceMiddleware.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Instanceof between Cake\Database\Driver and Cake\Database\Driver will always evaluate to true.

Check failure on line 125 in src/Middleware/CakeSentryPerformanceMiddleware.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

RedundantConditionGivenDocblockType

src/Middleware/CakeSentryPerformanceMiddleware.php:125:17: RedundantConditionGivenDocblockType: Docblock-defined type Cake\Database\Driver for $driver is always Cake\Database\Driver (see https://psalm.dev/156)
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
if ($logger instanceof CakeSentryLog) {
$logger->setPerformanceMonitoring(true);

Check warning on line 130 in src/Middleware/CakeSentryPerformanceMiddleware.php

View check run for this annotation

Codecov / codecov/patch

src/Middleware/CakeSentryPerformanceMiddleware.php#L125-L130

Added lines #L125 - L130 were not covered by tests
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/Middleware/CakeSentryQueryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CakeSentry\Middleware;

use Cake\Core\Configure;
use Cake\Database\Driver;
use Cake\Datasource\ConnectionManager;
use CakeSentry\Database\Log\CakeSentryLog;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -59,9 +60,11 @@
$logger = null;
/** @var \Cake\Database\Driver $driver */
$driver = $connection->getDriver();
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
if ($driver instanceof Driver) {

Check failure on line 63 in src/Middleware/CakeSentryQueryMiddleware.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Instanceof between Cake\Database\Driver and Cake\Database\Driver will always evaluate to true.

Check failure on line 63 in src/Middleware/CakeSentryQueryMiddleware.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

RedundantConditionGivenDocblockType

src/Middleware/CakeSentryQueryMiddleware.php:63:17: RedundantConditionGivenDocblockType: Docblock-defined type Cake\Database\Driver for $driver is always Cake\Database\Driver (see https://psalm.dev/156)
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();

Check warning on line 66 in src/Middleware/CakeSentryQueryMiddleware.php

View check run for this annotation

Codecov / codecov/patch

src/Middleware/CakeSentryQueryMiddleware.php#L66

Added line #L66 was not covered by tests
}
}

$logger = new CakeSentryLog($logger, $name, $includeSchemaReflection);
Expand Down
Loading