<?php

declare(strict_types=1);

namespace PpPhp\Core\Diagnostics\Registry;

use PpPhp\Core\Diagnostics\Contracts\DiagnosticRuleInterface;

final class DiagnosticRuleRegistry
{
    /** @var array<string, DiagnosticRuleInterface> */
    private array $rules = [];

    public function register(DiagnosticRuleInterface $rule): void
    {
        $this->rules[$rule->id()] = $rule;
    }

    public function has(string $id): bool
    {
        return isset($this->rules[$id]);
    }

    public function get(string $id): ?DiagnosticRuleInterface
    {
        return $this->rules[$id] ?? null;
    }

    /** @return DiagnosticRuleInterface[] */
    public function all(): array
    {
        return array_values($this->rules);
    }
}
