Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
kgalanos authored and actions-user committed Mar 10, 2022
1 parent 228f4c0 commit f5dd2f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/CheckAfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

require_once __DIR__ . "/../vendor/autoload.php";
it('afm is Valid - 1', function () {
expect(\Kgalanos\CheckAfm\CheckAfm::checkAfm('011111111')->isValid())->toBeTrue();
Expand Down

0 comments on commit f5dd2f7

Please sign in to comment.