CoreFiles by mySites.guru
RgbPaletteEntry.php74 lines, 1,854 bytes, from Joomla_5.0.0-alpha1-Alpha-Full_Package.zip
Raw History Compare with 4.4.0-alpha4
md5
fe9206ac0386873e7aeb787632b08571
sha1
ea979c3caf1df64232f5c8cd999d77e50ab3c113
sha256
e17c1460fe8a5f245539a7a2053f95adc3e7e0f62bd9f98fe4b87508fd73332c
<?php

declare(strict_types=1);

namespace Webauthn\MetadataService\Statement;

use function array_key_exists;
use function is_int;
use JsonSerializable;
use Webauthn\MetadataService\Exception\MetadataStatementLoadingException;

class RgbPaletteEntry implements JsonSerializable
{
    private readonly int $r;

    private readonly int $g;

    private readonly int $b;

    public function __construct(int $r, int $g, int $b)
    {
        ($r >= 0 && $r <= 255) || throw MetadataStatementLoadingException::create('The key "r" is invalid');
        ($g >= 0 && $g <= 255) || throw MetadataStatementLoadingException::create('The key "g" is invalid');
        ($b >= 0 && $b <= 255) || throw MetadataStatementLoadingException::create('The key "b" is invalid');
        $this->r = $r;
        $this->g = $g;
        $this->b = $b;
    }

    public function getR(): int
    {
        return $this->r;
    }

    public function getG(): int
    {
        return $this->g;
    }

    public function getB(): int
    {
        return $this->b;
    }

    /**
     * @param array<string, mixed> $data
     */
    public static function createFromArray(array $data): self
    {
        foreach (['r', 'g', 'b'] as $key) {
            array_key_exists($key, $data) || throw MetadataStatementLoadingException::create(sprintf(
                'The key "%s" is missing',
                $key
            ));
            is_int($data[$key]) || throw MetadataStatementLoadingException::create(
                sprintf('The key "%s" is invalid', $key)
            );
        }

        return new self($data['r'], $data['g'], $data['b']);
    }

    /**
     * @return array<string, int>
     */
    public function jsonSerialize(): array
    {
        return [
            'r' => $this->r,
            'g' => $this->g,
            'b' => $this->b,
        ];
    }
}

The same content is in 6 releases, Joomla 5.0.0-alpha1 to 5.0.0-beta2. See them all, or every version of this file.