final private static function guardConstants(array $constants): void
    {
        $duplicates = [];
        foreach ($constants as $value) {
            $names = array_keys($constants, $value, $strict = true);
            if (count($names) > 1) {
                $duplicates[VarPrinter::toString($value)] = $names;
            }
        }
        if (!empty($duplicates)) {
            $list = array_map(function ($names) use ($constants) {
                return sprintf('(%s)=%s', implode('|', $names), VarPrinter::toString($constants[$names[0]]));
            }, $duplicates);
            $message = sprintf('Duplicate enum values: %s', implode(', ', $list));
            throw new DomainException($message);
        }
    }
final private static function guardConstants(array $constants): void
    {
        $duplicates = [];
        foreach ($constants as $value) {
            $names = array_keys($constants, $value, $strict = true);
            if (count($names) > 1) {
                $duplicates[VarPrinter::toString($value)] = $names;
            }
        }
        if (!empty($duplicates)) {
            $list = array_map(function ($names) use ($constants) {
                return sprintf('(%s)=%s', implode('|', $names), VarPrinter::toString($constants[$names[0]]));
            }, $duplicates);
            $message = sprintf('Duplicate enum values: %s', implode(', ', $list));
            throw new DomainException($message);
        }
    }
final private static function guardConstants ( array $ constants ) : void { $ duplicates = [ ] ; foreach ( $ constants as $ value ) { $ names = array_keys ( $ constants , $ value , $ strict = true ) ; if ( count ( $ names ) > 1 ) { $ duplicates [ VarPrinter :: toString ( $ value ) ] = $ names ; } } if ( ! empty ( $ duplicates ) ) { $ list = array_map ( function ( $ names ) use ( $ constants ) { return sprintf ( '(%s)=%s' , implode ( '|' , $ names ) , VarPrinter :: toString ( $ constants [ $ names [ 0 ] ] ) ) ; } , $ duplicates ) ; $ message = sprintf ( 'Duplicate enum values: %s' , implode ( ', ' , $ list ) ) ; throw new DomainException ( $ message ) ; } }
Validates enum constants

@param array $constants The enum constants

@return void

@throws DomainException When more than one constant has the same value
Validates enum constants