From 646a5160c5a02eac8750cf76c81ab235807aaa5b Mon Sep 17 00:00:00 2001 From: "Moji (Mojtaba) Rakhisi" <20111073+mojtabaRKS@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:05:47 +0330 Subject: [PATCH] refac : replace concatenating with str use --- src/PersianValidators.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/PersianValidators.php b/src/PersianValidators.php index 19bcc42..671c803 100644 --- a/src/PersianValidators.php +++ b/src/PersianValidators.php @@ -368,11 +368,7 @@ public function validateIranianNationalCode($attribute, $value, $parameters) $sub = 0; - if (strlen($value) == 8) { - $value = '00' . $value; - } elseif (strlen($value) == 9) { - $value = '0' . $value; - } + $value = str_pad($value, 10, '0', STR_PAD_LEFT); for ($i = 0; $i <= 8; $i++) { $sub = $sub + ( $value[$i] * ( 10 - $i ) ); @@ -384,11 +380,7 @@ public function validateIranianNationalCode($attribute, $value, $parameters) $control = 11 - ( $sub % 11 ); } - if ($value[9] == $control) { - return true; - } else { - return false; - } + return (int) $value[9] === $control; } /**