Skip to content

$level as nullable is deprecated, the explicit nullable type must be used instead in... #112

@barbanet

Description

@barbanet

https://github.com/minicli/minicli/blob/main/src/Logging/Logger.php#L38

    public function log(string $message, array $context = [], LogLevel $level = null): void
    {
        $level ??= $this->logLevel;

        $this->writeLog(sprintf(
            "[%s] %s: %s%s\n",
            date($this->timestampFormat),
            $level->value,
            $message,
            [] === $context ? '' : ' - '.json_encode($context)
        ));
    }

I found this issue when upgrading from PHP 8.3 to 8.4.
Changing the method to:

    public function log(string $message, array $context = [], ?LogLevel $level = null): void
    {
        $level ??= $this->logLevel;

        $this->writeLog(sprintf(
            "[%s] %s: %s%s\n",
            date($this->timestampFormat),
            $level->value,
            $message,
            [] === $context ? '' : ' - '.json_encode($context)
        ));
    }

Seems to be working.
In addition, you need to have updated dependencies defined in composer.json.

Is this a submittable change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions