Skip to content

Commit

Permalink
Update CS
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Oct 24, 2023
1 parent 002e2d4 commit 36a1dee
Show file tree
Hide file tree
Showing 31 changed files with 74 additions and 146 deletions.
4 changes: 3 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => true,
],
'phpdoc_no_useless_inheritdoc' => false,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
],
'phpdoc_to_comment' => false,
'phpdoc_align' => [
'tags' => ['param', 'return', 'throws', 'type', 'var'],
Expand Down
70 changes: 0 additions & 70 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ parameters:
count: 1
path: src/Client.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$hint$#"
count: 3
path: src/ClientInterface.php

-
message: "#^Offset 'host' does not exist on array\\{scheme\\: 'http'\\|'https', host\\?\\: string, port\\?\\: int\\<0, 65535\\>, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
count: 1
Expand Down Expand Up @@ -255,51 +250,6 @@ parameters:
count: 1
path: src/Serializer/AbstractSerializer.php

-
message: "#^Method Sentry\\\\ClientInterface\\:\\:captureException\\(\\) invoked with 3 parameters, 1\\-2 required\\.$#"
count: 1
path: src/State/Hub.php

-
message: "#^Method Sentry\\\\ClientInterface\\:\\:captureLastError\\(\\) invoked with 2 parameters, 0\\-1 required\\.$#"
count: 1
path: src/State/Hub.php

-
message: "#^Method Sentry\\\\ClientInterface\\:\\:captureMessage\\(\\) invoked with 4 parameters, 1\\-3 required\\.$#"
count: 1
path: src/State/Hub.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:captureException\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
path: src/State/HubAdapter.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:captureLastError\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: src/State/HubAdapter.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:captureMessage\\(\\) invoked with 3 parameters, 1\\-2 required\\.$#"
count: 1
path: src/State/HubAdapter.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:startTransaction\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
path: src/State/HubAdapter.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$customSamplingContext$#"
count: 1
path: src/State/HubInterface.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$hint$#"
count: 3
path: src/State/HubInterface.php

-
message: "#^Call to method getResponse\\(\\) on an unknown class GuzzleHttp\\\\Exception\\\\RequestException\\.$#"
count: 1
Expand Down Expand Up @@ -344,23 +294,3 @@ parameters:
message: "#^Method Sentry\\\\Util\\\\JSON\\:\\:encode\\(\\) should return string but returns string\\|false\\.$#"
count: 1
path: src/Util/JSON.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:captureException\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
path: src/functions.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:captureLastError\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: src/functions.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:captureMessage\\(\\) invoked with 3 parameters, 1\\-2 required\\.$#"
count: 1
path: src/functions.php

-
message: "#^Method Sentry\\\\State\\\\HubInterface\\:\\:startTransaction\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
path: src/functions.php
2 changes: 1 addition & 1 deletion src/CheckIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class CheckIn
public function __construct(
string $monitorSlug,
CheckInStatus $status,
string $id = null,
?string $id = null,
?string $release = null,
?string $environment = null,
$duration = null,
Expand Down
2 changes: 1 addition & 1 deletion src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class ClientBuilder
*
* @param Options|null $options The client options
*/
public function __construct(Options $options = null)
public function __construct(?Options $options = null)
{
$this->options = $options ?? new Options();

Expand Down
6 changes: 3 additions & 3 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getOptions(): Options;
* @param Scope|null $scope An optional scope keeping the state
* @param EventHint|null $hint Object that can contain additional information about the event
*/
public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null/*, ?EventHint $hint = null*/): ?EventId;
public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null, ?EventHint $hint = null): ?EventId;

/**
* Logs an exception.
Expand All @@ -40,15 +40,15 @@ public function captureMessage(string $message, ?Severity $level = null, ?Scope
* @param Scope|null $scope An optional scope keeping the state
* @param EventHint|null $hint Object that can contain additional information about the event
*/
public function captureException(\Throwable $exception, ?Scope $scope = null/*, ?EventHint $hint = null*/): ?EventId;
public function captureException(\Throwable $exception, ?Scope $scope = null, ?EventHint $hint = null): ?EventId;

/**
* Logs the most recent error (obtained with {@link error_get_last}).
*
* @param Scope|null $scope An optional scope keeping the state
* @param EventHint|null $hint Object that can contain additional information about the event
*/
public function captureLastError(?Scope $scope = null/*, ?EventHint $hint = null*/): ?EventId;
public function captureLastError(?Scope $scope = null, ?EventHint $hint = null): ?EventId;

/**
* Captures a new event using the provided data.
Expand Down
4 changes: 1 addition & 3 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static function createEvent(?EventId $eventId = null): self
*
* @param EventId|null $eventId The ID of the event
*/
public static function createTransaction(EventId $eventId = null): self
public static function createTransaction(?EventId $eventId = null): self
{
return new self($eventId, EventType::transaction());
}
Expand Down Expand Up @@ -260,8 +260,6 @@ public function setSdkVersion(string $sdkVersion): void

/**
* Gets the timestamp of when this event was generated.
*
* @return float
*/
public function getTimestamp(): ?float
{
Expand Down
2 changes: 1 addition & 1 deletion src/Integration/FrameContextifierIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function getSourceCodeExcerpt(int $maxContextLines, string $filePath, in
'post_context' => [],
];

$target = max(0, ($lineNumber - ($maxContextLines + 1)));
$target = max(0, $lineNumber - ($maxContextLines + 1));
$currentLineNumber = $target + 1;

try {
Expand Down
6 changes: 2 additions & 4 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(array $options = [])
*
* @deprecated since version 3.5, to be removed in 4.0
*/
public function getSendAttempts(/*bool $triggerDeprecation = true*/): int
public function getSendAttempts(/* bool $triggerDeprecation = true */): int
{
if (0 === \func_num_args() || false !== func_get_arg(0)) {
@trigger_error(sprintf('Method %s() is deprecated since version 3.5 and will be removed in 4.0.', __METHOD__), \E_USER_DEPRECATED);
Expand Down Expand Up @@ -343,7 +343,7 @@ public function setInAppIncludedPaths(array $paths): void
*
* @deprecated since version 3.2, to be removed in 4.0
*/
public function getLogger(/*bool $triggerDeprecation = true*/): string
public function getLogger(/* bool $triggerDeprecation = true */): string
{
if (0 === \func_num_args() || false !== func_get_arg(0)) {
@trigger_error(sprintf('Method %s() is deprecated since version 3.2 and will be removed in 4.0.', __METHOD__), \E_USER_DEPRECATED);
Expand All @@ -370,8 +370,6 @@ public function setLogger(string $logger): void

/**
* Gets the release tag to be passed with every event sent to Sentry.
*
* @return string
*/
public function getRelease(): ?string
{
Expand Down
3 changes: 0 additions & 3 deletions src/Profiling/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* module: string|null,
* lineno: int|null,
* }
*
* @phpstan-type SentryProfile array{
* device: array{
* architecture: string,
Expand Down Expand Up @@ -61,15 +60,13 @@
* stacks: array<int, array<int, int>>,
* },
* }
*
* @phpstan-type ExcimerLogStackEntryTrace array{
* file: string,
* line: int,
* class?: string,
* function?: string,
* closure_line?: int,
* }
*
* @phpstan-type ExcimerLogStackEntry array{
* trace: array<int, ExcimerLogStackEntryTrace>,
* timestamp: float
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/AbstractSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function serializeValue($value)
}
}

return 'Object ' . $reflection->getName() . (is_scalar($objectId) ? '(#' . $objectId . ')' : '');
return 'Object ' . $reflection->getName() . (\is_scalar($objectId) ? '(#' . $objectId . ')' : '');
}

if (\is_resource($value)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Serializer/PayloadSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ public function toArray(Event $event): array
* as a context into the payload.
*/
if (
EventType::event() === $event->getType() &&
!$this->options->isTracingEnabled()
EventType::event() === $event->getType()
&& !$this->options->isTracingEnabled()
) {
$dynamicSamplingContext = $event->getSdkMetadata('dynamic_sampling_context');
if ($dynamicSamplingContext instanceof DynamicSamplingContext) {
Expand Down
46 changes: 22 additions & 24 deletions src/Severity.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,32 @@ public function __construct(string $value = self::INFO)
* Translate a PHP Error constant into a Sentry log level group.
*
* @param int $severity PHP E_* error constant
*
* @return Severity
*/
public static function fromError(int $severity): self
{
switch ($severity) {
case \E_DEPRECATED:
case \E_USER_DEPRECATED:
case \E_WARNING:
case \E_USER_WARNING:
return self::warning();
case \E_ERROR:
case \E_PARSE:
case \E_CORE_ERROR:
case \E_CORE_WARNING:
case \E_COMPILE_ERROR:
case \E_COMPILE_WARNING:
return self::fatal();
case \E_RECOVERABLE_ERROR:
case \E_USER_ERROR:
return self::error();
case \E_NOTICE:
case \E_USER_NOTICE:
case \E_STRICT:
return self::info();
default:
return self::error();
}
case \E_DEPRECATED:
case \E_USER_DEPRECATED:
case \E_WARNING:
case \E_USER_WARNING:
return self::warning();
case \E_ERROR:
case \E_PARSE:
case \E_CORE_ERROR:
case \E_CORE_WARNING:
case \E_COMPILE_ERROR:
case \E_COMPILE_WARNING:
return self::fatal();
case \E_RECOVERABLE_ERROR:
case \E_USER_ERROR:
return self::error();
case \E_NOTICE:
case \E_USER_NOTICE:
case \E_STRICT:
return self::info();
default:
return self::error();
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/State/HubAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public function getIntegration(string $className): ?IntegrationInterface

/**
* {@inheritdoc}
*
* @param array<string, mixed> $customSamplingContext Additional context that will be passed to the {@see SamplingContext}
*/
public function startTransaction(TransactionContext $context, array $customSamplingContext = []): Transaction
{
Expand Down
8 changes: 4 additions & 4 deletions src/State/HubInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public function bindClient(ClientInterface $client): void;
* @param Severity|null $level The severity level of the message
* @param EventHint|null $hint Object that can contain additional information about the event
*/
public function captureMessage(string $message, ?Severity $level = null/*, ?EventHint $hint = null*/): ?EventId;
public function captureMessage(string $message, ?Severity $level = null, ?EventHint $hint = null): ?EventId;

/**
* Captures an exception event and sends it to Sentry.
*
* @param \Throwable $exception The exception
* @param EventHint|null $hint Object that can contain additional information about the event
*/
public function captureException(\Throwable $exception/*, ?EventHint $hint = null*/): ?EventId;
public function captureException(\Throwable $exception, ?EventHint $hint = null): ?EventId;

/**
* Captures a new event using the provided data.
Expand All @@ -114,7 +114,7 @@ public function captureEvent(Event $event, ?EventHint $hint = null): ?EventId;
*
* @param EventHint|null $hint Object that can contain additional information about the event
*/
public function captureLastError(/*?EventHint $hint = null*/): ?EventId;
public function captureLastError(?EventHint $hint = null): ?EventId;

/**
* Records a new breadcrumb which will be attached to future events. They
Expand Down Expand Up @@ -158,7 +158,7 @@ public function getIntegration(string $className): ?IntegrationInterface;
* @param TransactionContext $context Properties of the new transaction
* @param array<string, mixed> $customSamplingContext Additional context that will be passed to the {@see SamplingContext}
*/
public function startTransaction(TransactionContext $context/*, array $customSamplingContext = []*/): Transaction;
public function startTransaction(TransactionContext $context, array $customSamplingContext = []): Transaction;

/**
* Returns the transaction that is on the Hub.
Expand Down
2 changes: 1 addition & 1 deletion src/State/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class Scope
*/
private static $globalEventProcessors = [];

public function __construct(PropagationContext $propagationContext = null)
public function __construct(?PropagationContext $propagationContext = null)
{
$this->propagationContext = $propagationContext ?? PropagationContext::fromDefaults();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Tracing/GuzzleTracingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Sentry\Tracing;

use Closure;
use GuzzleHttp\Exception\RequestException as GuzzleRequestException;
use GuzzleHttp\Psr7\Uri;
use Psr\Http\Message\RequestInterface;
Expand All @@ -13,6 +12,7 @@
use Sentry\ClientInterface;
use Sentry\SentrySdk;
use Sentry\State\HubInterface;

use function Sentry\getBaggage;
use function Sentry\getTraceparent;

Expand All @@ -21,9 +21,9 @@
*/
final class GuzzleTracingMiddleware
{
public static function trace(?HubInterface $hub = null): Closure
public static function trace(?HubInterface $hub = null): \Closure
{
return static function (callable $handler) use ($hub): Closure {
return static function (callable $handler) use ($hub): \Closure {
return static function (RequestInterface $request, array $options) use ($hub, $handler) {
$hub = $hub ?? SentrySdk::getCurrentHub();
$client = $hub->getClient();
Expand Down Expand Up @@ -125,11 +125,11 @@ private static function shouldAttachTracingHeaders(?ClientInterface $client, Req

// Check if the request destination is allow listed in the trace_propagation_targets option.
if (
null !== $sdkOptions->getTracePropagationTargets() &&
null !== $sdkOptions->getTracePropagationTargets()
// Due to BC, we treat an empty array (the default) as all hosts are allow listed
(
[] === $sdkOptions->getTracePropagationTargets() ||
\in_array($request->getUri()->getHost(), $sdkOptions->getTracePropagationTargets())
&& (
[] === $sdkOptions->getTracePropagationTargets()
|| \in_array($request->getUri()->getHost(), $sdkOptions->getTracePropagationTargets())
)
) {
return true;
Expand Down
Loading

0 comments on commit 36a1dee

Please sign in to comment.