From f5dd2f795e01b681866aa4e81a8221f5b2876a5d Mon Sep 17 00:00:00 2001 From: kgalanos Date: Thu, 10 Mar 2022 20:29:15 +0000 Subject: [PATCH] Fix styling --- src/CheckAfm.php | 22 +++++++++++++--------- tests/ExampleTest.php | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/CheckAfm.php b/src/CheckAfm.php index ea4a145..cdb4b1a 100644 --- a/src/CheckAfm.php +++ b/src/CheckAfm.php @@ -3,39 +3,43 @@ namespace Kgalanos\CheckAfm; class CheckAfm - { - public static function checkAfm(string $afm):self + public static function checkAfm(string $afm): self { return new static($afm); } + public function __construct(protected string $afm) { } - public function isValid() :bool + public function isValid(): bool { //The count of numbers must be 9 including 0 if afm starts with 0 - if (! (strlen($this->afm) === 9)) + if (! (strlen($this->afm) === 9)) { return false; + } $arr = str_split($this->afm); //convert char to int - for($i=0;$i<=8;$i++){ - if(! is_numeric($arr[$i])) + for ($i = 0;$i <= 8;$i++) { + if (! is_numeric($arr[$i])) { return false; + } $arr[$i] = (int) $arr[$i]; } //keep the last number $chk_num = $arr[8]; $sum = 0; //calculate the - for($i=0;$i<=7;$i++){ - $sum = $sum + $arr[$i]* 2**(8-$i); + for ($i = 0;$i <= 7;$i++) { + $sum = $sum + $arr[$i] * 2 ** (8 - $i); } $sum %= 11; $sum %= 10; - if( $chk_num !== $sum) + if ($chk_num !== $sum) { return false; + } + return true; } } diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index d52ce62..db143f2 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -1,4 +1,5 @@ isValid())->toBeTrue();