diff --git a/src/Personnummer.php b/src/Personnummer.php index 604f385..94b76c3 100644 --- a/src/Personnummer.php +++ b/src/Personnummer.php @@ -49,7 +49,7 @@ public function isMale(): bool $parts = $this->parts; $genderDigit = substr($parts['num'], -1); - return boolval($genderDigit % 2); + return (bool)($genderDigit % 2); } /** @@ -98,7 +98,7 @@ public function isCoordinationNumber(): bool { $parts = $this->parts; - return checkdate(intval($parts['month']), $parts['day'] - 60, $parts['fullYear']); + return checkdate((int)$parts['month'], $parts['day'] - 60, $parts['fullYear']); } public static function valid(string $ssn, array $options = []): bool @@ -132,7 +132,7 @@ private static function getParts(string $ssn): array $parts = array_filter($match, 'is_string', ARRAY_FILTER_USE_KEY); if (!empty($parts['century'])) { - if (date('Y') - intval(strval($parts['century']) . strval($parts['year'])) < 100) { + if (date('Y') - (int)((string)$parts['century'] . (string)$parts['year']) < 100) { $parts['sep'] = '-'; } else { $parts['sep'] = '+'; @@ -163,8 +163,9 @@ private static function luhn(string $str): int { $sum = 0; - for ($i = 0; $i < strlen($str); $i++) { - $v = intval($str[$i]); + $len = strlen($str); + for ($i = 0; $i < $len; $i++) { + $v = (int)$str[$i]; $v *= 2 - ($i % 2); if ($v > 9) { @@ -174,7 +175,7 @@ private static function luhn(string $str): int $sum += $v; } - return intval(ceil($sum / 10) * 10 - $sum); + return (int)(ceil($sum / 10) * 10 - $sum); } /** @@ -206,7 +207,7 @@ public function getAge(): int { $parts = $this->parts; - $day = intval($parts['day']); + $day = (int)$parts['day']; if ($this->isCoordinationNumber()) { $day -= 60; } @@ -257,7 +258,7 @@ private function isValid(): bool } $checkStr = $parts['year'] . $parts['month'] . $parts['day'] . $parts['num']; - $validCheck = self::luhn($checkStr) === intval($parts['check']); + $validCheck = self::luhn($checkStr) === (int)$parts['check']; return $validDate && $validCheck; } diff --git a/src/PersonnummerException.php b/src/PersonnummerException.php index 347d859..dcfa786 100644 --- a/src/PersonnummerException.php +++ b/src/PersonnummerException.php @@ -14,9 +14,9 @@ class PersonnummerException extends Exception * @param null|Exception $previous */ public function __construct( - $message = 'Invalid swedish social security number', - $code = 400, - $previous = null + string $message = 'Invalid swedish social security number', + int $code = 400, + ?Exception $previous = null ) { parent::__construct($message, $code, $previous); }