Skip to content
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
3 changes: 3 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
parameters:
ignoreErrors:
-
message: "#.*#"
path: src/Util/DebugType.php
-
message: "#^Method Sentry\\\\Client\\:\\:getIntegration\\(\\) should return \\(T of Sentry\\\\Integration\\\\IntegrationInterface\\)\\|null but returns \\(T of Sentry\\\\Integration\\\\IntegrationInterface\\)\\|null\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/Util/DebugType.php" />
</ignoreFiles>
</projectFiles>

Expand Down
2 changes: 1 addition & 1 deletion src/CheckInStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* This enum represents all the possible status of a check in.
*/
final class CheckInStatus implements \Stringable
final class CheckInStatus
{
/**
* @var string The value of the enum instance
Expand Down
2 changes: 1 addition & 1 deletion src/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @author Stefano Arlandini <[email protected]>
*/
final class Dsn implements \Stringable
final class Dsn
{
/**
* @var string Regex to match the organization ID in the host.
Expand Down
3 changes: 2 additions & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Sentry\Logs\Log;
use Sentry\Profiling\Profile;
use Sentry\Tracing\Span;
use Sentry\Util\DebugType;

/**
* This is the base class for classes containing event data.
Expand Down Expand Up @@ -802,7 +803,7 @@ public function setExceptions(array $exceptions): self
{
foreach ($exceptions as $exception) {
if (!$exception instanceof ExceptionDataBag) {
throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, get_debug_type($exception)));
throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', ExceptionDataBag::class, DebugType::getDebugType($exception)));
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/EventHint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Sentry;

use Sentry\Util\DebugType;

/**
* This class represents hints on how to process an event.
*/
Expand Down Expand Up @@ -56,19 +58,19 @@ public static function fromArray(array $hintData): self
$extra = $hintData['extra'] ?? [];

if ($exception !== null && !$exception instanceof \Throwable) {
throw new \InvalidArgumentException(\sprintf('The value of the "exception" field must be an instance of a class implementing the "%s" interface. Got: "%s".', \Throwable::class, get_debug_type($exception)));
throw new \InvalidArgumentException(\sprintf('The value of the "exception" field must be an instance of a class implementing the "%s" interface. Got: "%s".', \Throwable::class, DebugType::getDebugType($exception)));
}

if ($mechanism !== null && !$mechanism instanceof ExceptionMechanism) {
throw new \InvalidArgumentException(\sprintf('The value of the "mechanism" field must be an instance of the "%s" class. Got: "%s".', ExceptionMechanism::class, get_debug_type($mechanism)));
throw new \InvalidArgumentException(\sprintf('The value of the "mechanism" field must be an instance of the "%s" class. Got: "%s".', ExceptionMechanism::class, DebugType::getDebugType($mechanism)));
}

if ($stacktrace !== null && !$stacktrace instanceof Stacktrace) {
throw new \InvalidArgumentException(\sprintf('The value of the "stacktrace" field must be an instance of the "%s" class. Got: "%s".', Stacktrace::class, get_debug_type($stacktrace)));
throw new \InvalidArgumentException(\sprintf('The value of the "stacktrace" field must be an instance of the "%s" class. Got: "%s".', Stacktrace::class, DebugType::getDebugType($stacktrace)));
}

if (!\is_array($extra)) {
throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', get_debug_type($extra)));
throw new \InvalidArgumentException(\sprintf('The value of the "extra" field must be an array. Got: "%s".', DebugType::getDebugType($extra)));
}

$hint->exception = $exception;
Expand Down
2 changes: 1 addition & 1 deletion src/EventId.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author Stefano Arlandini <[email protected]>
*/
final class EventId implements \Stringable
final class EventId
{
/**
* @var string The ID
Expand Down
2 changes: 1 addition & 1 deletion src/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @author Stefano Arlandini <[email protected]>
*/
final class EventType implements \Stringable
final class EventType
{
/**
* @var string The value of the enum instance
Expand Down
2 changes: 1 addition & 1 deletion src/FrameBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private function getFunctionArguments(array $backtraceFrame): array
} else {
$reflectionFunction = new \ReflectionMethod($backtraceFrame['class'], '__call');
}
} elseif ($backtraceFrame['function'] !== '__lambda_func' && !str_starts_with($backtraceFrame['function'], '{closure') && \function_exists($backtraceFrame['function'])) {
} elseif ($backtraceFrame['function'] !== '__lambda_func' && strpos($backtraceFrame['function'], '{closure') !== 0 && \function_exists($backtraceFrame['function'])) {
$reflectionFunction = new \ReflectionFunction($backtraceFrame['function']);
}
} catch (\ReflectionException $e) {
Expand Down
3 changes: 2 additions & 1 deletion src/Integration/IntegrationRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Psr\Log\LoggerInterface;
use Sentry\Options;
use Sentry\Util\DebugType;

/**
* @internal
Expand Down Expand Up @@ -123,7 +124,7 @@ private function getIntegrationsToSetup(Options $options): array
$integrations = $userIntegrations($defaultIntegrations);

if (!\is_array($integrations)) {
throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', get_debug_type($integrations)));
throw new \UnexpectedValueException(\sprintf('Expected the callback set for the "integrations" option to return a list of integrations. Got: "%s".', DebugType::getDebugType($integrations)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MonitorScheduleUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sentry;

final class MonitorScheduleUnit implements \Stringable
final class MonitorScheduleUnit
{
/**
* @var string The value of the enum instance
Expand Down
2 changes: 1 addition & 1 deletion src/Severity.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @author Stefano Arlandini <[email protected]>
*/
final class Severity implements \Stringable
final class Severity
{
/**
* This constant represents the "debug" severity level.
Expand Down
4 changes: 3 additions & 1 deletion src/Stacktrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Sentry;

use Sentry\Util\DebugType;

/**
* This class contains all the information about an error stacktrace.
*
Expand Down Expand Up @@ -31,7 +33,7 @@ public function __construct(array $frames)

foreach ($frames as $frame) {
if (!$frame instanceof Frame) {
throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, get_debug_type($frame)));
throw new \UnexpectedValueException(\sprintf('Expected an instance of the "%s" class. Got: "%s".', Frame::class, DebugType::getDebugType($frame)));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/State/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sentry\Tracing\Span;
use Sentry\Tracing\Transaction;
use Sentry\UserDataBag;
use Sentry\Util\DebugType;

/**
* The scope holds data that should implicitly be sent with Sentry events. It
Expand Down Expand Up @@ -208,7 +209,7 @@ public function getUser(): ?UserDataBag
public function setUser($user): self
{
if (!\is_array($user) && !$user instanceof UserDataBag) {
throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, get_debug_type($user)));
throw new \TypeError(\sprintf('The $user argument must be either an array or an instance of the "%s" class. Got: "%s".', UserDataBag::class, DebugType::getDebugType($user)));
}

if (\is_array($user)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/DynamicSamplingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static function fromHeader(string $header): self
$keyValueAndProperties = explode(';', $listMember, 2);
$keyValue = trim($keyValueAndProperties[0]);

if (!str_contains($keyValue, '=')) {
if (strpos($keyValue, '=') === false) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/SpanId.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* This class represents an span ID.
*/
final class SpanId implements \Stringable
final class SpanId
{
/**
* @var string The ID
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/SpanStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sentry\Tracing;

final class SpanStatus implements \Stringable
final class SpanStatus
{
/**
* @var string The value of the enum instance
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/TraceId.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* This class represents an trace ID.
*/
final class TraceId implements \Stringable
final class TraceId
{
/**
* @var string The ID
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/TransactionSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
*/
final class TransactionSource implements \Stringable
final class TransactionSource
{
/**
* @var string The value of the enum instance
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/ResultStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* This enum represents all possible reasons an event sending operation succeeded
* or failed.
*/
class ResultStatus implements \Stringable
class ResultStatus
{
/**
* @var string The value of the enum instance
Expand Down
4 changes: 3 additions & 1 deletion src/UserDataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Sentry;

use Sentry\Util\DebugType;

/**
* This class stores the information about the authenticated user for a request.
*
Expand Down Expand Up @@ -123,7 +125,7 @@ public function getId()
public function setId($id): self
{
if ($id !== null && !\is_string($id) && !\is_int($id)) {
throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', get_debug_type($id)));
throw new \UnexpectedValueException(\sprintf('Expected an integer or string value for the $id argument. Got: "%s".', DebugType::getDebugType($id)));
}

$this->id = $id;
Expand Down
74 changes: 74 additions & 0 deletions src/Util/DebugType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/*
* Original Code: https://github.com/symfony/polyfill/blob/1.x/src/Php80/Php80.php
*
* Copyright (c) 2015-present Fabien Potencier
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

declare(strict_types=1);

namespace Sentry\Util;

/**
* @internal
*/
final class DebugType
{
/**
* @param mixed $value
*/
public static function getDebugType($value): string
{
if (\function_exists('get_debug_type')) {
return get_debug_type($value);
}

switch (true) {
case $value === null: return 'null';
case \is_bool($value): return 'bool';
case \is_string($value): return 'string';
case \is_array($value): return 'array';
case \is_int($value): return 'int';
case \is_float($value): return 'float';
case \is_object($value): break;
case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class';
default:
if (null === $type = @get_resource_type($value)) {
return 'unknown';
}

if ($type === 'Unknown') {
$type = 'closed';
}

return "resource ($type)";
}

$class = \get_class($value);

if (strpos($class, '@') === false) {
return $class;
}

return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class') . '@anonymous';
}
}
2 changes: 1 addition & 1 deletion tests/Logs/LogsAggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testAttributes(array $attributes, array $expected): void
$log->attributes()->toSimpleArray(),
static function (string $key) {
// We are not testing internal Sentry attributes here, only the ones the user supplied
return !str_starts_with($key, 'sentry.');
return strpos($key, 'sentry.') !== 0;
},
\ARRAY_FILTER_USE_KEY
)
Expand Down
2 changes: 1 addition & 1 deletion tests/Monolog/LogsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testHandle($record, Log $expectedLog): void
$log->attributes()->toSimpleArray(),
static function (string $key) {
// We are not testing Sentry's own attributes here, only the ones the user supplied so filter them out of the expected attributes
return !str_starts_with($key, 'sentry.');
return strpos($key, 'sentry.') !== 0;
},
\ARRAY_FILTER_USE_KEY
)
Expand Down
Loading