diff --git a/library/Rules/Charset.php b/library/Rules/Charset.php index d8529b93..40492c9b 100644 --- a/library/Rules/Charset.php +++ b/library/Rules/Charset.php @@ -54,8 +54,6 @@ final class Charset extends AbstractRule */ public function validate($input): bool { - $detectedEncoding = mb_detect_encoding($input, $this->charset, true); - - return in_array($detectedEncoding, $this->charset, true); + return in_array(mb_detect_encoding($input, $this->charset, true), $this->charset, true); } } diff --git a/library/Rules/Contains.php b/library/Rules/Contains.php index 0e1ec731..b4103427 100644 --- a/library/Rules/Contains.php +++ b/library/Rules/Contains.php @@ -16,7 +16,6 @@ namespace Respect\Validation\Rules; use function in_array; use function is_array; use function is_scalar; -use function mb_detect_encoding; use function mb_stripos; use function mb_strpos; @@ -74,11 +73,10 @@ final class Contains extends AbstractRule return false; } - $encoding = (string) mb_detect_encoding($haystack); if ($this->identical) { - return mb_strpos($haystack, $needle, 0, $encoding) !== false; + return mb_strpos($haystack, $needle) !== false; } - return mb_stripos($haystack, $needle, 0, $encoding) !== false; + return mb_stripos($haystack, $needle) !== false; } } diff --git a/library/Rules/EndsWith.php b/library/Rules/EndsWith.php index c0caf392..90326785 100644 --- a/library/Rules/EndsWith.php +++ b/library/Rules/EndsWith.php @@ -15,7 +15,6 @@ namespace Respect\Validation\Rules; use function end; use function is_array; -use function mb_detect_encoding; use function mb_strlen; use function mb_strripos; use function mb_strrpos; @@ -70,10 +69,7 @@ final class EndsWith extends AbstractRule return end($input) == $this->endValue; } - $encoding = (string) mb_detect_encoding($input); - $endPosition = mb_strlen($input, $encoding) - mb_strlen($this->endValue, $encoding); - - return mb_strripos($input, $this->endValue, 0, $encoding) === $endPosition; + return mb_strripos($input, $this->endValue) === mb_strlen($input) - mb_strlen($this->endValue); } /** @@ -85,9 +81,6 @@ final class EndsWith extends AbstractRule return end($input) === $this->endValue; } - $encoding = (string) mb_detect_encoding($input); - $endPosition = mb_strlen($input, $encoding) - mb_strlen($this->endValue, $encoding); - - return mb_strrpos($input, $this->endValue, 0, $encoding) === $endPosition; + return mb_strrpos($input, $this->endValue) === mb_strlen($input) - mb_strlen($this->endValue); } } diff --git a/library/Rules/In.php b/library/Rules/In.php index 448ee8af..1b3bb841 100644 --- a/library/Rules/In.php +++ b/library/Rules/In.php @@ -15,7 +15,6 @@ namespace Respect\Validation\Rules; use function in_array; use function is_array; -use function mb_detect_encoding; use function mb_stripos; use function mb_strpos; @@ -74,9 +73,7 @@ final class In extends AbstractRule return $input == $this->haystack; } - $inputString = (string) $input; - - return mb_stripos($this->haystack, $inputString, 0, (string) mb_detect_encoding($inputString)) !== false; + return mb_stripos($this->haystack, (string) $input) !== false; } /** @@ -92,8 +89,6 @@ final class In extends AbstractRule return $input === $this->haystack; } - $inputString = (string) $input; - - return mb_strpos($this->haystack, $inputString, 0, (string) mb_detect_encoding($inputString)) !== false; + return mb_strpos($this->haystack, (string) $input) !== false; } } diff --git a/library/Rules/Length.php b/library/Rules/Length.php index df0b8fc1..5be52ae5 100644 --- a/library/Rules/Length.php +++ b/library/Rules/Length.php @@ -22,7 +22,6 @@ use function is_array; use function is_int; use function is_object; use function is_string; -use function mb_detect_encoding; use function mb_strlen; use function sprintf; @@ -89,7 +88,7 @@ final class Length extends AbstractRule private function extractLength($input): ?int { if (is_string($input)) { - return (int) mb_strlen($input, (string) mb_detect_encoding($input)); + return (int) mb_strlen($input); } if (is_array($input) || $input instanceof CountableInterface) { diff --git a/library/Rules/Lowercase.php b/library/Rules/Lowercase.php index a73231d4..61e01d6d 100644 --- a/library/Rules/Lowercase.php +++ b/library/Rules/Lowercase.php @@ -14,7 +14,6 @@ declare(strict_types=1); namespace Respect\Validation\Rules; use function is_string; -use function mb_detect_encoding; use function mb_strtolower; /** @@ -36,6 +35,6 @@ final class Lowercase extends AbstractRule return false; } - return $input === mb_strtolower($input, (string) mb_detect_encoding($input)); + return $input === mb_strtolower($input); } } diff --git a/library/Rules/StartsWith.php b/library/Rules/StartsWith.php index 2ca46c94..bdb08894 100644 --- a/library/Rules/StartsWith.php +++ b/library/Rules/StartsWith.php @@ -14,7 +14,6 @@ declare(strict_types=1); namespace Respect\Validation\Rules; use function is_array; -use function mb_detect_encoding; use function mb_stripos; use function mb_strpos; use function reset; @@ -68,7 +67,7 @@ final class StartsWith extends AbstractRule return reset($input) == $this->startValue; } - return mb_stripos($input, $this->startValue, 0, (string) mb_detect_encoding($input)) === 0; + return mb_stripos($input, $this->startValue) === 0; } /** @@ -80,6 +79,6 @@ final class StartsWith extends AbstractRule return reset($input) === $this->startValue; } - return mb_strpos($input, $this->startValue, 0, (string) mb_detect_encoding($input)) === 0; + return mb_strpos($input, $this->startValue) === 0; } } diff --git a/library/Rules/Uppercase.php b/library/Rules/Uppercase.php index d749f1eb..bd6d8909 100644 --- a/library/Rules/Uppercase.php +++ b/library/Rules/Uppercase.php @@ -14,7 +14,6 @@ declare(strict_types=1); namespace Respect\Validation\Rules; use function is_string; -use function mb_detect_encoding; use function mb_strtoupper; /** @@ -36,6 +35,6 @@ final class Uppercase extends AbstractRule return false; } - return $input === mb_strtoupper($input, (string) mb_detect_encoding($input)); + return $input === mb_strtoupper($input); } }