Skip to content

Commit

Permalink
chore(Styles): fix codestyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
landa-worldia authored and cdaguerre committed Sep 12, 2024
1 parent eb91a97 commit 68dc2b6
Show file tree
Hide file tree
Showing 29 changed files with 58 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AddUserEventSubscriberSpec extends ObjectBehavior
private HttpKernelInterface|Collaborator $kernel;

public function let(
HttpKernelInterface $kernel
HttpKernelInterface $kernel,
): void {
$this->kernel = $kernel;
}
Expand All @@ -35,7 +35,7 @@ public function it_should_add_user_if_authenticated(
TokenStorageInterface $tokenStorage,
UsernamePasswordToken $usernamePasswordToken,
MainSpanContextInterface $mainSpanContext,
UserInterface $user
UserInterface $user,
): void {
$user->getRoles()->willReturn(['ADMIN']);
$user->getUserIdentifier()->willReturn('David');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TracingHandlerSpec extends ObjectBehavior
{
public function it_adds_event_from_all_channels(
MainSpanContextInterface $mainSpanContext,
SpanInterface $span
SpanInterface $span,
): void {
$this->beConstructedWith($mainSpanContext, Level::Info, []);

Expand All @@ -35,7 +35,7 @@ public function it_adds_event_from_all_channels(

public function it_adds_event_from_specific_channel_only(
MainSpanContextInterface $mainSpanContext,
SpanInterface $span
SpanInterface $span,
): void {
$this->beConstructedWith($mainSpanContext, Level::Info, ['foo']);

Expand All @@ -51,7 +51,7 @@ public function it_adds_event_from_specific_channel_only(

public function it_ignores_event_from_specific_channel(
MainSpanContextInterface $mainSpanContext,
SpanInterface $span
SpanInterface $span,
): void {
$this->beConstructedWith($mainSpanContext, Level::Info, ['!foo']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function it_gets_controller_and_route(ResourceInfo $info, AttributesInter
private function getMinimalInfo(): array
{
return [
'db_driver' => sprintf('doctrine/dbal-%s', InstalledVersions::getVersion('doctrine/dbal')),
'framework' => sprintf('symfony-%s', Kernel::VERSION),
'db_driver' => \sprintf('doctrine/dbal-%s', InstalledVersions::getVersion('doctrine/dbal')),
'framework' => \sprintf('symfony-%s', Kernel::VERSION),
];
}
}
11 changes: 7 additions & 4 deletions src/Bridge/GoogleCloud/Logging/Formatter/StdOutFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ protected function normalize(mixed $data, int $depth = 0): mixed
$data['severity'] = $data['level_name'];
unset($data['level_name']);

// Map channel
$data['logging.googleapis.com/labels'] = ['channel' => $data['channel']];
unset($data['channel']);

// Map tracing
if (!isset($data['context']) || !\is_array($data['context'])) {
return $data;
}
if (isset($data['context']['trace'])) {
$data['logging.googleapis.com/trace'] = 'projects/'.$this->project.'/traces/'.$data['context']['trace'];
}
Expand All @@ -60,10 +67,6 @@ protected function normalize(mixed $data, int $depth = 0): mixed
}
unset($data['context']['trace'], $data['context']['span'], $data['context']['sampled'], $data['context']['operation']);

// Map channel
$data['logging.googleapis.com/labels'] = ['channel' => $data['channel']];
unset($data['channel']);

if ($exception = $data['context']['exception'] ?? false) {
$data['message'] = $exception['message'];
$data['context'] = array_merge($data['context'], $exception['context']);
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarPrototype()->end()
->beforeNormalization()
->ifTrue(fn ($v) => !isset($v[ResourceAttributes::SERVICE_NAME]))
->thenInvalid(sprintf('You must provide the "%s" attribute in resource info.', ResourceAttributes::SERVICE_NAME))
->thenInvalid(\sprintf('You must provide the "%s" attribute in resource info.', ResourceAttributes::SERVICE_NAME))
->end()
->end()

Expand Down Expand Up @@ -91,7 +91,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->enumNode('level')
->defaultValue(Level::Info)
->values(Level::cases())
->info(sprintf('One of the %s levels.', Level::class))
->info(\sprintf('One of the %s levels.', Level::class))
->end()
->arrayNode('channels')
->defaultValue([])
Expand Down
12 changes: 6 additions & 6 deletions src/DependencyInjection/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function process(ContainerBuilder $container): void

foreach ($providedMetrics as $name => $metric) {
if (isset($metrics[$name])) {
throw new \RuntimeException(sprintf('A metric named %s is already registered.', $name));
throw new \RuntimeException(\sprintf('A metric named %s is already registered.', $name));
}
$metrics[$name] = $metric;
}
Expand All @@ -133,13 +133,13 @@ public function process(ContainerBuilder $container): void
}

foreach ($connectionsToTrace as $connection) {
$serviceId = sprintf('doctrine.dbal.%s_connection', $connection);
$serviceId = \sprintf('doctrine.dbal.%s_connection', $connection);

if (!\in_array($serviceId, $connections, true)) {
throw new \InvalidArgumentException(sprintf('No such connection: "%s".', $connection));
throw new \InvalidArgumentException(\sprintf('No such connection: "%s".', $connection));
}

$configDef = $container->getDefinition(sprintf('%s.configuration', $serviceId));
$configDef = $container->getDefinition(\sprintf('%s.configuration', $serviceId));

$middlewares = [];
foreach ($configDef->getMethodCalls() as $call) {
Expand Down Expand Up @@ -252,7 +252,7 @@ protected function loadTracing(array $config, ContainerBuilder $container): void

foreach (['blacklist', 'methods'] as $property) {
if (isset($config[$feature][$property])) {
$container->setParameter(sprintf('tracing.%s.%s', $feature, $property), $config[$feature][$property]);
$container->setParameter(\sprintf('tracing.%s.%s', $feature, $property), $config[$feature][$property]);
}
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ protected function loadLogging(array $config, ContainerBuilder $container): void
}

foreach ($config['handlers'] as $handler) {
if ($container->hasDefinition(sprintf('monolog.handler.%s', $handler))) {
if ($container->hasDefinition(\sprintf('monolog.handler.%s', $handler))) {
$container->getDefinition(\Instrumentation\Logging\Processor\TraceContextProcessor::class)
->addTag('monolog.processor', ['handler' => $handler]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/HttpMessageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function formatHeadersForSpanAttribute(array $headers): string
$lines = [];
foreach ($headers as $name => $values) {
foreach ($values as $value) {
$lines[] = sprintf('%s: %s', mb_strtolower($name), $value);
$lines[] = \sprintf('%s: %s', mb_strtolower($name), $value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Http/TracedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TracedResponse implements ResponseInterface, StreamableInterface

public function __construct(
private ResponseInterface $response,
private SpanInterface $span
private SpanInterface $span,
) {
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public static function stream(HttpClientInterface $client, iterable $responses,

foreach ($responses as $r) {
if (!$r instanceof self) {
throw new \TypeError(sprintf('"%s::stream()" expects parameter 1 to be an iterable of TracedResponse objects, "%s" given.', TracingHttpClient::class, get_debug_type($r)));
throw new \TypeError(\sprintf('"%s::stream()" expects parameter 1 to be an iterable of TracedResponse objects, "%s" given.', TracingHttpClient::class, get_debug_type($r)));
}

$traceableMap[$r->response] = $r;
Expand Down
4 changes: 2 additions & 2 deletions src/Http/TracingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
ClientRequestOperationNameResolverInterface|null $operationNameResolver = null,
ClientRequestAttributeProviderInterface|null $attributeProvider = null,
int $maxHostConnections = 6,
int $maxPendingPushes = 50
int $maxPendingPushes = 50,
) {
if (null === $client) {
$this->client = HttpClient::create([], $maxHostConnections, $maxPendingPushes);
Expand Down Expand Up @@ -70,7 +70,7 @@ protected function getExtraSpanAttributes(array|null $attributes): array
}

if (!\is_array($attributes)) {
throw new \RuntimeException(sprintf('Extra span attributes must be a comma separated list of attributes or an array. %s given.', get_debug_type($attributes)));
throw new \RuntimeException(\sprintf('Extra span attributes must be a comma separated list of attributes or an array. %s given.', get_debug_type($attributes)));
}

return $attributes;
Expand Down
4 changes: 4 additions & 0 deletions src/Metrics/CounterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function __construct(
*/
public function add($amount, iterable $attributes = [], $context = null): void
{
if (!\is_array($attributes)) {
return;
}

/** @var array<string> $labelNames */
$labelNames = array_keys($attributes['labels'] ?? []);
$labelValues = array_values($attributes['labels'] ?? []);
Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/EventSubscriber/RequestEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function onTerminate(Event\TerminateEvent $event): void
}

$time = microtime(true) - $event->getRequest()->server->get('REQUEST_TIME_FLOAT');
$code = sprintf('%sxx', substr((string) $event->getResponse()->getStatusCode(), 0, 1));
$code = \sprintf('%sxx', substr((string) $event->getResponse()->getStatusCode(), 0, 1));
$operation = $this->mainSpanContext?->getOperationName() ?: 'unknown';

$this->registry->getGauge('requests_handling')->dec();
Expand Down
3 changes: 3 additions & 0 deletions src/Metrics/HistogramAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function __construct(
*/
public function record($amount, iterable $attributes = [], $context = null): void
{
if (!\is_array($attributes)) {
return;
}
/** @var array<string> $labelNames */
$labelNames = array_keys($attributes['labels'] ?? []);
$labelValues = array_values($attributes['labels'] ?? []);
Expand Down
10 changes: 5 additions & 5 deletions src/Metrics/Meter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function createCounter(string $name, string|null $unit = null, string|nul
*/
public function createObservableCounter(string $name, string|null $unit = null, string|null $description = null, $advisory = [], callable ...$callbacks): ObservableCounterInterface
{
throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__));
throw new \LogicException(\sprintf('Method %s is not implemented', __METHOD__));
}

/**
Expand Down Expand Up @@ -95,7 +95,7 @@ public function createHistogram(string $name, string|null $unit = null, string|n
*/
public function createObservableGauge(string $name, string|null $unit = null, string|null $description = null, $advisory = [], callable ...$callbacks): ObservableGaugeInterface
{
throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__));
throw new \LogicException(\sprintf('Method %s is not implemented', __METHOD__));
}

/**
Expand Down Expand Up @@ -131,14 +131,14 @@ public function createUpDownCounter(string $name, string|null $unit = null, stri
*/
public function createObservableUpDownCounter(string $name, string|null $unit = null, string|null $description = null, $advisory = [], callable ...$callbacks): ObservableUpDownCounterInterface
{
throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__));
throw new \LogicException(\sprintf('Method %s is not implemented', __METHOD__));
}

public function batchObserve(
callable $callback,
AsynchronousInstrument $instrument,
AsynchronousInstrument ...$instruments
AsynchronousInstrument ...$instruments,
): ObservableCallbackInterface {
throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__));
throw new \LogicException(\sprintf('Method %s is not implemented', __METHOD__));
}
}
2 changes: 1 addition & 1 deletion src/Metrics/MetricDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
private string $type,
private string $help,
private array $labels = [],
private array|null $buckets = null
private array|null $buckets = null,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function getMetric(string $name): MetricDefinition
{
if (!isset($this->instantiated[$name])) {
if (!isset($this->metrics[$name])) {
throw new \InvalidArgumentException(sprintf('No metric registered with that name: "%s".', $name));
throw new \InvalidArgumentException(\sprintf('No metric registered with that name: "%s".', $name));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Metrics/UpDownCounterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function __construct(
*/
public function add($amount, iterable $attributes = [], $context = null): void
{
if (!\is_array($attributes)) {
return;
}
/** @var array<string> $labelNames */
$labelNames = array_keys($attributes['labels'] ?? []);
$labelValues = array_values($attributes['labels'] ?? []);
Expand Down
2 changes: 1 addition & 1 deletion src/Semantics/Attribute/ClientRequestAttributeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getAttributes(string $method, string $url, array $headers = []):
$headers[$header] = implode(',', $headers[$header]);
}

$attributes[sprintf('http.request.header.%s', str_replace('-', '_', $header))] = $headers[$header];
$attributes[\sprintf('http.request.header.%s', str_replace('-', '_', $header))] = $headers[$header];
}

$components = parse_url($url);
Expand Down
2 changes: 1 addition & 1 deletion src/Semantics/Attribute/ServerRequestAttributeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getAttributes(Request $request): array
}

foreach ($this->capturedHeaders as $header) {
$attributes[sprintf('http.response.header.%s', str_replace('-', '_', $header))] = [(string) $request->headers->get($header, '')];
$attributes[\sprintf('http.response.header.%s', str_replace('-', '_', $header))] = [(string) $request->headers->get($header, '')];
}

return array_filter($attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public function getOperationName(string $method, string $url): string
{
$url = parse_url($url);

return sprintf('http.%s %s://%s', strtolower($method), $url['scheme'] ?? 'http', $url['host'] ?? 'unknown');
return \sprintf('http.%s %s://%s', strtolower($method), $url['scheme'] ?? 'http', $url['host'] ?? 'unknown');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function getOperationName(Command|null $command): string
$name = $command->getName() ?: $command->getDefaultName();
}

return sprintf('cli %s', $name);
return \sprintf('cli %s', $name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function getOperationName(Envelope $envelope, string $operation): string
$name = $stamp->getOperationName();
}

return sprintf('message.%s %s', $name, $operation);
return \sprintf('message.%s %s', $name, $operation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function getOperationName(Request $request): string
$routeName = $request->getPathInfo();
}

return sprintf('http.%s %s', strtolower($request->getMethod()), $routeName);
return \sprintf('http.%s %s', strtolower($request->getMethod()), $routeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function getOperationName(Request $request): string
$path = $request->getPathInfo();
}

return sprintf('http.%s %s', strtolower($request->getMethod()), $path);
return \sprintf('http.%s %s', strtolower($request->getMethod()), $path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getSubscribedEvents(): array
public function __construct(
protected TracerProviderInterface $tracerProvider,
protected MainSpanContextInterface $mainSpanContext,
protected CommandOperationNameResolverInterface $operationNameResolver
protected CommandOperationNameResolverInterface $operationNameResolver,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function onRouteResolved(Event\RequestEvent $event): void

$span = $this->getSpanForRequest($request);

$span->updateName(sprintf('sf.controller.%s', $event->isMainRequest() ? 'main' : 'sub'));
$span->updateName(\sprintf('sf.controller.%s', $event->isMainRequest() ? 'main' : 'sub'));
$span->setAttribute('sf.controller', $controller);

if ($event->isMainRequest()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/Instrumentation/LogHandler/TracingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function write(LogRecord $record): void
$span = match ($this->strategy) {
self::STRATEGY_MAIN_SPAN => $this->mainSpanContext->getMainSpan(),
self::STRATEGY_CURRENT_SPAN => Span::getCurrent(),
default => throw new \InvalidArgumentException(sprintf('Unkown strategy "%s".', $this->strategy))
default => throw new \InvalidArgumentException(\sprintf('Unkown strategy "%s".', $this->strategy)),
};

if (isset($record->context['exception']) && $record->context['exception'] instanceof \Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getTraceContext(): array
$info['framework'] = 'symfony-'.Kernel::VERSION;

try {
$info['db_driver'] = sprintf('doctrine/dbal-%s', InstalledVersions::getVersion('doctrine/dbal'));
$info['db_driver'] = \sprintf('doctrine/dbal-%s', InstalledVersions::getVersion('doctrine/dbal'));
} catch (\Exception) {
// Ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function onRequest(Event\RequestEvent $event): void
$sampled = $this->incomingTraceResolver->isSampled($request);

if (null !== $traceId && null !== $spanId && null !== $sampled) {
$w3cHeader = sprintf('00-%s-%s-%s', $traceId, $spanId, $sampled ? '01' : '00');
$w3cHeader = \sprintf('00-%s-%s-%s', $traceId, $spanId, $sampled ? '01' : '00');
ContextInitializer::fromW3CHeader($w3cHeader);

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class PropagationStrategyStamp implements StampInterface
public function __construct(private string $strategy)
{
if (!\in_array($strategy, [self::STRATEGY_LINK, self::STRATEGY_PARENT])) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid value for strategy', $strategy));
throw new \InvalidArgumentException(\sprintf('"%s" is not a valid value for strategy', $strategy));
}
}

Expand Down

0 comments on commit 68dc2b6

Please sign in to comment.