Skip to content

Commit

Permalink
Merge branch '3.x' into 3.next
Browse files Browse the repository at this point in the history
# Conflicts:
#	.phive/phars.xml
#	phpstan.neon
#	psalm-baseline.xml
#	src/CakeSentryInit.php
  • Loading branch information
LordSimal committed Nov 17, 2024
2 parents 1aca98e + 7fbe98a commit fa507c4
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.12.3" installed="1.12.3" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.26.1" installed="5.26.1" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="2.0.1" installed="2.0.1" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.26.1" installed="5.26.1" location="./tools/psalm" copy="false"/>
</phive>
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
parameters:
paths:
- src/
level: 5
level: 8
bootstrapFiles:
- tests/bootstrap.php
ignoreErrors:
-
identifier: missingType.iterableValue
29 changes: 4 additions & 25 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/Database/Log/CakeSentryLog.php">
<DocblockTypeContradiction>
<code><![CDATA[str_contains($querystring, 'FROM information_schema')]]></code>
</DocblockTypeContradiction>
<InternalMethod>
<code><![CDATA[getContext]]></code>
<code><![CDATA[getContext]]></code>
<code><![CDATA[jsonSerialize]]></code>
</InternalMethod>
<RiskyTruthyFalsyComparison>
<code><![CDATA[!$querystring]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/DebugTimer.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[!$message]]></code>
<code><![CDATA[!$name]]></code>
<code><![CDATA[!$name]]></code>
<code><![CDATA[$name]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/EventSpanTrait.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[$endTime]]></code>
<code><![CDATA[$startTime]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Http/SentryClient.php">
<InternalMethod>
<code><![CDATA[getContext]]></code>
</InternalMethod>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$extras]]></code>
<code><![CDATA[$extras]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Middleware/CakeSentryPerformanceMiddleware.php">
<RiskyTruthyFalsyComparison>
Expand All @@ -47,8 +29,5 @@
<InternalMethod>
<code><![CDATA[getContext]]></code>
</InternalMethod>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$connectionName]]></code>
</RiskyTruthyFalsyComparison>
</file>
</files>
2 changes: 1 addition & 1 deletion src/CakeSentryInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function init(): void
}

$config = self::getConfig('sentry');
if (is_array($config) && Hash::check($config, 'dsn')) {
if ($config !== null && Hash::check($config, 'dsn')) {
init($config);
$event = new Event('CakeSentry.Client.afterSetup');
EventManager::instance()->dispatch($event);
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Log/CakeSentryLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ protected function isSchemaQuery(LoggedQuery $query): bool
$context = $query->getContext();
$querystring = $context['query'] ?? false;

if (!$querystring) {
$querystring = $query->jsonSerialize()['query'];
if ($querystring === '') {
$querystring = $query->jsonSerialize()['query'] ?? '';
}

return // Multiple engines
Expand Down
16 changes: 8 additions & 8 deletions src/DebugTimer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class DebugTimer
protected static array $_timers = [];

/**
* Start an benchmarking timer.
* Start a benchmarking timer.
*
* @param string $name The name of the timer to start.
* @param string $message A message for your timer
* @param string|null $name The name of the timer to start.
* @param string|null $message A message for your timer
* @return bool Always true
*/
public static function start(?string $name = null, ?string $message = null): bool
{
$start = microtime(true);

if (!$name) {
if ($name === null) {
$named = false;
$calledFrom = debug_backtrace();
$file = $calledFrom[0]['file'] ?? 'unknown file';
Expand All @@ -51,7 +51,7 @@ public static function start(?string $name = null, ?string $message = null): boo
$named = true;
}

if (!$message) {
if ($message === null) {
$message = $name;
}

Expand Down Expand Up @@ -80,13 +80,13 @@ public static function start(?string $name = null, ?string $message = null): boo
*
* $name should be the same as the $name used in startTimer().
*
* @param string $name The name of the timer to end.
* @param string|null $name The name of the timer to end.
* @return bool true if timer was ended, false if timer was not started.
*/
public static function stop(?string $name = null): bool
{
$end = microtime(true);
if (!$name) {
if ($name === null) {
$names = array_reverse(array_keys(self::$_timers));
foreach ($names as $name) {
if (!empty(self::$_timers[$name]['end'])) {
Expand All @@ -110,7 +110,7 @@ public static function stop(?string $name = null): bool
if (!isset(self::$_timers[$name])) {
return false;
}
if ($name) {
if ($name !== null) {
self::$_timers[$name]['end'] = $end;
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventSpanTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function addEventSpan(string $name, string $sentryOp, ?float $startTime =
$spanContext->setDescription($name);
$spanContext->setOp($sentryOp);
//$spanContext->setData();
if ($startTime && $endTime) {
if ($startTime !== null && $endTime !== null) {
$spanContext->setStartTimestamp(DebugTimer::requestStartTime() + $startTime);
$spanContext->setEndTimestamp(DebugTimer::requestStartTime() + $endTime);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Http/SentryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function captureException(
$event = new Event('CakeSentry.Client.beforeCapture', $this, compact('exception', 'request'));
$eventManager->dispatch($event);

if ($extras) {
if ($extras !== null) {
$this->hub->configureScope(function (Scope $scope) use ($extras): void {
$scope->setExtras($extras);
});
Expand Down Expand Up @@ -152,7 +152,7 @@ public function captureError(
$event = new Event('CakeSentry.Client.beforeCapture', $this, compact('error', 'request'));
$eventManager->dispatch($event);

if ($extras) {
if ($extras !== null) {
$this->hub->configureScope(function (Scope $scope) use ($extras): void {
$scope->setExtras($extras);
});
Expand All @@ -163,7 +163,7 @@ public function captureError(

$client = $this->hub->getClient();
if ($client) {
/** @var array<int, array{function?: string, line?: int, file?: string, class?: class-string, type?: string, args?: array}> $trace */
/** @var list<array{function?: string, line?: int, file?: string, class?: class-string, type?: string, args?: array}> $trace */
$trace = $this->cleanedTrace($error->getTrace());
/** @psalm-suppress ArgumentTypeCoercion */
$stacktrace = $client->getStacktraceBuilder()
Expand Down Expand Up @@ -196,7 +196,7 @@ public function getHub(): HubInterface
* @param array<array<string, null|int|string|array>> $traces
* @return array<array<string, null|int|string|array>>
*/
private function cleanedTrace(array $traces): array
protected function cleanedTrace(array $traces): array
{
foreach ($traces as $key => $trace) {
if (isset($trace['line']) && ($trace['line'] === '??' || $trace['line'] === '')) {
Expand Down
2 changes: 1 addition & 1 deletion src/QuerySpanTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function addTransactionSpan(LoggedQuery $query, ?string $connectionName =
return;
}

if ($connectionName) {
if ($connectionName !== null) {
/** @var \Cake\Database\Driver $driver */
$driver = ConnectionManager::get($connectionName)->getDriver();
$dialect = $driver->schemaDialect();
Expand Down

0 comments on commit fa507c4

Please sign in to comment.