henzeb/enumhancer

View on GitHub
src/Concerns/From.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace Henzeb\Enumhancer\Concerns;

use Henzeb\Enumhancer\Helpers\EnumGetters;
use UnitEnum;

trait From
{
    /**
     * @param UnitEnum|string $key
     * @return self
     */
    public static function from(UnitEnum|string $key): self
    {
        return EnumGetters::get(static::class, $key, true, true);
    }

    public static function tryFrom(UnitEnum|string $key): ?self
    {
        return EnumGetters::tryGet(static::class, $key, true);
    }
}