From 92cb03679f5aee883100f972161b4d5d145ecd84 Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 10:23:50 +0100 Subject: [PATCH 01/10] Fix for "PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead" --- src/String/template.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/String/template.php b/src/String/template.php index a035e74..559e2b4 100644 --- a/src/String/template.php +++ b/src/String/template.php @@ -120,17 +120,17 @@ function template(string $string, array $options = []): callable if ($escapeValue) { $escapeValue = \trim($escapeValue); - $source .= ""; + $source .= ""; } if ($evaluateValue) { - $source .= ""; + $source .= ""; } if ($interpolateValue) { $interpolateValue = \trim($interpolateValue ?? $esTemplateValue); $interpolateValue = \preg_replace('#^([\p{L}\p{N}_]+)$#u', '$$1', $interpolateValue); - $source .= ""; + $source .= ""; } return $source; From 8cc5fa15cfc872e3ac01ca76173c9eeb9630e2ec Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 10:24:39 +0100 Subject: [PATCH 02/10] Use of `is_iterable` instead of `is_array($source) || $source instanceof Traversable` --- src/internal/baseMatches.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/baseMatches.php b/src/internal/baseMatches.php index d7c919b..3f39f4f 100644 --- a/src/internal/baseMatches.php +++ b/src/internal/baseMatches.php @@ -21,7 +21,7 @@ function baseMatches($source): callable return true; } - if (\is_array($source) || $source instanceof \Traversable) { + if (\is_iterable($source)) { foreach ($source as $k => $v) { if (!isEqual(property($k)($value, $index, $collection), $v)) { return false; From 2294511a7685957147e16542c409e25aa732a4df Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 10:25:27 +0100 Subject: [PATCH 03/10] Use of null coalesce operator, that comes with PHP7.1 --- src/String/truncate.php | 2 +- src/internal/castSlice.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/String/truncate.php b/src/String/truncate.php index cdca582..7fc4601 100644 --- a/src/String/truncate.php +++ b/src/String/truncate.php @@ -101,7 +101,7 @@ function truncate($string, array $options = []) $newEnd = \end($match[0])[1]; } - $result = \substr($result, 0, null === $newEnd ? $end : $newEnd); + $result = \substr($result, 0, $newEnd ?? $end); } } elseif (\strpos($string, $separator) !== $end) { $index = \strrpos($result, $separator); diff --git a/src/internal/castSlice.php b/src/internal/castSlice.php index fcb027c..6d50495 100644 --- a/src/internal/castSlice.php +++ b/src/internal/castSlice.php @@ -25,7 +25,7 @@ function castSlice(array $array, int $start, ?int $end = null): array { $length = \count($array); - $end = null === $end ? $length : $end; + $end = $end ?? $length; return (!$start && $end >= $length) ? $array : \array_slice($array, $start, $end); } From bbc8fc469f70e450d5788d149be49494928784d9 Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 10:26:05 +0100 Subject: [PATCH 04/10] The rand() function has been replaced with the random_int() function. This change provides more reliable randomness and mitigates potential security vulnerabilities associated with the previous function. --- src/Number/random.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Number/random.php b/src/Number/random.php index 7da25a7..7a72b97 100644 --- a/src/Number/random.php +++ b/src/Number/random.php @@ -74,5 +74,5 @@ function random($lower = null, $upper = null, $floating = null) return $lower + \abs($upper - $lower) * \mt_rand(0, $randMax) / $randMax; } - return \rand((int) $lower, (int) $upper); + return random_int((int) $lower, (int) $upper); } From 822764e64df62939aa4f7447ea7a63e63691d289 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Tue, 12 Dec 2023 11:46:44 +0200 Subject: [PATCH 05/10] Use root namespace for function call --- src/Number/random.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Number/random.php b/src/Number/random.php index 7a72b97..8d322af 100644 --- a/src/Number/random.php +++ b/src/Number/random.php @@ -74,5 +74,5 @@ function random($lower = null, $upper = null, $floating = null) return $lower + \abs($upper - $lower) * \mt_rand(0, $randMax) / $randMax; } - return random_int((int) $lower, (int) $upper); + return \random_int((int) $lower, (int) $upper); } From 706f23d299824a1a083c7030baa7cb3666107bbc Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 11:06:08 +0100 Subject: [PATCH 06/10] The `dropWhile` predicate in Array has been updated to use the current array value instead of directly referencing by index. --- src/Array/dropWhile.php | 4 +++- tests/Array/DropWhileTest.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Array/dropWhile.php b/src/Array/dropWhile.php index ce62b5f..fea0fe8 100644 --- a/src/Array/dropWhile.php +++ b/src/Array/dropWhile.php @@ -40,11 +40,13 @@ function dropWhile(array $array, callable $predicate): array $count = \count($array); $length = 0; $index = \key($array); - while ($length <= $count && $predicate($array[$index], $index, $array)) { + $value = \current($array); + while ($length <= $count && $predicate($value, $index, $array)) { array_shift($array); \reset($array); $length++; $index = \key($array); + $value = \current($array); } return $array; diff --git a/tests/Array/DropWhileTest.php b/tests/Array/DropWhileTest.php index 997f761..cf5a2e8 100644 --- a/tests/Array/DropWhileTest.php +++ b/tests/Array/DropWhileTest.php @@ -26,4 +26,23 @@ public function testDropWhile() return $user['active']; })); } + + public function testDropWhile2() + { + $lines = [ + 'Processing report:', + 'Processed: 1', + 'Successful: 1', + '', + '', + ]; + + $lines = dropWhile($lines, static function ($x) { return trim((string) $x) !== ''; }); + + self::assertEquals(['', ''], $lines); + + $lines = dropWhile($lines, static function ($x) { return trim((string) $x) === ''; }); + + self::assertEmpty($lines); + } } From 2888581c0e92499e3cbc8917246fd3fbae225a34 Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 11:09:03 +0100 Subject: [PATCH 07/10] Fixed tabs -> spaces --- tests/Array/DropWhileTest.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Array/DropWhileTest.php b/tests/Array/DropWhileTest.php index cf5a2e8..437813e 100644 --- a/tests/Array/DropWhileTest.php +++ b/tests/Array/DropWhileTest.php @@ -26,23 +26,23 @@ public function testDropWhile() return $user['active']; })); } - + public function testDropWhile2() { $lines = [ - 'Processing report:', - 'Processed: 1', - 'Successful: 1', - '', - '', + 'Processing report:', + 'Processed: 1', + 'Successful: 1', + '', + '', ]; - - $lines = dropWhile($lines, static function ($x) { return trim((string) $x) !== ''; }); - - self::assertEquals(['', ''], $lines); - - $lines = dropWhile($lines, static function ($x) { return trim((string) $x) === ''; }); - - self::assertEmpty($lines); + + $lines = dropWhile($lines, static function ($x) { return trim((string) $x) !== ''; }); + + self::assertEquals(['', ''], $lines); + + $lines = dropWhile($lines, static function ($x) { return trim((string) $x) === ''; }); + + self::assertEmpty($lines); } } From 0b131683b667cc7e24595da4d859774b0c0003a1 Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 11:10:43 +0100 Subject: [PATCH 08/10] Fixed tabs -> spaces --- src/Array/dropWhile.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Array/dropWhile.php b/src/Array/dropWhile.php index fea0fe8..36020df 100644 --- a/src/Array/dropWhile.php +++ b/src/Array/dropWhile.php @@ -40,13 +40,13 @@ function dropWhile(array $array, callable $predicate): array $count = \count($array); $length = 0; $index = \key($array); - $value = \current($array); + $value = \current($array); while ($length <= $count && $predicate($value, $index, $array)) { array_shift($array); \reset($array); $length++; $index = \key($array); - $value = \current($array); + $value = \current($array); } return $array; From 894cd2aeb44bef10418bfb6599505d2a9c2d27d5 Mon Sep 17 00:00:00 2001 From: rkr Date: Tue, 12 Dec 2023 11:20:08 +0100 Subject: [PATCH 09/10] Fixed code style --- tests/Array/DropWhileTest.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/Array/DropWhileTest.php b/tests/Array/DropWhileTest.php index 437813e..5efeadf 100644 --- a/tests/Array/DropWhileTest.php +++ b/tests/Array/DropWhileTest.php @@ -26,7 +26,7 @@ public function testDropWhile() return $user['active']; })); } - + public function testDropWhile2() { $lines = [ @@ -36,13 +36,17 @@ public function testDropWhile2() '', '', ]; - - $lines = dropWhile($lines, static function ($x) { return trim((string) $x) !== ''; }); - + + $lines = dropWhile($lines, static function ($x) { + return trim((string) $x) !== ''; + }); + self::assertEquals(['', ''], $lines); - - $lines = dropWhile($lines, static function ($x) { return trim((string) $x) === ''; }); - + + $lines = dropWhile($lines, static function ($x) { + return trim((string) $x) === ''; + }); + self::assertEmpty($lines); } } From adcade45b922482f2bd1968139a8481c137d9065 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Tue, 12 Dec 2023 15:32:56 +0200 Subject: [PATCH 10/10] Combine tests --- tests/Array/DropWhileTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Array/DropWhileTest.php b/tests/Array/DropWhileTest.php index 5efeadf..50bef5a 100644 --- a/tests/Array/DropWhileTest.php +++ b/tests/Array/DropWhileTest.php @@ -25,10 +25,7 @@ public function testDropWhile() $this->assertSame([['user' => 'pebbles', 'active' => false]], dropWhile($users, function ($user) { return $user['active']; })); - } - - public function testDropWhile2() - { + $lines = [ 'Processing report:', 'Processed: 1', pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy