Skip to content

Commit

Permalink
change nullable cs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Jan 14, 2025
1 parent 2d78e99 commit 6a16e90
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
9 changes: 7 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php

/*
* This file is part of the worldia/instrumentation-bundle package.
* (c) Worldia <[email protected]>
*/

require_once 'vendor/autoload.php';

return CodingStandards\Factory::createPhpCsFixerConfig(__DIR__, [
'rules' => [
'nullable_type_declaration' => ['syntax' => 'union']
]
'nullable_type_declaration' => ['syntax' => 'union'],
],
]);
4 changes: 2 additions & 2 deletions example/src/Controller/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ private function getExtraOptions(): array
return [
'propagate' => false,
'operation_name' => 'http.get timeapi.io-time',
'on_request' => function (array $headers, string|null $body, SpanInterface $span): void {
'on_request' => function (array $headers, $body, SpanInterface $span): void {
$span->setAttribute('request.headers', $headers);
},
'on_response' => function (array $headers, string|null $body, SpanInterface $span): void {
'on_response' => function (array $headers, $body, SpanInterface $span): void {
$span->setAttribute('response.headers', json_encode($headers));
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace spec\Instrumentation\Tracing\Request\EventListener;

use Instrumentation\Tracing\Bridge\MainSpanContextInterface;
use OpenTelemetry\API\Trace\SpanInterface;
use OpenTelemetry\SemConv\TraceAttributes;
use PhpSpec\ObjectBehavior;
Expand All @@ -34,16 +33,14 @@ public function it_should_add_user_if_authenticated(
SpanInterface $requestSpan,
TokenStorageInterface $tokenStorage,
UsernamePasswordToken $usernamePasswordToken,
MainSpanContextInterface $mainSpanContext,
UserInterface $user,
): void {
$user->getRoles()->willReturn(['ADMIN']);
$user->getUserIdentifier()->willReturn('David');
$usernamePasswordToken->getUser()->willReturn($user);
$tokenStorage->getToken()->willReturn($usernamePasswordToken);
$this->setupRequestSpan($requestSpan, $mainSpanContext);
$this->setupRequestSpan($requestSpan);
$this->beConstructedWith(
$mainSpanContext,
$tokenStorage
);
$mainRequestEvent = $this->createRequestEvent('/somewhere/{id}', Request::METHOD_PUT);
Expand All @@ -52,10 +49,9 @@ public function it_should_add_user_if_authenticated(
$requestSpan->setAttribute(TraceAttributes::USER_ROLES, ['ADMIN'])->shouldHaveBeenCalled();
}

private function setupRequestSpan(SpanInterface $requestSpan, MainSpanContextInterface $mainSpanContext)
private function setupRequestSpan(SpanInterface $requestSpan)
{
$requestSpan->setAttribute(Argument::cetera())->willReturn($requestSpan);
$mainSpanContext->getMainSpan()->willReturn($requestSpan);
}

private function createRequestEvent(
Expand Down
2 changes: 1 addition & 1 deletion src/Semantics/ResourceInfoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class ResourceInfoProvider implements ResourceInfoProviderInterface
{
private ?ResourceInfo $info = null;
private ResourceInfo|null $info = null;

/**
* @param array<string,string> $attributes
Expand Down
6 changes: 3 additions & 3 deletions src/Tracing/HttpClient/TracedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class TracedResponse implements ResponseInterface, StreamableInterface
{
private ?string $content = null;
private string|null $content = null;
/** @var resource|null */
private $stream;

Expand Down Expand Up @@ -88,7 +88,7 @@ public function cancel(): void
}
}

public function getInfo(?string $type = null): mixed
public function getInfo(string|null $type = null): mixed
{
return $this->response->getInfo($type);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public function toStream(bool $throw = true)
*
* @internal
*/
public static function stream(HttpClientInterface $client, iterable $responses, ?float $timeout): \Generator
public static function stream(HttpClientInterface $client, iterable $responses, float|null $timeout): \Generator
{
$wrappedResponses = [];
$traceableMap = new \SplObjectStorage();
Expand Down
6 changes: 2 additions & 4 deletions src/Tracing/HttpClient/TracingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ final class TracingHttpClient implements HttpClientInterface
* @param HttpClientInterface|array<mixed>|null $client
*/
public function __construct(
HttpClientInterface|array|null $client = null,
ClientRequestOperationNameResolverInterface|null $operationNameResolver = null,
ClientRequestAttributeProviderInterface|null $attributeProvider = null,
HttpClientInterface|array|null $client = null, ClientRequestOperationNameResolverInterface|null $operationNameResolver = null, ClientRequestAttributeProviderInterface|null $attributeProvider = null,
private readonly bool $propagateByDefault = true,
int $maxHostConnections = 6,
int $maxPendingPushes = 50,
Expand All @@ -66,7 +64,7 @@ public function __construct(
* operation_name: non-empty-string,
* propagate: bool,
* extra_attributes: array<non-empty-string, string>,
* on_request: callable(array<string,array<string>>, string|null, SpanInterface): void,
* on_request: callable(array<string,array<string>>, string|resource|null, SpanInterface): void,
* on_response: callable(array<string,array<string>>, string|resource|null, SpanInterface): void,
* }
* } $options
Expand Down
4 changes: 2 additions & 2 deletions src/Tracing/Request/EventListener/AddUserEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function getSubscribedEvents(): array
];
}

public function __construct(private readonly ?TokenStorageInterface $tokenStorage = null)
public function __construct(private readonly TokenStorageInterface|null $tokenStorage = null)
{
}

Expand Down Expand Up @@ -77,7 +77,7 @@ private function getRoles(UserInterface|\Stringable|string $user): array
return [];
}

private function getUsername(UserInterface|\Stringable|string $user): ?string
private function getUsername(UserInterface|\Stringable|string $user): string|null
{
if ($user instanceof UserInterface) {
if (method_exists($user, 'getUserIdentifier')) {
Expand Down

0 comments on commit 6a16e90

Please sign in to comment.