Skip to content

Commit 67158e4

Browse files
committed
used PHP 7.0 features
1 parent 237a909 commit 67158e4

23 files changed

+120
-120
lines changed

src/Utils/Callback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static function unwrap(\Closure $closure)
177177
$r = new \ReflectionFunction($closure);
178178
if (substr($r->getName(), -1) === '}') {
179179
$vars = $r->getStaticVariables();
180-
return isset($vars['_callable_']) ? $vars['_callable_'] : $closure;
180+
return $vars['_callable_'] ?? $closure;
181181

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

src/Utils/Html.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static function el($name = NULL, $attrs = NULL)
7070

7171
if (isset($parts[1])) {
7272
foreach (Strings::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\s))?#i') as $m) {
73-
$el->attrs[$m[1]] = isset($m[3]) ? $m[3] : TRUE;
73+
$el->attrs[$m[1]] = $m[3] ?? TRUE;
7474
}
7575
}
7676

@@ -175,7 +175,7 @@ public function setAttribute($name, $value)
175175
*/
176176
public function getAttribute($name)
177177
{
178-
return isset($this->attrs[$name]) ? $this->attrs[$name] : NULL;
178+
return $this->attrs[$name] ?? NULL;
179179
}
180180

181181

@@ -249,7 +249,7 @@ public function __call($m, $args)
249249
$m = substr($m, 3);
250250
$m[0] = $m[0] | "\x20";
251251
if ($p === 'get') {
252-
return isset($this->attrs[$m]) ? $this->attrs[$m] : NULL;
252+
return $this->attrs[$m] ?? NULL;
253253

254254
} elseif ($p === 'add') {
255255
$args[] = TRUE;

src/Utils/Json.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function encode($value, $options = 0)
3939
}
4040

4141
if (PHP_VERSION_ID < 70100) {
42-
$json = str_replace(["\xe2\x80\xa8", "\xe2\x80\xa9"], ['\u2028', '\u2029'], $json);
42+
$json = str_replace(["\u{2028}", "\u{2029}"], ['\u2028', '\u2029'], $json);
4343
}
4444

4545
return $json;

src/Utils/Strings.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Strings
1818
{
1919
use Nette\StaticClass;
2020

21-
const TRIM_CHARACTERS = " \t\n\r\0\x0B\xC2\xA0";
21+
const TRIM_CHARACTERS = " \t\n\r\0\x0B\u{A0}";
2222

2323

2424
/**
@@ -163,15 +163,15 @@ public static function toAscii($s)
163163
$s = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s);
164164
$s = strtr($s, '`\'"^~?', "\x01\x02\x03\x04\x05\x06");
165165
$s = str_replace(
166-
["\xE2\x80\x9E", "\xE2\x80\x9C", "\xE2\x80\x9D", "\xE2\x80\x9A", "\xE2\x80\x98", "\xE2\x80\x99", "\xC2\xB0"],
166+
["\u{201E}", "\u{201C}", "\u{201D}", "\u{201A}", "\u{2018}", "\u{2019}", "\u{B0}"],
167167
["\x03", "\x03", "\x03", "\x02", "\x02", "\x02", "\x04"], $s
168168
);
169169
if ($transliterator !== NULL) {
170170
$s = $transliterator->transliterate($s);
171171
}
172172
if (ICONV_IMPL === 'glibc') {
173173
$s = str_replace(
174-
["\xC2\xBB", "\xC2\xAB", "\xE2\x80\xA6", "\xE2\x84\xA2", "\xC2\xA9", "\xC2\xAE"],
174+
["\u{BB}", "\u{AB}", "\u{2026}", "\u{2122}", "\u{A9}", "\u{AE}"],
175175
['>>', '<<', '...', 'TM', '(c)', '(R)'], $s
176176
);
177177
$s = iconv('UTF-8', 'WINDOWS-1250//TRANSLIT//IGNORE', $s);
@@ -216,7 +216,7 @@ public static function webalize($s, $charlist = NULL, $lower = TRUE)
216216
* @param string UTF-8 encoding
217217
* @return string
218218
*/
219-
public static function truncate($s, $maxLen, $append = "\xE2\x80\xA6")
219+
public static function truncate(string $s, int $maxLen, string $append = "\u{2026}")
220220
{
221221
if (self::length($s) > $maxLen) {
222222
$maxLen = $maxLen - self::length($append);
@@ -592,7 +592,7 @@ public static function pcre($func, $args)
592592
if (($code = preg_last_error()) // run-time error, but preg_last_error & return code are liars
593593
&& ($res === NULL || !in_array($func, ['preg_filter', 'preg_replace_callback', 'preg_replace']))
594594
) {
595-
throw new RegexpException((isset($messages[$code]) ? $messages[$code] : 'Unknown error')
595+
throw new RegexpException(($messages[$code] ?? 'Unknown error')
596596
. ' (pattern: ' . implode(' or ', (array) $args[0]) . ')', $code);
597597
}
598598
return $res;

src/Utils/Validators.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function is($value, $expected)
134134
continue;
135135
}
136136
} elseif ($type === 'pattern') {
137-
if (preg_match('|^' . (isset($item[1]) ? $item[1] : '') . '\z|', $value)) {
137+
if (preg_match('|^' . ($item[1] ?? '') . '\z|', $value)) {
138138
return TRUE;
139139
}
140140
continue;

tests/Utils/Json.encode().phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Assert::exception(function () {
2727

2828

2929
// default JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES
30-
Assert::same("\"/I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n\"", Json::encode("/I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n"));
31-
Assert::same('"\u2028\u2029"', Json::encode("\xe2\x80\xa8\xe2\x80\xa9"));
30+
Assert::same("\"/I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n\"", Json::encode("/I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n"));
31+
Assert::same('"\u2028\u2029"', Json::encode("\u{2028}\u{2029}"));
3232

3333
// JSON_PRETTY_PRINT
3434
Assert::same("[\n 1,\n 2,\n 3\n]", Json::encode([1, 2, 3], Json::PRETTY));

tests/Utils/Strings.after().phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test(function () {
3333

3434

3535
test(function () {
36-
$foo = "I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n"; // Iñtërnâtiônàlizætiøn
37-
Assert::same("\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n", Strings::after($foo, 'ti', 1));
38-
Assert::same("\xc3\xb8n", Strings::after($foo, 'ti', 2));
36+
$foo = "I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n"; // Iñtërnâtiônàlizætiøn
37+
Assert::same("\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n", Strings::after($foo, 'ti', 1));
38+
Assert::same("\u{F8}n", Strings::after($foo, 'ti', 2));
3939
});

tests/Utils/Strings.before().phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test(function () {
3232

3333

3434
test(function () {
35-
$foo = "I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n"; // Iñtërnâtiônàlizætiøn
36-
Assert::same("I\xc3\xb1t\xc3\xabrn\xc3\xa2", Strings::before($foo, 'ti', 1));
37-
Assert::same("I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6", Strings::before($foo, 'ti', 2));
35+
$foo = "I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n"; // Iñtërnâtiônàlizætiøn
36+
Assert::same("I\u{F1}t\u{EB}rn\u{E2}", Strings::before($foo, 'ti', 1));
37+
Assert::same("I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}", Strings::before($foo, 'ti', 2));
3838
});

tests/Utils/Strings.checkEncoding().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Tester\Assert;
1111
require __DIR__ . '/../bootstrap.php';
1212

1313

14-
Assert::true(Strings::checkEncoding("\xc5\xbelu\xc5\xa5ou\xc4\x8dk\xc3\xbd")); // UTF-8 žluťoučký
14+
Assert::true(Strings::checkEncoding("\u{17E}lu\u{165}ou\u{10D}k\u{FD}")); // UTF-8 žluťoučký
1515
Assert::true(Strings::checkEncoding("\x01")); // C0
1616
Assert::false(Strings::checkEncoding("\xed\xa0\x80")); // surrogate pairs xD800
1717
Assert::false(Strings::checkEncoding("\xf4\x90\x80\x80")); // out of range x110000

tests/Utils/Strings.chr().phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ require __DIR__ . '/../bootstrap.php';
1313

1414
Assert::same("\x00", Strings::chr(0x000000));
1515
Assert::same("\x7F", Strings::chr(0x00007F));
16-
Assert::same("\xC2\x80", Strings::chr(0x000080));
17-
Assert::same("\xDF\xBF", Strings::chr(0x0007FF));
18-
Assert::same("\xE0\xA0\x80", Strings::chr(0x000800));
19-
Assert::same("\xED\x9F\xBF", Strings::chr(0x00D7FF));
20-
Assert::same("\xEE\x80\x80", Strings::chr(0x00E000));
21-
Assert::same("\xEF\xBF\xBF", Strings::chr(0x00FFFF));
22-
Assert::same("\xF0\x90\x80\x80", Strings::chr(0x010000));
23-
Assert::same("\xF4\x8F\xBF\xBF", Strings::chr(0x10FFFF));
16+
Assert::same("\u{80}", Strings::chr(0x000080));
17+
Assert::same("\u{7FF}", Strings::chr(0x0007FF));
18+
Assert::same("\u{800}", Strings::chr(0x000800));
19+
Assert::same("\u{D7FF}", Strings::chr(0x00D7FF));
20+
Assert::same("\u{E000}", Strings::chr(0x00E000));
21+
Assert::same("\u{FFFF}", Strings::chr(0x00FFFF));
22+
Assert::same("\u{10000}", Strings::chr(0x010000));
23+
Assert::same("\u{10FFFF}", Strings::chr(0x10FFFF));
2424

2525
foreach ([-1, 0xD800, 0xDFFF, 0x110000] as $code) {
2626
Assert::exception(function () use ($code) {

0 commit comments

Comments
 (0)