Skip to content

Commit f60e987

Browse files
committed
optimized unique check + better exception message
1 parent 8d5d776 commit f60e987

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/MabeEnum/Enum.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,13 @@ final static public function getConstants()
179179
$constants = $reflection->getConstants();
180180

181181
// Constant values needs to be unique
182-
if (count($constants) > count(array_unique($constants))) {
183-
$ambiguous = array();
184-
foreach (array_count_values($constants) as $constValue => $countValue) {
185-
if ($countValue > 1) {
186-
$ambiguous[] = $constValue;
187-
}
188-
}
182+
if (max(array_count_values($constants)) > 1) {
183+
$ambiguous = array_map(function ($v) use ($constants) {
184+
return implode('/', array_keys($constants, $v)) . '=' . $v;
185+
}, array_unique(array_diff_assoc($constants, array_unique($constants))));
189186
throw new LogicException(sprintf(
190187
'All possible values needs to be unique. The following are ambiguous: %s',
191-
"'" . implode("', '", $ambiguous) . "'"
188+
implode(', ', $ambiguous)
192189
));
193190
}
194191

0 commit comments

Comments
 (0)