Skip to content

Commit

Permalink
used native PHP 8 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 28, 2021
1 parent dc67af6 commit 30e2c2c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Utils/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function toReflection($callable): \ReflectionFunctionAbstract
$callable = self::unwrap($callable);
}

if (is_string($callable) && strpos($callable, '::')) {
if (is_string($callable) && str_contains($callable, '::')) {
return new \ReflectionMethod($callable);
} elseif (is_array($callable)) {
return new \ReflectionMethod($callable[0], $callable[1]);
Expand All @@ -120,7 +120,7 @@ public static function isStatic(callable $callable): bool
public static function unwrap(\Closure $closure): callable
{
$r = new \ReflectionFunction($closure);
if (substr($r->name, -1) === '}') {
if (str_ends_with($r->name, '}')) {
return $closure;

} elseif ($obj = $r->getClosureThis()) {
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,14 +805,14 @@ final public function attributes(): string
$value = (string) $value;
}

$q = strpos($value, '"') === false ? '"' : "'";
$q = str_contains($value, '"') ? "'" : '"';
$s .= ' ' . $key . '=' . $q
. str_replace(
['&', $q, '<'],
['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
$value,
)
. (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
. (str_contains($value, '`') && strpbrk($value, ' <>"\'') === false ? ' ' : '')
. $q;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ public function __clone()

private static function isPercent(int|string &$num): bool
{
if (is_string($num) && substr($num, -1) === '%') {
if (is_string($num) && str_ends_with($num, '%')) {
$num = (float) substr($num, 0, -1);
return true;
} elseif (is_int($num) || $num === (string) (int) $num) {
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function chr(int $code): string
*/
public static function startsWith(string $haystack, string $needle): bool
{
return strncmp($haystack, $needle, strlen($needle)) === 0;
return str_starts_with($haystack, $needle);
}


Expand All @@ -71,7 +71,7 @@ public static function startsWith(string $haystack, string $needle): bool
*/
public static function endsWith(string $haystack, string $needle): bool
{
return $needle === '' || substr($haystack, -strlen($needle)) === $needle;
return str_ends_with($haystack, $needle);
}


Expand All @@ -80,7 +80,7 @@ public static function endsWith(string $haystack, string $needle): bool
*/
public static function contains(string $haystack, string $needle): bool
{
return strpos($haystack, $needle) !== false;
return str_contains($haystack, $needle);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ public static function assertField(
public static function is(mixed $value, string $expected): bool
{
foreach (explode('|', $expected) as $item) {
if (substr($item, -2) === '[]') {
if (str_ends_with($item, '[]')) {
if (is_iterable($value) && self::everyIs($value, substr($item, 0, -2))) {
return true;
}
continue;
} elseif (substr($item, 0, 1) === '?') {
} elseif (str_starts_with($item, '?')) {
$item = substr($item, 1);
if ($value === null) {
return true;
Expand Down

0 comments on commit 30e2c2c

Please sign in to comment.