diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1102d63d..bb51e01f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/composer.json b/composer.json index 607891141..c00da9591 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/HttpClient/HttpClient.php b/src/HttpClient/HttpClient.php index 2a373d930..fc0823373 100644 --- a/src/HttpClient/HttpClient.php +++ b/src/HttpClient/HttpClient.php @@ -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); }; diff --git a/src/Logs/LogsAggregator.php b/src/Logs/LogsAggregator.php index e2fb5ea78..8d1ab7db4 100644 --- a/src/Logs/LogsAggregator.php +++ b/src/Logs/LogsAggregator.php @@ -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) { @@ -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(); }); diff --git a/src/Metrics/Metrics.php b/src/Metrics/Metrics.php index 936538e19..a45d7e6fc 100644 --- a/src/Metrics/Metrics.php +++ b/src/Metrics/Metrics.php @@ -109,7 +109,7 @@ public function timing( int $stackLevel = 0 ) { return trace( - function () use ($callback) { + static function () use ($callback) { return $callback(); }, SpanContext::make() diff --git a/src/Metrics/MetricsAggregator.php b/src/Metrics/MetricsAggregator.php index e18ca7ddf..a25df0b35 100644 --- a/src/Metrics/MetricsAggregator.php +++ b/src/Metrics/MetricsAggregator.php @@ -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) { @@ -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(); diff --git a/src/State/HubAdapter.php b/src/State/HubAdapter.php index 503153860..8e4343858 100644 --- a/src/State/HubAdapter.php +++ b/src/State/HubAdapter.php @@ -206,7 +206,7 @@ public function __clone() /** * @see https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup */ - public function __wakeup() + public function __unserialize(array $data) { throw new \BadMethodCallException('Unserializing instances of this class is forbidden.'); } @@ -214,7 +214,7 @@ public function __wakeup() /** * @see https://www.php.net/manual/en/language.oop5.magic.php#object.sleep */ - public function __sleep() + public function __serialize() { throw new \BadMethodCallException('Serializing instances of this class is forbidden.'); } diff --git a/src/Tracing/Span.php b/src/Tracing/Span.php index 09fe62a20..f45050620 100644 --- a/src/Tracing/Span.php +++ b/src/Tracing/Span.php @@ -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, ]); diff --git a/src/functions.php b/src/functions.php index 36c7c8b50..a7412fce7 100644 --- a/src/functions.php +++ b/src/functions.php @@ -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. @@ -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(); }); @@ -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(); }); @@ -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); }); @@ -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); }); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index a6cf67c8b..fb8b51d61 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -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; diff --git a/tests/FrameBuilderTest.php b/tests/FrameBuilderTest.php index 667b85a18..ecb01f0e1 100644 --- a/tests/FrameBuilderTest.php +++ b/tests/FrameBuilderTest.php @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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 = []; diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 949f9fadd..07e0bd918 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -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 @@ -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 * * * *'), @@ -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 @@ -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 * * * *'), @@ -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()); @@ -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) { diff --git a/tests/Logs/LogsAggregatorTest.php b/tests/Logs/LogsAggregatorTest.php index 83a91e1da..89e175a70 100644 --- a/tests/Logs/LogsAggregatorTest.php +++ b/tests/Logs/LogsAggregatorTest.php @@ -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'); diff --git a/tests/Logs/LogsTest.php b/tests/Logs/LogsTest.php index 3aab97419..4dd361b56 100644 --- a/tests/Logs/LogsTest.php +++ b/tests/Logs/LogsTest.php @@ -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; diff --git a/tests/Serializer/AbstractSerializerTest.php b/tests/Serializer/AbstractSerializerTest.php index 36f753c73..89932ba1a 100644 --- a/tests/Serializer/AbstractSerializerTest.php +++ b/tests/Serializer/AbstractSerializerTest.php @@ -458,7 +458,7 @@ public function serializableCallableProvider(): array return [ [ - 'callable' => function (array $param1) { + 'callable' => static function (array $param1) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -466,7 +466,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [array param1]', ], [ - 'callable' => function ($param1a) { + 'callable' => static function ($param1a) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -474,7 +474,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [mixed|null param1a]', ], [ - 'callable' => function (callable $param1c) { + 'callable' => static function (callable $param1c) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -482,7 +482,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [callable param1c]', ], [ - 'callable' => function (\stdClass $param1d) { + 'callable' => static function (\stdClass $param1d) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -490,7 +490,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [stdClass param1d]', ], [ - 'callable' => function (?\stdClass $param1e = null) { + 'callable' => static function (?\stdClass $param1e = null) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -498,7 +498,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [stdClass|null [param1e]]', ], [ - 'callable' => function (array &$param1f) { + 'callable' => static function (array &$param1f) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -506,7 +506,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [array ¶m1f]', ], [ - 'callable' => function (?array &$param1g = null) { + 'callable' => static function (?array &$param1g = null) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -534,7 +534,7 @@ public function serializableCallableProvider(): array 'expected' => 'Callable void ' . SerializerTestObject::class . '::testy []', ], [ - 'callable' => function (int $param1_70a) { + 'callable' => static function (int $param1_70a) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -542,7 +542,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [int param1_70a]', ], [ - 'callable' => function (&$param): int { + 'callable' => static function (&$param): int { return (int) $param; }, 'expected' => $prettyClosureNames @@ -550,7 +550,7 @@ public function serializableCallableProvider(): array : 'Lambda int ' . __NAMESPACE__ . '\\{closure} [mixed|null ¶m]', ], [ - 'callable' => function (int $param): ?int { + 'callable' => static function (int $param): ?int { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -558,7 +558,7 @@ public function serializableCallableProvider(): array : 'Lambda int ' . __NAMESPACE__ . '\\{closure} [int param]', ], [ - 'callable' => function (?int $param1_70b) { + 'callable' => static function (?int $param1_70b) { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames @@ -566,7 +566,7 @@ public function serializableCallableProvider(): array : 'Lambda ' . __NAMESPACE__ . '\\{closure} [int|null param1_70b]', ], [ - 'callable' => function (?int $param1_70c): void { + 'callable' => static function (?int $param1_70c): void { throw new \Exception('Don\'t even think about invoke me'); }, 'expected' => $prettyClosureNames diff --git a/tests/State/HubTest.php b/tests/State/HubTest.php index bb735cb96..0fb31e2cd 100644 --- a/tests/State/HubTest.php +++ b/tests/State/HubTest.php @@ -240,7 +240,7 @@ public function testCaptureMessage(array $functionCallArgs, array $expectedFunct $eventId = EventId::generate(); $hub = new Hub(); - $hub->configureScope(function (Scope $scope) use ($propagationContext): void { + $hub->configureScope(static function (Scope $scope) use ($propagationContext): void { $scope->setPropagationContext($propagationContext); }); @@ -299,7 +299,7 @@ public function testCaptureException(array $functionCallArgs, array $expectedFun $eventId = EventId::generate(); $hub = new Hub(); - $hub->configureScope(function (Scope $scope) use ($propagationContext): void { + $hub->configureScope(static function (Scope $scope) use ($propagationContext): void { $scope->setPropagationContext($propagationContext); }); @@ -354,7 +354,7 @@ public function testCaptureLastError(array $functionCallArgs, array $expectedFun $eventId = EventId::generate(); $hub = new Hub(); - $hub->configureScope(function (Scope $scope) use ($propagationContext): void { + $hub->configureScope(static function (Scope $scope) use ($propagationContext): void { $scope->setPropagationContext($propagationContext); }); @@ -813,7 +813,7 @@ public function testStartTransactionUpdatesTheDscSampleRate(): void $client->expects($this->once()) ->method('getOptions') ->willReturn(new Options([ - 'traces_sampler' => function (SamplingContext $samplingContext): float { + 'traces_sampler' => static function (SamplingContext $samplingContext): float { return 1.0; }, ])); diff --git a/tests/State/ScopeTest.php b/tests/State/ScopeTest.php index 281cbadb9..f2d99db01 100644 --- a/tests/State/ScopeTest.php +++ b/tests/State/ScopeTest.php @@ -405,7 +405,7 @@ public function testAddEventProcessor(): void return null; }); - $scope->addEventProcessor(function () use (&$callback3Called) { + $scope->addEventProcessor(static function () use (&$callback3Called) { $callback3Called = true; return null; @@ -425,7 +425,7 @@ public function testEventProcessorReceivesTheEventAndEventHint(): void $processorCalled = false; $processorReceivedHint = null; - $scope->addEventProcessor(function (Event $eventArg, EventHint $hint) use (&$processorCalled, &$processorReceivedHint): ?Event { + $scope->addEventProcessor(static function (Event $eventArg, EventHint $hint) use (&$processorCalled, &$processorReceivedHint): ?Event { $processorCalled = true; $processorReceivedHint = $hint; diff --git a/tests/Transport/HttpTransportTest.php b/tests/Transport/HttpTransportTest.php index 1d34137ae..206261eb0 100644 --- a/tests/Transport/HttpTransportTest.php +++ b/tests/Transport/HttpTransportTest.php @@ -62,7 +62,7 @@ public function testSend(Response $response, ResultStatus $expectedResultStatus, $this->logger->expects($this->exactly(\count($messages))) ->method($level) ->with($this->logicalOr( - ...array_map(function (string $message) { + ...array_map(static function (string $message) { return new StringMatchesFormatDescription($message); }, $messages) ));