Skip to content

Commit 79be624

Browse files
xurshudyanXurshudyan
andauthored
[13.x] Remove function existence checks (#54876)
* Remove function existence checks * remove unused JsonException import --------- Co-authored-by: Xurshudyan <[email protected]>
1 parent 4ca4a16 commit 79be624

File tree

2 files changed

+5
-44
lines changed

2 files changed

+5
-44
lines changed

src/Illuminate/Support/Str.php

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Closure;
66
use Illuminate\Support\Traits\Macroable;
7-
use JsonException;
87
use League\CommonMark\Environment\Environment;
98
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
109
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
@@ -546,17 +545,7 @@ public static function isJson($value)
546545
return false;
547546
}
548547

549-
if (function_exists('json_validate')) {
550-
return json_validate($value, 512);
551-
}
552-
553-
try {
554-
json_decode($value, true, 512, JSON_THROW_ON_ERROR);
555-
} catch (JsonException) {
556-
return false;
557-
}
558-
559-
return true;
548+
return json_validate($value, 512);
560549
}
561550

562551
/**
@@ -906,17 +895,7 @@ public static function numbers($value)
906895
*/
907896
public static function padBoth($value, $length, $pad = ' ')
908897
{
909-
if (function_exists('mb_str_pad')) {
910-
return mb_str_pad($value, $length, $pad, STR_PAD_BOTH);
911-
}
912-
913-
$short = max(0, $length - mb_strlen($value));
914-
$shortLeft = floor($short / 2);
915-
$shortRight = ceil($short / 2);
916-
917-
return mb_substr(str_repeat($pad, $shortLeft), 0, $shortLeft).
918-
$value.
919-
mb_substr(str_repeat($pad, $shortRight), 0, $shortRight);
898+
return mb_str_pad($value, $length, $pad, STR_PAD_BOTH);
920899
}
921900

922901
/**
@@ -929,13 +908,7 @@ public static function padBoth($value, $length, $pad = ' ')
929908
*/
930909
public static function padLeft($value, $length, $pad = ' ')
931910
{
932-
if (function_exists('mb_str_pad')) {
933-
return mb_str_pad($value, $length, $pad, STR_PAD_LEFT);
934-
}
935-
936-
$short = max(0, $length - mb_strlen($value));
937-
938-
return mb_substr(str_repeat($pad, $short), 0, $short).$value;
911+
return mb_str_pad($value, $length, $pad, STR_PAD_LEFT);
939912
}
940913

941914
/**
@@ -948,13 +921,7 @@ public static function padLeft($value, $length, $pad = ' ')
948921
*/
949922
public static function padRight($value, $length, $pad = ' ')
950923
{
951-
if (function_exists('mb_str_pad')) {
952-
return mb_str_pad($value, $length, $pad, STR_PAD_RIGHT);
953-
}
954-
955-
$short = max(0, $length - mb_strlen($value));
956-
957-
return $value.mb_substr(str_repeat($pad, $short), 0, $short);
924+
return mb_str_pad($value, $length, $pad, STR_PAD_RIGHT);
958925
}
959926

960927
/**

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,7 @@ public function validateJson($attribute, $value)
15261526
return false;
15271527
}
15281528

1529-
if (function_exists('json_validate')) {
1530-
return json_validate($value);
1531-
}
1532-
1533-
json_decode($value);
1534-
1535-
return json_last_error() === JSON_ERROR_NONE;
1529+
return json_validate($value);
15361530
}
15371531

15381532
/**

0 commit comments

Comments
 (0)