diff --git a/analysis-baseline.toml b/analysis-baseline.toml index a75d873308..536037537a 100644 --- a/analysis-baseline.toml +++ b/analysis-baseline.toml @@ -750,6 +750,12 @@ code = "mixed-operand" message = "Left operand in `>=` comparison has `mixed` type." count = 2 +[[issues]] +file = "src/OpenTelemetry/Propagation/SentryPropagator.php" +code = "mixed-assignment" +message = "Assigning `mixed` type to a variable may lead to unexpected behavior." +count = 2 + [[issues]] file = "src/Options.php" code = "deprecated-method" @@ -1059,7 +1065,7 @@ count = 1 [[issues]] file = "src/Profiling/Profile.php" code = "invalid-return-statement" -message = '''Invalid return type for function `Sentry\Profiling\Profile::getFormattedData`: expected `array{'device': array{'architecture': string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': string}, 'platform': string, 'profile': array{'frames': array, 'samples': array, 'stacks': array>}, 'release': string, 'runtime': array{'name': string, 'version': string}, 'timestamp': string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': string, 'trace_id': string}, 'version': string}|null`, but found `array{'device': array{'architecture': null|string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': null|string}, 'platform': string('php'), 'profile': array{'frames': array{}|list, 'samples': array{}|non-empty-list, 'stacks': list>}, 'release': string, 'runtime': array{'name': string, 'sapi': null|string, 'version': null|string}, 'timestamp': non-empty-string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': null|string, 'trace_id': null|string}, 'version': string}`.''' +message = '''Invalid return type for function `Sentry\Profiling\Profile::getFormattedData`: expected `array{'device': array{'architecture': string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': string}, 'platform': string('php'), 'profile': array{'frames': array, 'samples': array, 'stacks': array>}, 'release': string, 'runtime': array{'name': string, 'version': string}, 'timestamp': string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': string, 'trace_id': string}, 'version': string}|null`, but found `array{'device': array{'architecture': null|string}, 'environment': string, 'event_id': string, 'os': array{'build_number': string, 'name': string, 'version': null|string}, 'platform': string('php'), 'profile': array{'frames': array{}|list, 'samples': array{}|non-empty-list, 'stacks': list>}, 'release': string, 'runtime': array{'name': string, 'sapi': null|string, 'version': null|string}, 'timestamp': non-empty-string, 'transaction': array{'active_thread_id': string, 'id': string, 'name': null|string, 'trace_id': null|string}, 'version': string}`.''' count = 1 [[issues]] diff --git a/src/Profiling/Profile.php b/src/Profiling/Profile.php index 3e88e9cf29..70bf5f972d 100644 --- a/src/Profiling/Profile.php +++ b/src/Profiling/Profile.php @@ -37,7 +37,7 @@ * version: string, * build_number: string, * }, - * platform: string, + * platform: 'php', * release: string, * environment: string, * runtime: array{ diff --git a/src/State/Scope.php b/src/State/Scope.php index 600e5857b5..ba7f4e3193 100644 --- a/src/State/Scope.php +++ b/src/State/Scope.php @@ -460,7 +460,7 @@ public function applyToEvent(Event $event, ?EventHint $hint = null, ?Options $op 'flag' => key($flag), 'result' => current($flag), ]; - }, $this->flags), + }, array_values($this->flags)), ]); } diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 7d712f6524..c42999c1a8 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -497,10 +497,10 @@ public function testTraceDoesntCreateSpanIfTransactionIsNotSampled(): void $transaction->setSampled(false); $scope->expects($this->never()) - ->method('setSpan'); + ->method('setSpan'); $scope->expects($this->exactly(3)) - ->method('getSpan') - ->willReturn($transaction); + ->method('getSpan') + ->willReturn($transaction); SentrySdk::setCurrentHub($hub); diff --git a/tests/State/ScopeTest.php b/tests/State/ScopeTest.php index 7ee6ff2c88..2d44d6e190 100644 --- a/tests/State/ScopeTest.php +++ b/tests/State/ScopeTest.php @@ -108,6 +108,31 @@ public function testSetFlag(): void ], $event->getContexts()['flags']); } + public function testSetFlagKeepsDuplicateFlagUpdatesSerializedAsList(): void + { + $scope = new Scope(); + + $scope->addFeatureFlag('feature-flag-1', true); + $scope->addFeatureFlag('feature-flag-2', false); + $scope->addFeatureFlag('feature-flag-1', false); + + $event = $scope->applyToEvent(Event::createEvent()); + + $this->assertNotNull($event); + $this->assertArrayHasKey('flags', $event->getContexts()); + $this->assertSame([ + [ + 'flag' => 'feature-flag-2', + 'result' => false, + ], + [ + 'flag' => 'feature-flag-1', + 'result' => false, + ], + ], $event->getContexts()['flags']['values']); + $this->assertSame('[{"flag":"feature-flag-2","result":false},{"flag":"feature-flag-1","result":false}]', json_encode($event->getContexts()['flags']['values'])); + } + public function testSetFlagLimit(): void { $scope = new Scope();