Skip to content

Commit db8599f

Browse files
committed
No type-hints for private/final methods except void for performance reasons
1 parent 3f9edaf commit db8599f

File tree

4 files changed

+46
-45
lines changed

4 files changed

+46
-45
lines changed

src/Enum.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class Enum
5858
* @param null|bool|int|float|string|array $value The value of the enumerator
5959
* @param int|null $ordinal The ordinal number of the enumerator
6060
*/
61-
final private function __construct($value, int $ordinal = null)
61+
final private function __construct($value, $ordinal = null)
6262
{
6363
$this->value = $value;
6464
$this->ordinal = $ordinal;
@@ -117,7 +117,7 @@ final public function getValue()
117117
*
118118
* @return string
119119
*/
120-
final public function getName(): string
120+
final public function getName()
121121
{
122122
return self::$names[static::class][$this->ordinal ?: $this->getOrdinal()];
123123
}
@@ -127,7 +127,7 @@ final public function getName(): string
127127
*
128128
* @return int
129129
*/
130-
final public function getOrdinal(): int
130+
final public function getOrdinal()
131131
{
132132
if ($this->ordinal === null) {
133133
$ordinal = 0;
@@ -151,7 +151,7 @@ final public function getOrdinal(): int
151151
* @param static|null|bool|int|float|string|array $enumerator An enumerator object or value
152152
* @return bool
153153
*/
154-
final public function is($enumerator): bool
154+
final public function is($enumerator)
155155
{
156156
return $this === $enumerator || $this->value === $enumerator
157157

@@ -170,7 +170,7 @@ final public function is($enumerator): bool
170170
* @throws InvalidArgumentException On an unknwon or invalid value
171171
* @throws LogicException On ambiguous constant values
172172
*/
173-
final public static function get($enumerator): self
173+
final public static function get($enumerator)
174174
{
175175
if ($enumerator instanceof static && \get_class($enumerator) === static::class) {
176176
return $enumerator;
@@ -187,7 +187,7 @@ final public static function get($enumerator): self
187187
* @throws InvalidArgumentException On an unknwon or invalid value
188188
* @throws LogicException On ambiguous constant values
189189
*/
190-
final public static function byValue($value): self
190+
final public static function byValue($value)
191191
{
192192
if (!isset(self::$constants[static::class])) {
193193
self::detectConstants(static::class);
@@ -219,7 +219,7 @@ final public static function byValue($value): self
219219
* @throws InvalidArgumentException On an invalid or unknown name
220220
* @throws LogicException On ambiguous values
221221
*/
222-
final public static function byName(string $name): self
222+
final public static function byName(string $name)
223223
{
224224
if (isset(self::$instances[static::class][$name])) {
225225
return self::$instances[static::class][$name];
@@ -241,7 +241,7 @@ final public static function byName(string $name): self
241241
* @throws InvalidArgumentException On an invalid ordinal number
242242
* @throws LogicException On ambiguous values
243243
*/
244-
final public static function byOrdinal(int $ordinal): self
244+
final public static function byOrdinal(int $ordinal)
245245
{
246246
if (!isset(self::$names[static::class])) {
247247
self::detectConstants(static::class);
@@ -268,7 +268,7 @@ final public static function byOrdinal(int $ordinal): self
268268
*
269269
* @return static[]
270270
*/
271-
final public static function getEnumerators(): array
271+
final public static function getEnumerators()
272272
{
273273
if (!isset(self::$names[static::class])) {
274274
self::detectConstants(static::class);
@@ -281,7 +281,7 @@ final public static function getEnumerators(): array
281281
*
282282
* @return mixed[]
283283
*/
284-
final public static function getValues(): array
284+
final public static function getValues()
285285
{
286286
return \array_values(self::detectConstants(static::class));
287287
}
@@ -291,7 +291,7 @@ final public static function getValues(): array
291291
*
292292
* @return string[]
293293
*/
294-
final public static function getNames(): array
294+
final public static function getNames()
295295
{
296296
if (!isset(self::$names[static::class])) {
297297
self::detectConstants(static::class);
@@ -304,7 +304,7 @@ final public static function getNames(): array
304304
*
305305
* @return int[]
306306
*/
307-
final public static function getOrdinals(): array
307+
final public static function getOrdinals()
308308
{
309309
$count = \count(self::detectConstants(static::class));
310310
return $count ? \range(0, $count - 1) : [];
@@ -316,7 +316,7 @@ final public static function getOrdinals(): array
316316
* @return array
317317
* @throws LogicException On ambiguous constant values
318318
*/
319-
final public static function getConstants(): array
319+
final public static function getConstants()
320320
{
321321
return self::detectConstants(static::class);
322322
}
@@ -327,7 +327,7 @@ final public static function getConstants(): array
327327
* @param static|null|bool|int|float|string|array $enumerator
328328
* @return bool
329329
*/
330-
final public static function has($enumerator): bool
330+
final public static function has($enumerator)
331331
{
332332
return ($enumerator instanceof static && \get_class($enumerator) === static::class)
333333
|| static::hasValue($enumerator);
@@ -339,7 +339,7 @@ final public static function has($enumerator): bool
339339
* @param null|bool|int|float|string|array $value
340340
* @return bool
341341
*/
342-
final public static function hasValue($value): bool
342+
final public static function hasValue($value)
343343
{
344344
$constants = self::detectConstants(static::class);
345345
return \in_array($value, $constants, true);
@@ -351,7 +351,7 @@ final public static function hasValue($value): bool
351351
* @param string $name
352352
* @return bool
353353
*/
354-
final public static function hasName(string $name): bool
354+
final public static function hasName(string $name)
355355
{
356356
return \defined("static::{$name}");
357357
}
@@ -362,7 +362,7 @@ final public static function hasName(string $name): bool
362362
* @param string $class
363363
* @return array
364364
*/
365-
private static function detectConstants(string $class): array
365+
private static function detectConstants($class)
366366
{
367367
if (!isset(self::$constants[$class])) {
368368
$reflection = new ReflectionClass($class);
@@ -397,7 +397,7 @@ private static function detectConstants(string $class): array
397397
* @param array $constants
398398
* @return bool
399399
*/
400-
private static function noAmbiguousValues(array $constants): bool
400+
private static function noAmbiguousValues($constants)
401401
{
402402
foreach ($constants as $value) {
403403
$names = \array_keys($constants, $value, true);
@@ -421,7 +421,7 @@ private static function noAmbiguousValues(array $constants): bool
421421
* @throws InvalidArgumentException On an invalid or unknown name
422422
* @throws LogicException On ambiguous constant values
423423
*/
424-
final public static function __callStatic(string $method, array $args): self
424+
final public static function __callStatic(string $method, array $args)
425425
{
426426
return self::byName($method);
427427
}

src/EnumMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getValues(): array
9595
* @param bool $strict Use strict type comparison
9696
* @return Enum|null The found key or NULL
9797
*/
98-
public function search($value, bool $strict = false): ?Enum
98+
public function search($value, bool $strict = false)
9999
{
100100
$ord = \array_search($value, $this->map, $strict);
101101
if ($ord !== false) {

src/EnumSerializableTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public function serialize(): string
4242
* Unserializes a given serialized value and push it into the current instance
4343
* This will be called automatically on `unserialize()` if the enumeration implements the `Serializable` interface
4444
* @param string $serialized
45+
* @return void
4546
* @throws RuntimeException On an unknown or invalid value
4647
* @throws LogicException On changing numeration value by calling this directly
4748
*/
48-
public function unserialize($serialized)
49+
public function unserialize($serialized): void
4950
{
5051
$value = \unserialize($serialized);
5152
$constants = self::getConstants();

src/EnumSet.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function getIterator(): Iterator
156156
* @see getIterator()
157157
* @see goGetIteratorInt()
158158
*/
159-
private function doGetIteratorBin(): Iterator
159+
private function doGetIteratorBin()
160160
{
161161
$bitset = $this->bitset;
162162
$byteLen = \strlen($bitset);
@@ -185,7 +185,7 @@ private function doGetIteratorBin(): Iterator
185185
* @see getIterator()
186186
* @see doGetIteratorBin()
187187
*/
188-
private function doGetIteratorInt(): Iterator
188+
private function doGetIteratorInt()
189189
{
190190
$count = $this->enumerationCount;
191191
$bitset = $this->bitset;
@@ -219,7 +219,7 @@ public function count(): int
219219
* @see count()
220220
* @see doCountInt()
221221
*/
222-
private function doCountBin(): int
222+
private function doCountBin()
223223
{
224224
$count = 0;
225225
$bitset = $this->bitset;
@@ -252,7 +252,7 @@ private function doCountBin(): int
252252
* @see count()
253253
* @see doCountBin()
254254
*/
255-
private function doCountInt(): int
255+
private function doCountInt()
256256
{
257257
$count = 0;
258258
$bitset = $this->bitset;
@@ -325,10 +325,10 @@ public function isSuperset(EnumSet $other): bool
325325
* Produce a new set with enumerators from both this and other (this | other)
326326
*
327327
* @param EnumSet $other EnumSet of the same enumeration to produce the union
328-
* @return EnumSet
328+
* @return static
329329
* @throws InvalidArgumentException If $other doesn't match the enumeration
330330
*/
331-
public function union(EnumSet $other): EnumSet
331+
public function union(EnumSet $other): self
332332
{
333333
if ($this->enumeration !== $other->enumeration) {
334334
throw new InvalidArgumentException(\sprintf(
@@ -346,10 +346,10 @@ public function union(EnumSet $other): EnumSet
346346
* Produce a new set with enumerators common to both this and other (this & other)
347347
*
348348
* @param EnumSet $other EnumSet of the same enumeration to produce the intersect
349-
* @return EnumSet
349+
* @return static
350350
* @throws InvalidArgumentException If $other doesn't match the enumeration
351351
*/
352-
public function intersect(EnumSet $other): EnumSet
352+
public function intersect(EnumSet $other): self
353353
{
354354
if ($this->enumeration !== $other->enumeration) {
355355
throw new InvalidArgumentException(\sprintf(
@@ -367,10 +367,10 @@ public function intersect(EnumSet $other): EnumSet
367367
* Produce a new set with enumerators in this but not in other (this - other)
368368
*
369369
* @param EnumSet $other EnumSet of the same enumeration to produce the diff
370-
* @return EnumSet
370+
* @return static
371371
* @throws InvalidArgumentException If $other doesn't match the enumeration
372372
*/
373-
public function diff(EnumSet $other): EnumSet
373+
public function diff(EnumSet $other): self
374374
{
375375
if ($this->enumeration !== $other->enumeration) {
376376
throw new InvalidArgumentException(\sprintf(
@@ -388,10 +388,10 @@ public function diff(EnumSet $other): EnumSet
388388
* Produce a new set with enumerators in either this and other but not in both (this ^ other)
389389
*
390390
* @param EnumSet $other EnumSet of the same enumeration to produce the symmetric difference
391-
* @return EnumSet
391+
* @return static
392392
* @throws InvalidArgumentException If $other doesn't match the enumeration
393393
*/
394-
public function symDiff(EnumSet $other): EnumSet
394+
public function symDiff(EnumSet $other): self
395395
{
396396
if ($this->enumeration !== $other->enumeration) {
397397
throw new InvalidArgumentException(\sprintf(
@@ -425,7 +425,7 @@ public function getOrdinals(): array
425425
* @see getOrdinals()
426426
* @see goGetOrdinalsInt()
427427
*/
428-
private function doGetOrdinalsBin(): array
428+
private function doGetOrdinalsBin()
429429
{
430430
$ordinals = [];
431431
$bitset = $this->bitset;
@@ -455,7 +455,7 @@ private function doGetOrdinalsBin(): array
455455
* @see getOrdinals()
456456
* @see doGetOrdinalsBin()
457457
*/
458-
private function doGetOrdinalsInt(): array
458+
private function doGetOrdinalsInt()
459459
{
460460
$ordinals = [];
461461
$count = $this->enumerationCount;
@@ -531,7 +531,7 @@ public function getBinaryBitsetLe(): string
531531
* @see getBinaryBitsetLe()
532532
* @see doGetBinaryBitsetLeInt()
533533
*/
534-
private function doGetBinaryBitsetLeBin(): string
534+
private function doGetBinaryBitsetLeBin()
535535
{
536536
return $this->bitset;
537537
}
@@ -545,7 +545,7 @@ private function doGetBinaryBitsetLeBin(): string
545545
* @see getBinaryBitsetLe()
546546
* @see doGetBinaryBitsetLeBin()
547547
*/
548-
private function doGetBinaryBitsetLeInt(): string
548+
private function doGetBinaryBitsetLeInt()
549549
{
550550
$bin = \pack(\PHP_INT_SIZE === 8 ? 'P' : 'V', $this->bitset);
551551
return \substr($bin, 0, (int)\ceil($this->enumerationCount / 8));
@@ -578,7 +578,7 @@ public function setBinaryBitsetLe(string $bitset): void
578578
* @see setBinaryBitsetLeBin()
579579
* @see doSetBinaryBitsetLeInt()
580580
*/
581-
private function doSetBinaryBitsetLeBin(string $bitset): void
581+
private function doSetBinaryBitsetLeBin($bitset): void
582582
{
583583
$size = \strlen($this->bitset);
584584
$sizeIn = \strlen($bitset);
@@ -619,7 +619,7 @@ private function doSetBinaryBitsetLeBin(string $bitset): void
619619
* @see setBinaryBitsetLeBin()
620620
* @see doSetBinaryBitsetLeBin()
621621
*/
622-
private function doSetBinaryBitsetLeInt(string $bitset): void
622+
private function doSetBinaryBitsetLeInt($bitset): void
623623
{
624624
$len = \strlen($bitset);
625625
$int = 0;
@@ -692,7 +692,7 @@ public function getBit(int $ordinal): bool
692692
* @see getBit()
693693
* @see doGetBitInt()
694694
*/
695-
private function doGetBitBin(int $ordinal): bool
695+
private function doGetBitBin($ordinal)
696696
{
697697
return (\ord($this->bitset[(int) ($ordinal / 8)]) & 1 << ($ordinal % 8)) !== 0;
698698
}
@@ -707,7 +707,7 @@ private function doGetBitBin(int $ordinal): bool
707707
* @see getBit()
708708
* @see doGetBitBin()
709709
*/
710-
private function doGetBitInt(int $ordinal): bool
710+
private function doGetBitInt($ordinal)
711711
{
712712
return (bool)($this->bitset & (1 << $ordinal));
713713
}
@@ -747,7 +747,7 @@ public function setBit(int $ordinal, bool $bit): void
747747
* @see setBit()
748748
* @see doSetBitInt()
749749
*/
750-
private function doSetBitBin(int $ordinal): void
750+
private function doSetBitBin($ordinal): void
751751
{
752752
$byte = (int) ($ordinal / 8);
753753
$this->bitset[$byte] = $this->bitset[$byte] | \chr(1 << ($ordinal % 8));
@@ -763,7 +763,7 @@ private function doSetBitBin(int $ordinal): void
763763
* @see setBit()
764764
* @see doSetBitBin()
765765
*/
766-
private function doSetBitInt(int $ordinal): void
766+
private function doSetBitInt($ordinal): void
767767
{
768768
$this->bitset = $this->bitset | (1 << $ordinal);
769769
}
@@ -778,7 +778,7 @@ private function doSetBitInt(int $ordinal): void
778778
* @see setBit()
779779
* @see doUnsetBitInt()
780780
*/
781-
private function doUnsetBitBin(int $ordinal): void
781+
private function doUnsetBitBin($ordinal): void
782782
{
783783
$byte = (int) ($ordinal / 8);
784784
$this->bitset[$byte] = $this->bitset[$byte] & \chr(~(1 << ($ordinal % 8)));
@@ -794,7 +794,7 @@ private function doUnsetBitBin(int $ordinal): void
794794
* @see setBit()
795795
* @see doUnsetBitBin()
796796
*/
797-
private function doUnsetBitInt(int $ordinal): void
797+
private function doUnsetBitInt($ordinal): void
798798
{
799799
$this->bitset = $this->bitset & ~(1 << $ordinal);
800800
}

0 commit comments

Comments
 (0)