Skip to content

Commit

Permalink
Replace implicitly nullable parameters for PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JeppeKnockaert committed Dec 3, 2024
1 parent c1cde2d commit 785a5dd
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion appsec/run-tests-internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3403,7 +3403,7 @@ function show_result(
$tested,
$tested_file,
$extra = '',
array $temp_filenames = null
?array $temp_filenames = null
) {
global $SHOW_ONLY_GROUPS, $colorize;

Expand Down
2 changes: 1 addition & 1 deletion src/DDTrace/Integrations/AMQP/AMQPIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public function setGenericTags(
SpanData $span,
string $name,
string $spanKind,
string $resourceDetail = null,
?string $resourceDetail = null,
$exception = null
) {
$span->name = "amqp.$name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CodeIgniterIntegration extends Integration
/**
* Add instrumentation to CodeIgniter requests
*/
public function init(\CI_Router $router = null): int
public function init(?\CI_Router $router = null): int
{
$integration = $this;
$rootSpan = \DDTrace\root_span();
Expand Down
18 changes: 9 additions & 9 deletions src/DDTrace/Integrations/Logs/LogsIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static function laminasLogLevelToString(int $logLevel, string $fallback):
}

public static function getPlaceholders(
string $traceIdSubstitute = null,
string $spanIdSubstitute = null
?string $traceIdSubstitute = null,
?string $spanIdSubstitute = null
): array {
$placeholders = [
'%dd.trace_id%' => 'dd.trace_id="' . ($traceIdSubstitute ?? logs_correlation_trace_id()) . '"',
Expand Down Expand Up @@ -84,8 +84,8 @@ public static function messageContainsPlaceholders(string $message): bool

public static function appendTraceIdentifiersToMessage(
string $message,
string $traceIdSubstitute = null,
string $spanIdSubstitute = null
?string $traceIdSubstitute = null,
?string $spanIdSubstitute = null
): string {
$placeholders = LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute);
LogsIntegration::replacePlaceholders($message, $placeholders);
Expand All @@ -108,9 +108,9 @@ public static function appendTraceIdentifiersToMessage(

public static function replacePlaceholders(
string $message,
array $placeholders = null,
string $traceIdSubstitute = null,
string $spanIdSubstitute = null
?array $placeholders = null,
?string $traceIdSubstitute = null,
?string $spanIdSubstitute = null
): string {
return strtr(
$message,
Expand All @@ -120,8 +120,8 @@ public static function replacePlaceholders(

public static function addTraceIdentifiersToContext(
array $context,
string $traceIdSubstitute = null,
string $spanIdSubstitute = null
?string $traceIdSubstitute = null,
?string $spanIdSubstitute = null
): array {
if (!isset($context['dd.trace_id'])) {
$context['dd.trace_id'] = $traceIdSubstitute ?? logs_correlation_trace_id();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function setCommonTags(
WordPressIntegration $integration,
SpanData $span,
string $name,
string $resource = null
?string $resource = null
) {
$span->name = $name;
$span->resource = $resource ?: $name;
Expand Down
10 changes: 5 additions & 5 deletions src/DDTrace/OpenTelemetry/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public function addLink(SpanContextInterface $context, iterable $attributes = []
/**
* @inheritDoc
*/
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null): SpanInterface
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null): SpanInterface
{
if (!$this->hasEnded()) {
$this->span->events[] = new SpanEvent(
Expand Down Expand Up @@ -427,7 +427,7 @@ public function updateName(string $name): SpanInterface
/**
* @inheritDoc
*/
public function setStatus(string $code, string $description = null): SpanInterface
public function setStatus(string $code, ?string $description = null): SpanInterface
{
if ($this->hasEnded()) {
return $this;
Expand Down Expand Up @@ -459,7 +459,7 @@ public function setStatus(string $code, string $description = null): SpanInterfa
/**
* @inheritDoc
*/
public function end(int $endEpochNanos = null): void
public function end(?int $endEpochNanos = null): void
{
if ($this->hasEnded()) {
return;
Expand All @@ -472,7 +472,7 @@ public function end(int $endEpochNanos = null): void
$this->spanProcessor->onEnd($this);
}

public function endOTelSpan(int $endEpochNanos = null): void
public function endOTelSpan(?int $endEpochNanos = null): void
{
if ($this->hasEnded()) {
return;
Expand Down Expand Up @@ -572,7 +572,7 @@ private function updateSpanEvents()
$this->totalRecordedEvents = count($otel);
}

private function createAndSaveSpanLink(SpanContextInterface $context, iterable $attributes = [], LinkInterface $link = null)
private function createAndSaveSpanLink(SpanContextInterface $context, iterable $attributes = [], ?LinkInterface $link = null)
{
$spanLink = new SpanLink();
$spanLink->traceId = $context->getTraceId();
Expand Down
2 changes: 1 addition & 1 deletion src/DDTrace/OpenTelemetry/SpanBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function addLink(SpanContextInterface $context, iterable $attributes = []
return $this;
}

public function addEvent(string $name, iterable $attributes = [], int $timestamp = null): SpanBuilderInterface
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null): SpanBuilderInterface
{
$this->events[] = new Event(
$name,
Expand Down
4 changes: 2 additions & 2 deletions src/DDTrace/OpenTracer/Tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Tracer implements OTTracer
/**
* @param TracerInterface|null $tracer
*/
public function __construct(TracerInterface $tracer = null)
public function __construct(?TracerInterface $tracer = null)
{
$this->tracer = $tracer ?: GlobalTracer::get();
}
Expand All @@ -39,7 +39,7 @@ public function __construct(TracerInterface $tracer = null)
* @param array $config
* @return self
*/
public static function make(Transport $transport = null, array $propagators = null, array $config = [])
public static function make(?Transport $transport = null, ?array $propagators = null, array $config = [])
{
return new self(
new DDTracer($transport, $propagators, $config)
Expand Down
4 changes: 2 additions & 2 deletions src/DDTrace/OpenTracer1/Tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class Tracer implements OTTracer
/**
* @param TracerInterface|null $tracer
*/
public function __construct(TracerInterface $tracer = null)
public function __construct(?TracerInterface $tracer = null)
{
$this->tracer = $tracer ?: GlobalTracer::get();
}
Expand All @@ -41,7 +41,7 @@ public function __construct(TracerInterface $tracer = null)
* @param array $config
* @return self
*/
public static function make(Transport $transport = null, array $propagators = null, array $config = [])
public static function make(?Transport $transport = null, ?array $propagators = null, array $config = [])
{
return new self(
new DDTracer($transport, $propagators, $config)
Expand Down
2 changes: 1 addition & 1 deletion src/DDTrace/ScopeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ScopeManager implements ScopeManagerInterface
*/
private $rootContext;

public function __construct(SpanContext $rootContext = null)
public function __construct(?SpanContext $rootContext = null)
{
$this->rootContext = $rootContext;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DDTrace/Tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class Tracer implements TracerInterface
* @param Propagator[] $propagators
* @param array $config
*/
public function __construct(Transport $transport = null, array $propagators = null, array $config = [])
public function __construct(?Transport $transport = null, ?array $propagators = null, array $config = [])
{
$this->transport = $transport ?: new Internal();
$textMapPropagator = new TextMap($this);
Expand Down
14 changes: 7 additions & 7 deletions src/ddtrace_php_api.stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function addLink(\OpenTelemetry\API\Trace\SpanContextInterface $context,
/**
* @inheritDoc
*/
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null) : \OpenTelemetry\API\Trace\SpanInterface
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null) : \OpenTelemetry\API\Trace\SpanInterface
{
}
/**
Expand All @@ -174,16 +174,16 @@ public function updateName(string $name) : \OpenTelemetry\API\Trace\SpanInterfac
/**
* @inheritDoc
*/
public function setStatus(string $code, string $description = null) : \OpenTelemetry\API\Trace\SpanInterface
public function setStatus(string $code, ?string $description = null) : \OpenTelemetry\API\Trace\SpanInterface
{
}
/**
* @inheritDoc
*/
public function end(int $endEpochNanos = null) : void
public function end(?int $endEpochNanos = null) : void
{
}
public function endOTelSpan(int $endEpochNanos = null) : void
public function endOTelSpan(?int $endEpochNanos = null) : void
{
}
public function getResource() : \OpenTelemetry\SDK\Resource\ResourceInfo
Expand Down Expand Up @@ -212,7 +212,7 @@ public function setParent($context) : \OpenTelemetry\API\Trace\SpanBuilderInterf
public function addLink(\OpenTelemetry\API\Trace\SpanContextInterface $context, iterable $attributes = []) : \OpenTelemetry\API\Trace\SpanBuilderInterface
{
}
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null) : \OpenTelemetry\API\Trace\SpanBuilderInterface
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null) : \OpenTelemetry\API\Trace\SpanBuilderInterface
{
}
public function recordException(\Throwable $exception, iterable $attributes = []) : \OpenTelemetry\API\Trace\SpanBuilderInterface
Expand Down Expand Up @@ -506,7 +506,7 @@ public function close();
namespace DDTrace {
final class ScopeManager implements \DDTrace\Contracts\ScopeManager
{
public function __construct(\DDTrace\SpanContext $rootContext = null)
public function __construct(?\DDTrace\SpanContext $rootContext = null)
{
}
/**
Expand Down Expand Up @@ -1341,7 +1341,7 @@ final class Tracer implements \DDTrace\Contracts\Tracer
* @param Propagator[] $propagators
* @param array $config
*/
public function __construct(\DDTrace\Transport $transport = null, array $propagators = null, array $config = [])
public function __construct(?\DDTrace\Transport $transport = null, ?array $propagators = null, array $config = [])
{
}
public function limited()
Expand Down
12 changes: 6 additions & 6 deletions tests/Common/TracerTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function resetRequestDumper()
* @return array[]
* @throws Exception
*/
public function tracesFromWebRequest($fn, $tracer = null, callable $until = null)
public function tracesFromWebRequest($fn, $tracer = null, ?callable $until = null)
{
self::putEnv('DD_TRACE_SHUTDOWN_TIMEOUT=666666'); // Arbitrarily high value to avoid flakiness
self::putEnv('DD_TRACE_AGENT_RETRIES=3');
Expand Down Expand Up @@ -384,7 +384,7 @@ private function parseRawDumpedSpans($rawSpans)
* @return array
* @throws \Exception
*/
private function parseTracesFromDumpedData(callable $until = null, $throw = false)
private function parseTracesFromDumpedData(?callable $until = null, $throw = false)
{
$loaded = $this->retrieveDumpedTraceData($until, $throw);
if (!$loaded) {
Expand Down Expand Up @@ -438,20 +438,20 @@ public function parseMultipleRequestsFromDumpedData()
/**
* Returns the raw response body, if any, or null otherwise.
*/
public function retrieveDumpedData(callable $until = null, $throw = false)
public function retrieveDumpedData(?callable $until = null, $throw = false)
{
return $this->retrieveAnyDumpedData($until, $throw);
}

/**
* Returns the raw response body, if any, or null otherwise.
*/
public function retrieveDumpedMetrics(callable $until = null, $throw = false)
public function retrieveDumpedMetrics(?callable $until = null, $throw = false)
{
return $this->retrieveAnyDumpedData($until, $throw, true);
}

public function retrieveAnyDumpedData(callable $until = null, $throw, $metrics = false) {
public function retrieveAnyDumpedData(?callable $until = null, $throw, $metrics = false) {
$until = $until ?? $this->untilFirstTraceRequest();

$allResponses = [];
Expand Down Expand Up @@ -493,7 +493,7 @@ public function retrieveAnyDumpedData(callable $until = null, $throw, $metrics =
return $allResponses;
}

public function retrieveDumpedTraceData(callable $until = null, $throw = false)
public function retrieveDumpedTraceData(?callable $until = null, $throw = false)
{
return array_values(array_filter($this->retrieveDumpedData($until, $throw), function ($request) {
// Filter telemetry requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract public function authorize($user, CakeRequest $request);
* @return mixed
* @throws CakeException
*/
public function controller(Controller $controller = null) {
public function controller(?Controller $controller = null) {
if ($controller) {
if (!$controller instanceof Controller) {
throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ControllerAuthorize extends BaseAuthorize {
* @return mixed
* @throws CakeException
*/
public function controller(Controller $controller = null) {
public function controller(?Controller $controller = null) {
if ($controller) {
if (!method_exists($controller, 'isAuthorized')) {
throw new CakeException(__d('cake_dev', '$controller does not implement an %s method.', 'isAuthorized()'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ protected function _setDefaults() {
* @param CakeRequest|null $request The request to authenticate for. If empty, the current request will be used.
* @return bool True if $user is authorized, otherwise false
*/
public function isAuthorized($user = null, CakeRequest $request = null) {
public function isAuthorized($user = null, ?CakeRequest $request = null) {
if (empty($user) && !$this->user()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class PrivateActionException extends CakeException {
protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';

//@codingStandardsIgnoreStart
public function __construct($message, $code = 404, Exception $previous = null) {
public function __construct($message, $code = 404, ?Exception $previous = null) {
parent::__construct($message, $code, $previous);
}
//@codingStandardsIgnoreEnd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ protected function _execute($sql, $params = array(), $prepareOptions = array())
* @param PDOStatement $query the query to extract the error from if any
* @return string Error message with error number
*/
public function lastError(PDOStatement $query = null) {
public function lastError(?PDOStatement $query = null) {
if ($query) {
$error = $query->errorInfo();
} else {
Expand Down Expand Up @@ -2639,7 +2639,7 @@ public function fields(Model $Model, $alias = null, $fields = array(), $quote =
* @param Model $Model A reference to the Model instance making the query
* @return string SQL fragment
*/
public function conditions($conditions, $quoteValues = true, $where = true, Model $Model = null) {
public function conditions($conditions, $quoteValues = true, $where = true, ?Model $Model = null) {
$clause = $out = '';

if ($where) {
Expand Down Expand Up @@ -2682,7 +2682,7 @@ public function conditions($conditions, $quoteValues = true, $where = true, Mode
* @param Model $Model A reference to the Model instance making the query
* @return string SQL fragment
*/
public function conditionKeysToString($conditions, $quoteValues = true, Model $Model = null) {
public function conditionKeysToString($conditions, $quoteValues = true, ?Model $Model = null) {
$out = array();
$data = $columnType = null;

Expand Down Expand Up @@ -2787,7 +2787,7 @@ public function conditionKeysToString($conditions, $quoteValues = true, Model $M
* @param Model $Model Model object initiating the query
* @return string
*/
protected function _parseKey($key, $value, Model $Model = null) {
protected function _parseKey($key, $value, ?Model $Model = null) {
$operatorMatch = '/^(((' . implode(')|(', $this->_sqlOps);
$operatorMatch .= ')\\x20?)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is';
$bound = (strpos($key, '?') !== false || (is_array($value) && strpos($key, ':') !== false));
Expand Down Expand Up @@ -2954,7 +2954,7 @@ public function limit($limit, $offset = null) {
* @param Model $Model Model reference (used to look for virtual field)
* @return string ORDER BY clause
*/
public function order($keys, $direction = 'ASC', Model $Model = null) {
public function order($keys, $direction = 'ASC', ?Model $Model = null) {
if (!is_array($keys)) {
$keys = array($keys);
}
Expand Down Expand Up @@ -3037,7 +3037,7 @@ public function order($keys, $direction = 'ASC', Model $Model = null) {
* @param Model $Model The model to get group by fields for.
* @return string Group By clause or null.
*/
public function group($fields, Model $Model = null) {
public function group($fields, ?Model $Model = null) {
if (empty($fields)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3886,7 +3886,7 @@ protected function _clearCache($type = null) {
* If null a new ModelValidator instance will be made using current model object
* @return ModelValidator
*/
public function validator(ModelValidator $instance = null) {
public function validator(?ModelValidator $instance = null) {
if ($instance) {
$this->_validator = $instance;
} elseif (!$this->_validator) {
Expand Down
Loading

0 comments on commit 785a5dd

Please sign in to comment.