Skip to content

Commit 0c5fcc9

Browse files
committed
removed support for PHP 7
1 parent 1cfb541 commit 0c5fcc9

14 files changed

+122
-382
lines changed

src/Utils/Html.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,15 +763,7 @@ final public function render(int $indent = null): string
763763

764764
final public function __toString(): string
765765
{
766-
try {
767-
return $this->render();
768-
} catch (\Throwable $e) {
769-
if (PHP_VERSION_ID >= 70400) {
770-
throw $e;
771-
}
772-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
773-
return '';
774-
}
766+
return $this->render();
775767
}
776768

777769

src/Utils/Image.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,7 @@ public function toString(int $type = self::JPEG, int $quality = null): string
591591
*/
592592
public function __toString(): string
593593
{
594-
try {
595-
return $this->toString();
596-
} catch (\Throwable $e) {
597-
if (func_num_args() || PHP_VERSION_ID >= 70400) {
598-
throw $e;
599-
}
600-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
601-
return '';
602-
}
594+
return $this->toString();
603595
}
604596

605597

src/Utils/Reflection.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function getParameterTypes(\ReflectionParameter $param): array
9898
*/
9999
public static function getPropertyType(\ReflectionProperty $prop): ?string
100100
{
101-
return self::getType($prop, PHP_VERSION_ID >= 70400 ? $prop->getType() : null);
101+
return self::getType($prop, $prop->getType());
102102
}
103103

104104

@@ -319,9 +319,7 @@ private static function parseUseStatements(string $code, string $forClass = null
319319
$namespace = $class = $classLevel = $level = null;
320320
$res = $uses = [];
321321

322-
$nameTokens = PHP_VERSION_ID < 80000
323-
? [T_STRING, T_NS_SEPARATOR]
324-
: [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED];
322+
$nameTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED];
325323

326324
while ($token = current($tokens)) {
327325
next($tokens);

src/Utils/Type.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ final class Type
3434
*/
3535
public static function fromReflection($reflection): ?self
3636
{
37-
if ($reflection instanceof \ReflectionProperty && PHP_VERSION_ID < 70400) {
38-
return null;
39-
} elseif ($reflection instanceof \ReflectionMethod) {
37+
if ($reflection instanceof \ReflectionMethod) {
4038
$type = $reflection->getReturnType() ?? (PHP_VERSION_ID >= 80100 ? $reflection->getTentativeReturnType() : null);
4139
} else {
4240
$type = $reflection instanceof \ReflectionFunctionAbstract

tests/Utils/Reflection.getParameterType.80.phpt

Lines changed: 0 additions & 70 deletions
This file was deleted.

tests/Utils/Reflection.getParameterType.phpt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ require __DIR__ . '/../bootstrap.php';
1616

1717
class A
1818
{
19-
public function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none, ?B $nullable)
20-
{
19+
public function method(
20+
Undeclared $undeclared,
21+
B $b,
22+
array $array,
23+
callable $callable,
24+
self $self,
25+
$none,
26+
?B $nullable,
27+
mixed $mixed,
28+
array|self $union,
29+
array|self|null $nullableUnion,
30+
) {
2131
}
2232
}
2333

@@ -38,6 +48,20 @@ Assert::same('callable', Reflection::getParameterType($params[3]));
3848
Assert::same('A', Reflection::getParameterType($params[4]));
3949
Assert::null(Reflection::getParameterType($params[5]));
4050
Assert::same('Test\B', Reflection::getParameterType($params[6]));
51+
Assert::same(['Test\B', 'null'], Reflection::getParameterTypes($params[6]));
52+
Assert::same('mixed', Reflection::getParameterType($params[7]));
53+
Assert::same(['mixed'], Reflection::getParameterTypes($params[7]));
54+
Assert::same(['A', 'array'], Reflection::getParameterTypes($params[8]));
55+
Assert::same(['A', 'array', 'null'], Reflection::getParameterTypes($params[9]));
56+
57+
Assert::exception(function () use ($params) {
58+
Reflection::getParameterType($params[8]);
59+
}, Nette\InvalidStateException::class, 'The $union in A::method() is not expected to have a union or intersection type.');
60+
61+
Assert::exception(function () use ($params) {
62+
Reflection::getParameterType($params[9]);
63+
}, Nette\InvalidStateException::class, 'The $nullableUnion in A::method() is not expected to have a union or intersection type.');
64+
4165

4266
$method = new ReflectionMethod('AExt', 'methodExt');
4367
$params = $method->getParameters();

tests/Utils/Reflection.getPropertyType.74.phpt

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/Utils/Reflection.getPropertyType.80.phpt

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/Utils/Reflection.getPropertyType.phpt

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
declare(strict_types=1);
88

99
use Nette\Utils\Reflection;
10+
use Test\B; // for testing purposes
1011
use Tester\Assert;
1112

1213

@@ -15,11 +16,46 @@ require __DIR__ . '/../bootstrap.php';
1516

1617
class A
1718
{
19+
public Undeclared $undeclared;
20+
public B $b;
21+
public array $array;
22+
public self $self;
1823
public $none;
24+
public ?B $nullable;
25+
public mixed $mixed;
26+
public array|self $union;
27+
public array|self|null $nullableUnion;
28+
}
29+
30+
class AExt extends A
31+
{
32+
public parent $parent;
1933
}
2034

2135
$class = new ReflectionClass('A');
2236
$props = $class->getProperties();
2337

24-
Assert::null(Reflection::getPropertyType($props[0]));
25-
Assert::same([], Reflection::getPropertyTypes($props[0]));
38+
Assert::same('Undeclared', Reflection::getPropertyType($props[0]));
39+
Assert::same('Test\B', Reflection::getPropertyType($props[1]));
40+
Assert::same('array', Reflection::getPropertyType($props[2]));
41+
Assert::same('A', Reflection::getPropertyType($props[3]));
42+
Assert::null(Reflection::getPropertyType($props[4]));
43+
Assert::same('Test\B', Reflection::getPropertyType($props[5]));
44+
Assert::same(['Test\B', 'null'], Reflection::getPropertyTypes($props[5]));
45+
Assert::same('mixed', Reflection::getPropertyType($props[6]));
46+
Assert::same(['mixed'], Reflection::getPropertyTypes($props[6]));
47+
Assert::same(['A', 'array'], Reflection::getPropertyTypes($props[7]));
48+
Assert::same(['A', 'array', 'null'], Reflection::getPropertyTypes($props[8]));
49+
50+
Assert::exception(function () use ($props) {
51+
Reflection::getPropertyType($props[7]);
52+
}, Nette\InvalidStateException::class, 'The A::$union is not expected to have a union or intersection type.');
53+
54+
Assert::exception(function () use ($props) {
55+
Reflection::getPropertyType($props[8]);
56+
}, Nette\InvalidStateException::class, 'The A::$nullableUnion is not expected to have a union or intersection type.');
57+
58+
$class = new ReflectionClass('AExt');
59+
$props = $class->getProperties();
60+
61+
Assert::same('A', Reflection::getPropertyType($props[0]));

0 commit comments

Comments
 (0)