Skip to content

Commit 03f3913

Browse files
Merge branch '6.4' into 7.0
* 6.4: More short closures + isset instead of null checks + etc.
2 parents f073957 + fe9228b commit 03f3913

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

AbstractString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public function split(string $delimiter, int $limit = null, int $flags = null):
448448
$delimiter .= 'i';
449449
}
450450

451-
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
451+
set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m));
452452

453453
try {
454454
if (false === $chunks = preg_split($delimiter, $this->string, $limit, $flags)) {
@@ -507,7 +507,7 @@ public function toByteString(string $toEncoding = null): ByteString
507507
return $b;
508508
}
509509

510-
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
510+
set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m));
511511

512512
try {
513513
try {

AbstractUnicodeString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array
228228
$regexp .= 'i';
229229
}
230230

231-
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
231+
set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m));
232232

233233
try {
234234
if (false === $match($regexp.'u', $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) {
@@ -312,7 +312,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static
312312
$replace = 'preg_replace';
313313
}
314314

315-
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
315+
set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m));
316316

317317
try {
318318
if (null === $string = $replace($fromRegexp.'u', $to, $this->string)) {

ByteString.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array
236236
$regexp .= 'i';
237237
}
238238

239-
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
239+
set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m));
240240

241241
try {
242242
if (false === $match($regexp, $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) {
@@ -300,7 +300,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static
300300

301301
$replace = \is_array($to) || $to instanceof \Closure ? 'preg_replace_callback' : 'preg_replace';
302302

303-
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
303+
set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m));
304304

305305
try {
306306
if (null === $string = $replace($fromRegexp, $to, $this->string)) {
@@ -417,7 +417,7 @@ public function toCodePointString(string $fromEncoding = null): CodePointString
417417
return $u;
418418
}
419419

420-
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
420+
set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m));
421421

422422
try {
423423
try {

UnicodeString.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,32 @@ class UnicodeString extends AbstractUnicodeString
3434
{
3535
public function __construct(string $string = '')
3636
{
37-
$this->string = normalizer_is_normalized($string) ? $string : normalizer_normalize($string);
37+
if ('' === $string || normalizer_is_normalized($this->string = $string)) {
38+
return;
39+
}
3840

39-
if (false === $this->string) {
41+
if (false === $string = normalizer_normalize($string)) {
4042
throw new InvalidArgumentException('Invalid UTF-8 string.');
4143
}
44+
45+
$this->string = $string;
4246
}
4347

4448
public function append(string ...$suffix): static
4549
{
4650
$str = clone $this;
4751
$str->string = $this->string.(1 >= \count($suffix) ? ($suffix[0] ?? '') : implode('', $suffix));
48-
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
4952

50-
if (false === $str->string) {
53+
if (normalizer_is_normalized($str->string)) {
54+
return $str;
55+
}
56+
57+
if (false === $string = normalizer_normalize($str->string)) {
5158
throw new InvalidArgumentException('Invalid UTF-8 string.');
5259
}
5360

61+
$str->string = $string;
62+
5463
return $str;
5564
}
5665

@@ -209,12 +218,17 @@ public function prepend(string ...$prefix): static
209218
{
210219
$str = clone $this;
211220
$str->string = (1 >= \count($prefix) ? ($prefix[0] ?? '') : implode('', $prefix)).$this->string;
212-
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
213221

214-
if (false === $str->string) {
222+
if (normalizer_is_normalized($str->string)) {
223+
return $str;
224+
}
225+
226+
if (false === $string = normalizer_normalize($str->string)) {
215227
throw new InvalidArgumentException('Invalid UTF-8 string.');
216228
}
217229

230+
$str->string = $string;
231+
218232
return $str;
219233
}
220234

@@ -235,11 +249,16 @@ public function replace(string $from, string $to): static
235249
}
236250

237251
$str->string = $result.$tail;
238-
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
239252

240-
if (false === $str->string) {
253+
if (normalizer_is_normalized($str->string)) {
254+
return $str;
255+
}
256+
257+
if (false === $string = normalizer_normalize($str->string)) {
241258
throw new InvalidArgumentException('Invalid UTF-8 string.');
242259
}
260+
261+
$str->string = $string;
243262
}
244263

245264
return $str;
@@ -269,12 +288,17 @@ public function splice(string $replacement, int $start = 0, int $length = null):
269288
$start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
270289
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length;
271290
$str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);
272-
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
273291

274-
if (false === $str->string) {
292+
if (normalizer_is_normalized($str->string)) {
293+
return $str;
294+
}
295+
296+
if (false === $string = normalizer_normalize($str->string)) {
275297
throw new InvalidArgumentException('Invalid UTF-8 string.');
276298
}
277299

300+
$str->string = $string;
301+
278302
return $str;
279303
}
280304

0 commit comments

Comments
 (0)