Skip to content

Commit a576d02

Browse files
committed
removed support for PHP 7
1 parent 5818764 commit a576d02

12 files changed

+99
-339
lines changed

src/Utils/Html.php

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

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

776768

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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static function getParameterTypes(\ReflectionParameter $param): array
8181
*/
8282
public static function getPropertyType(\ReflectionProperty $prop): ?string
8383
{
84-
return self::getType($prop, PHP_VERSION_ID >= 70400 ? $prop->getType() : null);
84+
return self::getType($prop, $prop->getType());
8585
}
8686

8787

@@ -90,7 +90,7 @@ public static function getPropertyType(\ReflectionProperty $prop): ?string
9090
*/
9191
public static function getPropertyTypes(\ReflectionProperty $prop): array
9292
{
93-
return self::getType($prop, PHP_VERSION_ID >= 70400 ? $prop->getType() : null, true);
93+
return self::getType($prop, $prop->getType(), true);
9494
}
9595

9696

@@ -328,9 +328,7 @@ private static function parseUseStatements(string $code, string $forClass = null
328328
$namespace = $class = $classLevel = $level = null;
329329
$res = $uses = [];
330330

331-
$nameTokens = PHP_VERSION_ID < 80000
332-
? [T_STRING, T_NS_SEPARATOR]
333-
: [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED];
331+
$nameTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED];
334332

335333
while ($token = current($tokens)) {
336334
next($tokens);

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 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 type.');
64+
4165

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

tests/Utils/Reflection.getPropertyType.80.phpt

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

tests/Utils/Reflection.getPropertyType.phpt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/**
44
* Test: Nette\Utils\Reflection::getPropertyType
5-
* @phpversion 7.4
65
*/
76

87
declare(strict_types=1);
@@ -23,6 +22,9 @@ class A
2322
public self $self;
2423
public $none;
2524
public ?B $nullable;
25+
public mixed $mixed;
26+
public array|self $union;
27+
public array|self|null $nullableUnion;
2628
}
2729

2830
class AExt extends A
@@ -39,6 +41,19 @@ Assert::same('array', Reflection::getPropertyType($props[2]));
3941
Assert::same('A', Reflection::getPropertyType($props[3]));
4042
Assert::null(Reflection::getPropertyType($props[4]));
4143
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 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 type.');
4257

4358
$class = new ReflectionClass('AExt');
4459
$props = $class->getProperties();

0 commit comments

Comments
 (0)