JsonDecodeTrait.php

Code Hygiene Score: 100

Keine Issues gefunden.

Klassen 1

Funktionen 1

Verwendet von 14

Versionen 1

Code

<?php

declare(strict_types=1);

namespace Infrastructure\Traits;

// @responsibility: Sichere JSON-Dekodierung mit Fallback auf leeres Array

trait JsonDecodeTrait
{
    /**
     * Decode JSON string to array with safe defaults.
     *
     * @return array<mixed>
     */
    protected function decodeJsonArray(?string $json): array
    {
        if ($json === null || $json === '') {
            return [];
        }

        $decoded = json_decode($json, true);

        return is_array($decoded) ? $decoded : [];
    }
}
← Übersicht Graph