Skip to content

Commit 688f508

Browse files
committed
reduced code paths
1 parent 7c659da commit 688f508

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

src/Enum.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ final public static function getNames(): array
306306
final public static function getOrdinals(): array
307307
{
308308
$count = \count(self::detectConstants(static::class));
309-
return $count === 0 ? [] : \range(0, $count - 1);
309+
return $count ? \range(0, $count - 1) : [];
310310
}
311311

312312
/**
@@ -328,11 +328,8 @@ final public static function getConstants(): array
328328
*/
329329
final public static function has($enumerator): bool
330330
{
331-
if ($enumerator instanceof static && \get_class($enumerator) === static::class) {
332-
return true;
333-
}
334-
335-
return static::hasValue($enumerator);
331+
return ($enumerator instanceof static && \get_class($enumerator) === static::class)
332+
|| static::hasValue($enumerator);
336333
}
337334

338335
/**

src/EnumMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function search($value, bool $strict = false): ?Enum
112112
public function contains($enumerator): bool
113113
{
114114
try {
115-
$ord = ($this->enumeration)::get($enumerator)->getOrdinal();
115+
$ord = ($this->enumeration)::get($enumerator)->getOrdinal();
116116
return array_key_exists($ord, $this->map);
117117
} catch (InvalidArgumentException $e) {
118118
// An invalid enumerator can't be contained in this map

src/EnumSet.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,8 @@ public function isEqual(EnumSet $other): bool
348348
*/
349349
public function isSubset(EnumSet $other): bool
350350
{
351-
if ($this->enumeration !== $other->enumeration) {
352-
return false;
353-
}
354-
355-
return ($this->bitset & $other->bitset) === $this->bitset;
351+
return $this->enumeration === $other->enumeration
352+
&& ($this->bitset & $other->bitset) === $this->bitset;
356353
}
357354

358355
/**
@@ -362,11 +359,8 @@ public function isSubset(EnumSet $other): bool
362359
*/
363360
public function isSuperset(EnumSet $other): bool
364361
{
365-
if ($this->enumeration !== $other->enumeration) {
366-
return false;
367-
}
368-
369-
return ($this->bitset | $other->bitset) === $this->bitset;
362+
return $this->enumeration === $other->enumeration
363+
&& ($this->bitset | $other->bitset) === $this->bitset;
370364
}
371365

372366
/**

0 commit comments

Comments
 (0)