Skip to content

Commit 06d3c61

Browse files
committed
Removed code for PHP < 7.2 and HHVM
1 parent 688f508 commit 06d3c61

File tree

4 files changed

+13
-43
lines changed

4 files changed

+13
-43
lines changed

bench/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$zendassertions = ini_get('zend.assertions');
4-
if (\PHP_VERSION_ID >= 70000 && $zendassertions != -1) {
4+
if ($zendassertions != -1) {
55
echo 'Please disable zend.assertions in php.ini (zend.assertions = -1)' . PHP_EOL
66
. "Current ini setting: zend.assertions = {$zendassertions}]" . PHP_EOL;
77
exit(1);

src/Enum.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,35 +365,27 @@ private static function detectConstants(string $class): array
365365
{
366366
if (!isset(self::$constants[$class])) {
367367
$reflection = new ReflectionClass($class);
368-
$publicConstants = [];
368+
$allConstants = [];
369369

370370
do {
371371
$scopeConstants = [];
372-
if (\PHP_VERSION_ID >= 70100 && method_exists(ReflectionClass::class, 'getReflectionConstants')) {
373-
// Since PHP-7.1 visibility modifiers are allowed for class constants
374-
// for enumerations we are only interested in public once.
375-
// NOTE: HHVM > 3.26.2 still does not support private/protected constants.
376-
// It allows the visibility keyword but ignores it.
377-
foreach ($reflection->getReflectionConstants() as $reflConstant) {
378-
if ($reflConstant->isPublic()) {
379-
$scopeConstants[ $reflConstant->getName() ] = $reflConstant->getValue();
380-
}
372+
// Enumerators must be defined as public class constants
373+
foreach ($reflection->getReflectionConstants() as $reflConstant) {
374+
if ($reflConstant->isPublic()) {
375+
$scopeConstants[ $reflConstant->getName() ] = $reflConstant->getValue();
381376
}
382-
} else {
383-
// In PHP < 7.1 all class constants were public by definition
384-
$scopeConstants = $reflection->getConstants();
385377
}
386378

387-
$publicConstants = $scopeConstants + $publicConstants;
379+
$allConstants = $scopeConstants + $allConstants;
388380
} while (($reflection = $reflection->getParentClass()) && $reflection->name !== __CLASS__);
389381

390382
assert(
391-
self::noAmbiguousValues($publicConstants),
383+
self::noAmbiguousValues($allConstants),
392384
"Ambiguous enumerator values detected for {$class}"
393385
);
394386

395-
self::$constants[$class] = $publicConstants;
396-
self::$names[$class] = \array_keys($publicConstants);
387+
self::$constants[$class] = $allConstants;
388+
self::$names[$class] = \array_keys($allConstants);
397389
}
398390

399391
return self::$constants[$class];

tests/MabeEnumTest/EnumTest.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,7 @@ public function testInstantiateUsingMagicMethod()
314314
public function testEnabledAssertAmbiguousEnumeratorValues()
315315
{
316316
$this->expectException(AssertionError::class);
317-
318-
if (\PHP_VERSION_ID >= 70000 && strpos(\PHP_VERSION, 'hhvm') === false) {
319-
// The assertion error contains the assertion description as exception message since PHP-7
320-
$this->expectExceptionMessage('Ambiguous enumerator values detected for ' . EnumAmbiguous::class);
321-
}
317+
$this->expectExceptionMessage('Ambiguous enumerator values detected for ' . EnumAmbiguous::class);
322318

323319
EnumAmbiguous::get('unknown');
324320
}
@@ -334,11 +330,7 @@ public function testDisabledAssertAmbiguousEnumeratorValues()
334330
public function testExtendedEnabledAssertAmbiguousEnumeratorValues()
335331
{
336332
$this->expectException(AssertionError::class);
337-
338-
if (\PHP_VERSION_ID >= 70000 && strpos(\PHP_VERSION, 'hhvm') === false) {
339-
// The assertion error contains the assertion description as exception message since PHP-7
340-
$this->expectExceptionMessage('Ambiguous enumerator values detected for ' . EnumExtendedAmbiguous::class);
341-
}
333+
$this->expectExceptionMessage('Ambiguous enumerator values detected for ' . EnumExtendedAmbiguous::class);
342334

343335
EnumExtendedAmbiguous::get('unknown');
344336
}
@@ -414,13 +406,6 @@ public function testHasValue()
414406

415407
public function testConstVisibility()
416408
{
417-
if (PHP_VERSION_ID < 70100) {
418-
$this->markTestSkipped('This test is for PHP-7.1 and upper only');
419-
}
420-
if (defined('HHVM_VERSION')) {
421-
$this->markTestSkipped('HHVM does not support constant visibility');
422-
}
423-
424409
$constants = ConstVisibilityEnum::getConstants();
425410
$this->assertSame(array(
426411
'IPUB' => ConstVisibilityEnum::IPUB,
@@ -430,13 +415,6 @@ public function testConstVisibility()
430415

431416
public function testConstVisibilityExtended()
432417
{
433-
if (PHP_VERSION_ID < 70100) {
434-
$this->markTestSkipped('This test is for PHP-7.1 and upper only');
435-
}
436-
if (defined('HHVM_VERSION')) {
437-
$this->markTestSkipped('HHVM does not support constant visibility');
438-
}
439-
440418
$constants = ConstVisibilityEnumExtended::getConstants();
441419
$this->assertSame(array(
442420
'IPUB' => ConstVisibilityEnumExtended::IPUB,

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// make sure zend.assertions are available (not disabled on compile time)
77
$zendassertions = ini_get('zend.assertions');
8-
if (\PHP_VERSION_ID >= 70000 && $zendassertions == -1) {
8+
if ($zendassertions == -1) {
99
echo 'Please enable zend.assertions in php.ini (zend.assertions = 1)' . PHP_EOL
1010
. "Current ini setting: zend.assertions = {$zendassertions}]" . PHP_EOL;
1111
exit(1);

0 commit comments

Comments
 (0)