Skip to content

Commit e281d73

Browse files
committed
used native PHP 8 functions
1 parent 7aa0c10 commit e281d73

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/Utils/Callback.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static function toReflection($callable): \ReflectionFunctionAbstract
9393
$callable = self::unwrap($callable);
9494
}
9595

96-
if (is_string($callable) && strpos($callable, '::')) {
96+
if (is_string($callable) && str_contains($callable, '::')) {
9797
return new \ReflectionMethod($callable);
9898
} elseif (is_array($callable)) {
9999
return new \ReflectionMethod($callable[0], $callable[1]);
@@ -120,7 +120,7 @@ public static function isStatic(callable $callable): bool
120120
public static function unwrap(\Closure $closure): callable|array
121121
{
122122
$r = new \ReflectionFunction($closure);
123-
if (substr($r->name, -1) === '}') {
123+
if (str_ends_with($r->name, '}')) {
124124
return $closure;
125125

126126
} elseif ($obj = $r->getClosureThis()) {

src/Utils/Html.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,14 +815,14 @@ final public function attributes(): string
815815
$value = (string) $value;
816816
}
817817

818-
$q = strpos($value, '"') === false ? '"' : "'";
818+
$q = str_contains($value, '"') ? "'" : '"';
819819
$s .= ' ' . $key . '=' . $q
820820
. str_replace(
821821
['&', $q, '<'],
822822
['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
823823
$value,
824824
)
825-
. (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
825+
. (str_contains($value, '`') && strpbrk($value, ' <>"\'') === false ? ' ' : '')
826826
. $q;
827827
}
828828

src/Utils/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ public function __clone()
702702

703703
private static function isPercent(int|string &$num): bool
704704
{
705-
if (is_string($num) && substr($num, -1) === '%') {
705+
if (is_string($num) && str_ends_with($num, '%')) {
706706
$num = (float) substr($num, 0, -1);
707707
return true;
708708
} elseif (is_int($num) || $num === (string) (int) $num) {

src/Utils/Strings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function chr(int $code): string
6363
*/
6464
public static function startsWith(string $haystack, string $needle): bool
6565
{
66-
return strncmp($haystack, $needle, strlen($needle)) === 0;
66+
return str_starts_with($haystack, $needle);
6767
}
6868

6969

@@ -72,7 +72,7 @@ public static function startsWith(string $haystack, string $needle): bool
7272
*/
7373
public static function endsWith(string $haystack, string $needle): bool
7474
{
75-
return $needle === '' || substr($haystack, -strlen($needle)) === $needle;
75+
return str_ends_with($haystack, $needle);
7676
}
7777

7878

@@ -81,7 +81,7 @@ public static function endsWith(string $haystack, string $needle): bool
8181
*/
8282
public static function contains(string $haystack, string $needle): bool
8383
{
84-
return strpos($haystack, $needle) !== false;
84+
return str_contains($haystack, $needle);
8585
}
8686

8787

src/Utils/Validators.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ public static function assertField(
132132
public static function is(mixed $value, string $expected): bool
133133
{
134134
foreach (explode('|', $expected) as $item) {
135-
if (substr($item, -2) === '[]') {
135+
if (str_ends_with($item, '[]')) {
136136
if (is_iterable($value) && self::everyIs($value, substr($item, 0, -2))) {
137137
return true;
138138
}
139139

140140
continue;
141-
} elseif (substr($item, 0, 1) === '?') {
141+
} elseif (str_starts_with($item, '?')) {
142142
$item = substr($item, 1);
143143
if ($value === null) {
144144
return true;

0 commit comments

Comments
 (0)