Confidence.php

Code Hygiene Score: 100

Keine Issues gefunden.

Dependencies 1

Klassen 1

Funktionen 10

Verwendet von 4

Versionen 2

Code

<?php

declare(strict_types=1);

namespace Domain\ValueObject;

// @responsibility: Konfidenzwert (0.0-1.0) für Taxonomie-Mappings

use Domain\Constants;

final class Confidence
{
    private float $value;

    public function __construct(float $value)
    {
        if ($value < 0.0 || $value > 1.0) {
            throw new \InvalidArgumentException(
                sprintf('Confidence must be between 0.0 and 1.0, got %f', $value)
            );
        }
        $this->value = $value;
    }

    public static function fromFloat(float $value): self
    {
        return new self($value);
    }

    public static function high(): self
    {
        return new self(0.9);
    }

    public static function medium(): self
    {
        return new self(0.7);
    }

    public static function low(): self
    {
        return new self(0.5);
    }

    public function value(): float
    {
        return $this->value;
    }

    public function isHigh(): bool
    {
        return $this->value >= 0.8;
    }

    public function isMedium(): bool
    {
        return $this->value >= 0.5 && $this->value < 0.8;
    }

    public function isLow(): bool
    {
        return $this->value < 0.5;
    }

    public function asPercentage(): int
    {
        return (int) round($this->value * Constants::PERCENT_FULL);
    }
}
← Übersicht Graph