henzeb/enumhancer

View on GitHub
src/Concerns/ConfigureDefaults.php

Summary

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

namespace Henzeb\Enumhancer\Concerns;

use Henzeb\Enumhancer\Helpers\EnumProperties;
use Henzeb\Enumhancer\Exceptions\ReservedPropertyNameException;
use Henzeb\Enumhancer\Exceptions\PropertyAlreadyStoredException;

trait ConfigureDefaults
{
    /**
     * @throws ReservedPropertyNameException|PropertyAlreadyStoredException
     */
    public static function setDefault(?self $default): void
    {
        $reservedWord = EnumProperties::reservedWord('defaults');

        EnumProperties::store(
            self::class,
            $reservedWord,
            $default,
            true
        );
    }

    /**
     * @throws ReservedPropertyNameException|PropertyAlreadyStoredException
     */
    public static function setDefaultOnce(self $default): void
    {
        $reservedWord = EnumProperties::reservedWord('defaults');

        EnumProperties::storeOnce(
            self::class,
            $reservedWord,
            $default,
            true
        );
    }
}