Skip to content
Open
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
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
- ubuntu-latest
- windows-latest
php:
- { version: '7.2', phpunit: '^8.5.40' }
- { version: '7.3', phpunit: '^9.6.21' }
- { version: '7.4', phpunit: '^9.6.21' }
- { version: '8.0', phpunit: '^9.6.21' }
- { version: '8.1', phpunit: '^9.6.21' }
- { version: '8.2', phpunit: '^9.6.21' }
- { version: '8.3', phpunit: '^9.6.21' }
- { version: '8.4', phpunit: '^9.6.21' }
- { version: '8.5', phpunit: '^9.6.25' }
- { version: '7.2', phpunit: '^8.5.52' }
- { version: '7.3', phpunit: '^9.6.34' }
- { version: '7.4', phpunit: '^9.6.34' }
- { version: '8.0', phpunit: '^9.6.34' }
- { version: '8.1', phpunit: '^9.6.34' }
- { version: '8.2', phpunit: '^9.6.34' }
- { version: '8.3', phpunit: '^9.6.34' }
- { version: '8.4', phpunit: '^9.6.34' }
- { version: '8.5', phpunit: '^9.6.34' }
dependencies:
- lowest
- highest
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"monolog/monolog": "^1.6|^2.0|^3.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.5|^9.6",
"phpunit/phpunit": "^8.5.52|^9.6.33",
"vimeo/psalm": "^4.17"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function sendRequest(Request $request, Options $options): Response
}

$responseHeaders = [];
$responseHeaderCallback = function ($curlHandle, $headerLine) use (&$responseHeaders): int {
$responseHeaderCallback = static function ($curlHandle, $headerLine) use (&$responseHeaders): int {
return Http::parseResponseHeaders($headerLine, $responseHeaders);
};

Expand Down
4 changes: 2 additions & 2 deletions src/Logs/LogsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function add(
$log->setAttribute('sentry.sdk.version', $client->getSdkVersion());
}

$hub->configureScope(function (Scope $scope) use ($log) {
$hub->configureScope(static function (Scope $scope) use ($log) {
$user = $scope->getUser();
if ($user !== null) {
if ($user->getId() !== null) {
Expand Down Expand Up @@ -186,7 +186,7 @@ private function getTraceId(HubInterface $hub): string

$traceId = '';

$hub->configureScope(function (Scope $scope) use (&$traceId) {
$hub->configureScope(static function (Scope $scope) use (&$traceId) {
$traceId = (string) $scope->getPropagationContext()->getTraceId();
});

Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function timing(
int $stackLevel = 0
) {
return trace(
function () use ($callback) {
static function () use ($callback) {
return $callback();
},
SpanContext::make()
Expand Down
4 changes: 2 additions & 2 deletions src/Metrics/MetricsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function add(
];

if ($options->shouldSendDefaultPii()) {
$hub->configureScope(function (Scope $scope) use (&$defaultAttributes) {
$hub->configureScope(static function (Scope $scope) use (&$defaultAttributes) {
$user = $scope->getUser();
if ($user !== null) {
if ($user->getId() !== null) {
Expand Down Expand Up @@ -111,7 +111,7 @@ public function add(
$spanId = $span->getSpanId();
$traceId = $span->getTraceId();
} else {
$hub->configureScope(function (Scope $scope) use (&$traceId, &$spanId) {
$hub->configureScope(static function (Scope $scope) use (&$traceId, &$spanId) {
$propagationContext = $scope->getPropagationContext();
$traceId = $propagationContext->getTraceId();
$spanId = $propagationContext->getSpanId();
Expand Down
4 changes: 2 additions & 2 deletions src/State/HubAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@
/**
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup
*/
public function __wakeup()
public function __unserialize(array $data)

Check failure on line 209 in src/State/HubAdapter.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Sentry\State\HubAdapter::__unserialize() has parameter $data with no value type specified in iterable type array.
{
throw new \BadMethodCallException('Unserializing instances of this class is forbidden.');
}

/**
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.sleep
*/
public function __sleep()
public function __serialize()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serialization protection broken for PHP 7.2 and 7.3

High Severity

The __sleep() and __wakeup() methods were replaced with __serialize() and __unserialize(), but these magic methods were only introduced in PHP 7.4. Since the project supports PHP 7.2+ (per composer.json), on PHP 7.2 and 7.3 these methods won't be called during serialization, breaking the singleton pattern protection. Users on those PHP versions could now serialize/unserialize the HubAdapter singleton.

Fix in Cursor Fix in Web

{
throw new \BadMethodCallException('Serializing instances of this class is forbidden.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function setStatus(?SpanStatus $status)
*/
public function setHttpStatus(int $statusCode)
{
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) use ($statusCode) {
SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use ($statusCode) {
$scope->setContext('response', [
'status_code' => $statusCode,
]);
Expand Down
10 changes: 5 additions & 5 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function startTransaction(TransactionContext $context, array $customSamplingCont
*/
function trace(callable $trace, SpanContext $context)
{
return SentrySdk::getCurrentHub()->withScope(function (Scope $scope) use ($context, $trace) {
return SentrySdk::getCurrentHub()->withScope(static function (Scope $scope) use ($context, $trace) {
$parentSpan = $scope->getSpan();

// If there is a span set on the scope and it's sampled there is an active transaction.
Expand Down Expand Up @@ -299,7 +299,7 @@ function getTraceparent(): string
}

$traceParent = '';
$hub->configureScope(function (Scope $scope) use (&$traceParent) {
$hub->configureScope(static function (Scope $scope) use (&$traceParent) {
$traceParent = $scope->getPropagationContext()->toTraceparent();
});

Expand Down Expand Up @@ -342,7 +342,7 @@ function getBaggage(): string
}

$baggage = '';
$hub->configureScope(function (Scope $scope) use (&$baggage) {
$hub->configureScope(static function (Scope $scope) use (&$baggage) {
$baggage = $scope->getPropagationContext()->toBaggage();
});

Expand All @@ -358,7 +358,7 @@ function getBaggage(): string
function continueTrace(string $sentryTrace, string $baggage): TransactionContext
{
$hub = SentrySdk::getCurrentHub();
$hub->configureScope(function (Scope $scope) use ($sentryTrace, $baggage) {
$hub->configureScope(static function (Scope $scope) use ($sentryTrace, $baggage) {
$propagationContext = PropagationContext::fromHeaders($sentryTrace, $baggage);
$scope->setPropagationContext($propagationContext);
});
Expand Down Expand Up @@ -393,7 +393,7 @@ function trace_metrics(): TraceMetrics
*/
function addFeatureFlag(string $name, bool $result): void
{
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) use ($name, $result) {
SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use ($name, $result) {
$scope->addFeatureFlag($name, $result);
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ public function testAttachStacktrace(): void
$transport = $this->createMock(TransportInterface::class);
$transport->expects($this->once())
->method('send')
->with($this->callback(function (Event $event): bool {
->with($this->callback(static function (Event $event): bool {
$result = $event->getStacktrace();

return $result !== null;
Expand Down
10 changes: 5 additions & 5 deletions tests/FrameBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function testGetFunctionArgumentsWithVariadicParameters(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, int $second, ...$rest) {
$testFunction = static function (string $first, int $second, ...$rest) {
};

$backtraceFrame = [
Expand Down Expand Up @@ -325,7 +325,7 @@ public function testGetFunctionArgumentsWithOnlyVariadicParameters(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (...$args) {
$testFunction = static function (...$args) {
};

$backtraceFrame = [
Expand All @@ -352,7 +352,7 @@ public function testGetFunctionArgumentsWithEmptyVariadicParameters(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, ...$rest) {
$testFunction = static function (string $first, ...$rest) {
};

$backtraceFrame = [
Expand Down Expand Up @@ -381,7 +381,7 @@ public function testGetFunctionArgumentsWithNullValues(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, $second, ...$rest) {
$testFunction = static function (string $first, $second, ...$rest) {
};

$backtraceFrame = [
Expand Down Expand Up @@ -411,7 +411,7 @@ public function testGetFunctionArgumentsWithGapsInBacktraceArrayIndices(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, int $second, ...$rest) {
$testFunction = static function (string $first, int $second, ...$rest) {
};

$backtraceFrameArgs = [];
Expand Down
20 changes: 10 additions & 10 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ public function testWithMonitor(): void
$hub->expects($this->exactly(2))
->method('captureCheckIn')
->with(
$this->callback(function (string $slug): bool {
$this->callback(static function (string $slug): bool {
return $slug === 'test-crontab';
}),
$this->callback(function (CheckInStatus $checkInStatus): bool {
$this->callback(static function (CheckInStatus $checkInStatus): bool {
// just check for type CheckInStatus
return true;
}),
$this->anything(),
$this->callback(function (MonitorConfig $monitorConfig): bool {
$this->callback(static function (MonitorConfig $monitorConfig): bool {
return $monitorConfig->getSchedule()->getValue() === '*/5 * * * *'
&& $monitorConfig->getSchedule()->getType() === MonitorSchedule::TYPE_CRONTAB
&& $monitorConfig->getCheckinMargin() === 5
Expand All @@ -243,7 +243,7 @@ public function testWithMonitor(): void

SentrySdk::setCurrentHub($hub);

withMonitor('test-crontab', function () {
withMonitor('test-crontab', static function () {
// Do something...
}, new MonitorConfig(
new MonitorSchedule(MonitorSchedule::TYPE_CRONTAB, '*/5 * * * *'),
Expand All @@ -261,15 +261,15 @@ public function testWithMonitorCallableThrows(): void
$hub->expects($this->exactly(2))
->method('captureCheckIn')
->with(
$this->callback(function (string $slug): bool {
$this->callback(static function (string $slug): bool {
return $slug === 'test-crontab';
}),
$this->callback(function (CheckInStatus $checkInStatus): bool {
$this->callback(static function (CheckInStatus $checkInStatus): bool {
// just check for type CheckInStatus
return true;
}),
$this->anything(),
$this->callback(function (MonitorConfig $monitorConfig): bool {
$this->callback(static function (MonitorConfig $monitorConfig): bool {
return $monitorConfig->getSchedule()->getValue() === '*/5 * * * *'
&& $monitorConfig->getSchedule()->getType() === MonitorSchedule::TYPE_CRONTAB
&& $monitorConfig->getCheckinMargin() === 5
Expand All @@ -280,7 +280,7 @@ public function testWithMonitorCallableThrows(): void

SentrySdk::setCurrentHub($hub);

withMonitor('test-crontab', function () {
withMonitor('test-crontab', static function () {
throw new \Exception();
}, new MonitorConfig(
new MonitorSchedule(MonitorSchedule::TYPE_CRONTAB, '*/5 * * * *'),
Expand Down Expand Up @@ -352,7 +352,7 @@ public function testTraceReturnsClosureResult(): void
{
$returnValue = 'foo';

$result = trace(function () use ($returnValue) {
$result = trace(static function () use ($returnValue) {
return $returnValue;
}, new SpanContext());

Expand All @@ -379,7 +379,7 @@ public function testTraceCorrectlyReplacesAndRestoresCurrentSpan(): void
$this->assertSame($transaction, $hub->getSpan());

try {
trace(function () {
trace(static function () {
throw new \RuntimeException('Throwing should still restore the previous span');
}, new SpanContext());
} catch (\RuntimeException $e) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Logs/LogsAggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function testAttributesAreAddedToLogMessage(): void
$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);

$hub->configureScope(function (Scope $scope) {
$hub->configureScope(static function (Scope $scope) {
$userDataBag = new UserDataBag();
$userDataBag->setId('unique_id');
$userDataBag->setEmail('foo@example.com');
Expand Down
2 changes: 1 addition & 1 deletion tests/Logs/LogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function assertEvent(callable $assert, array $options = []): ClientInter
$transport = $this->createMock(TransportInterface::class);
$transport->expects($this->once())
->method('send')
->with($this->callback(function (Event $event) use ($assert): bool {
->with($this->callback(static function (Event $event) use ($assert): bool {
$assert($event);

return true;
Expand Down
Loading
Loading