henzeb/enumhancer

View on GitHub
src/Helpers/Bitmasks/Concerns/BitmaskValidators.php

Summary

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

namespace Henzeb\Enumhancer\Helpers\Bitmasks\Concerns;

use Henzeb\Enumhancer\Helpers\Bitmasks\EnumBitmasks;
use Henzeb\Enumhancer\Helpers\EnumCheck;

trait BitmaskValidators
{
    public function for(string $enumclass): bool
    {
        EnumCheck::check($enumclass);

        return $this->enumFQCN === $enumclass;
    }

    public function forOrFail(string $enumClass): bool
    {
        if ($this->for($enumClass)) {
            return true;
        }

        EnumBitmasks::throwMismatch(
            $this->forEnum(),
            $enumClass
        );
    }

    public function forEnum(): string
    {
        return $this->enumFQCN;
    }
}