Skip to content

Commit b963fb5

Browse files
committed
removed PHP 7.0 stuff
1 parent 37e91f9 commit b963fb5

File tree

9 files changed

+17
-67
lines changed

9 files changed

+17
-67
lines changed

src/Utils/Callback.php

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,11 @@ final class Callback
2525
*/
2626
public static function closure($callable, string $method = null): \Closure
2727
{
28-
if ($method !== null) {
29-
$callable = [$callable, $method];
30-
}
31-
32-
if (PHP_VERSION_ID >= 70100) {
33-
try {
34-
return \Closure::fromCallable($callable);
35-
} catch (\TypeError $e) {
36-
throw new Nette\InvalidArgumentException($e->getMessage());
37-
}
38-
} elseif (is_string($callable) && count($tmp = explode('::', $callable)) === 2) {
39-
$callable = $tmp;
40-
41-
} elseif ($callable instanceof \Closure) {
42-
return $callable;
43-
44-
} elseif (is_object($callable)) {
45-
$callable = [$callable, '__invoke'];
46-
}
47-
48-
if (is_string($callable) && function_exists($callable)) {
49-
return (new \ReflectionFunction($callable))->getClosure();
50-
51-
} elseif (is_array($callable) && method_exists($callable[0], $callable[1])) {
52-
return (new \ReflectionMethod($callable[0], $callable[1]))->getClosure($callable[0]);
28+
try {
29+
return \Closure::fromCallable($method === null ? $callable : [$callable, $method]);
30+
} catch (\TypeError $e) {
31+
throw new Nette\InvalidArgumentException($e->getMessage());
5332
}
54-
55-
self::check($callable);
56-
$_callable_ = $callable;
57-
return function (...$args) use ($_callable_) {
58-
return $_callable_(...$args);
59-
};
6033
}
6134

6235

@@ -169,8 +142,7 @@ public static function unwrap(\Closure $closure): callable
169142
{
170143
$r = new \ReflectionFunction($closure);
171144
if (substr($r->getName(), -1) === '}') {
172-
$vars = $r->getStaticVariables();
173-
return $vars['_callable_'] ?? $closure;
145+
return $closure;
174146

175147
} elseif ($obj = $r->getClosureThis()) {
176148
return [$obj, $r->getName()];

src/Utils/Image.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ public static function fromFile(string $file, int &$detectedFormat = null)
148148
}
149149

150150
$detectedFormat = @getimagesize($file)[2]; // @ - files smaller than 12 bytes causes read error
151-
if (!$detectedFormat && PHP_VERSION_ID < 70100 && @file_get_contents($file, false, null, 8, 4) === 'WEBP') { // @ - may not exists
152-
$detectedFormat = self::WEBP;
153-
}
154151
if (!isset(self::$formats[$detectedFormat])) {
155152
$detectedFormat = null;
156153
throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found.");

src/Utils/Json.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ public static function encode($value, int $flags = 0): string
3737
if ($error = json_last_error()) {
3838
throw new JsonException(json_last_error_msg(), $error);
3939
}
40-
41-
if (PHP_VERSION_ID < 70100) {
42-
$json = str_replace(["\u{2028}", "\u{2029}"], ['\u2028', '\u2029'], $json);
43-
}
44-
4540
return $json;
4641
}
4742

@@ -57,7 +52,6 @@ public static function decode(string $json, int $flags = 0)
5752
if ($error = json_last_error()) {
5853
throw new JsonException(json_last_error_msg(), $error);
5954
}
60-
6155
return $value;
6256
}
6357
}

src/Utils/Reflection.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,21 @@ public static function getParameterDefaultValue(\ReflectionParameter $param)
7575
if ($param->isDefaultValueConstant()) {
7676
$const = $orig = $param->getDefaultValueConstantName();
7777
$pair = explode('::', $const);
78-
if (isset($pair[1]) && strtolower($pair[0]) === 'self') {
79-
$pair[0] = $param->getDeclaringClass()->getName();
80-
}
81-
if (isset($pair[1]) && PHP_VERSION_ID >= 70100) {
78+
if (isset($pair[1])) {
79+
if (strtolower($pair[0]) === 'self') {
80+
$pair[0] = $param->getDeclaringClass()->getName();
81+
}
8282
try {
8383
$rcc = new \ReflectionClassConstant($pair[0], $pair[1]);
8484
} catch (\ReflectionException $e) {
8585
$name = self::toString($param);
8686
throw new \ReflectionException("Unable to resolve constant $orig used as default value of $name.", 0, $e);
8787
}
8888
return $rcc->getValue();
89-
}
90-
$const = implode('::', $pair);
91-
if (!defined($const)) {
89+
90+
} elseif (!defined($const)) {
9291
$const = substr((string) strrchr($const, '\\'), 1);
93-
if (isset($pair[1]) || !defined($const)) {
92+
if (!defined($const)) {
9493
$name = self::toString($param);
9594
throw new \ReflectionException("Unable to resolve constant $orig used as default value of $name.");
9695
}

src/Utils/Validators.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Validators
5151
'upper' => 'ctype_upper',
5252
'space' => 'ctype_space',
5353
'xdigit' => 'ctype_xdigit',
54-
'iterable' => [__CLASS__, 'isIterable'],
54+
'iterable' => 'is_iterable',
5555
];
5656

5757
protected static $counters = [
@@ -158,7 +158,7 @@ public static function is($value, string $expected): bool
158158
*/
159159
public static function everyIs($values, string $expected): bool
160160
{
161-
if (!self::isIterable($values)) {
161+
if (!is_iterable($values)) {
162162
return false;
163163
}
164164
foreach ($values as $value) {
@@ -317,13 +317,4 @@ public static function isPhpIdentifier(string $value): bool
317317
{
318318
return is_string($value) && preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\z#', $value);
319319
}
320-
321-
322-
/**
323-
* Returns true if value is iterable (array or instance of Traversable).
324-
*/
325-
private static function isIterable($value): bool
326-
{
327-
return is_array($value) || $value instanceof \Traversable;
328-
}
329320
}

tests/Utils/Callback.closure.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test(function () { // global function
9292

9393
Assert::exception(function () {
9494
Callback::closure('undefined');
95-
}, Nette\InvalidArgumentException::class, PHP_VERSION_ID >= 70100 ? "%a% function 'undefined' not found %a%" : "Callback 'undefined' is not callable.");
95+
}, Nette\InvalidArgumentException::class, "%a% function 'undefined' not found %a%");
9696

9797
Assert::exception(function () {
9898
Callback::toReflection('undefined');
@@ -148,7 +148,7 @@ test(function () { // object methods
148148
Assert::same('Test::privateFun', getName(Callback::toReflection([$test, 'privateFun'])));
149149
Assert::same('Test::privateFun', getName(Callback::toReflection(Callback::closure($test, 'privateFun'))));
150150

151-
Assert::same(PHP_VERSION_ID >= 70100 ? 'Test::__call privateFun *' : 'Test::privateFun*', Callback::closure($test, 'privateFun')->__invoke('*'));
151+
Assert::same('Test::__call privateFun *', Callback::closure($test, 'privateFun')->__invoke('*'));
152152

153153
Assert::same('Test::ref', Callback::closure($test, 'ref')(...[&$res]));
154154
Assert::same('Test::ref', $res);
@@ -181,7 +181,7 @@ test(function () { // static methods
181181
Assert::same('Test::privateStatic', getName(Callback::toReflection('Test::privateStatic')));
182182
Assert::same('Test::privateStatic', getName(Callback::toReflection(Callback::closure('Test::privateStatic'))));
183183

184-
Assert::same(PHP_VERSION_ID >= 70100 ? 'Test::__callStatic privateStatic *' : 'Test::privateStatic*', Callback::closure('Test::privateStatic')->__invoke('*'));
184+
Assert::same('Test::__callStatic privateStatic *', Callback::closure('Test::privateStatic')->__invoke('*'));
185185
});
186186

187187

tests/Utils/Reflection.getParameterDefaultValue.php71.phpt

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

33
/**
44
* Test: Nette\Utils\Reflection::getParameterDefaultValue()
5-
* @phpVersion 7.1
65
*/
76

87
declare(strict_types=1);

tests/Utils/Reflection.getParameterType.php71.phpt

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

33
/**
44
* Test: Nette\Utils\Reflection::getParameterType
5-
* @phpVersion 7.1
65
*/
76

87
declare(strict_types=1);

tests/Utils/Reflection.getReturnType.php71.phpt

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

33
/**
44
* Test: Nette\Utils\Reflection::getReturnType
5-
* @phpVersion 7.1
65
*/
76

87
declare(strict_types=1);

0 commit comments

Comments
 (0)