diff --git a/autoloader/index/0.php b/autoloader/index/0.php index e7b8cf5..47ec1ed 100644 --- a/autoloader/index/0.php +++ b/autoloader/index/0.php @@ -171,6 +171,8 @@ 'malkusch\bav\validatord9' => '../classes/validator/validators/ValidatorD9.php', 'malkusch\bav\validatore0' => '../classes/validator/validators/ValidatorE0.php', 'malkusch\bav\validatore1' => '../classes/validator/validators/ValidatorE1.php', + 'malkusch\bav\validatore2' => '../classes/validator/validators/ValidatorE2.php', + 'malkusch\bav\validatore3' => '../classes/validator/validators/ValidatorE3.php', 'malkusch\bav\domuripicker' => '../classes/dataBackend/file/download/uripicker/DOMURIPicker.php', 'malkusch\bav\bavexception' => '../classes/exception/BAVException.php', 'malkusch\bav\validator51x' => '../classes/validator/validators/Validator51x.php', diff --git a/classes/BAV.php b/classes/BAV.php index d52e63f..916b5c6 100644 --- a/classes/BAV.php +++ b/classes/BAV.php @@ -29,7 +29,7 @@ class BAV * @var DataBackend */ private $backend; - + /** * @var ContextValidation */ @@ -43,7 +43,7 @@ class BAV * * @see ConfigurationRegistry */ - public function __construct(Configuration $configuration = null) + public function __construct(?Configuration $configuration = null) { if (is_null($configuration)) { $configuration = ConfigurationRegistry::getConfiguration(); @@ -52,7 +52,7 @@ public function __construct(Configuration $configuration = null) $this->configuration = $configuration; $this->backend = $configuration->getDataBackendContainer()->getDataBackend(); - + $this->contextValidation = new ContextValidation($this->backend); } @@ -133,7 +133,7 @@ public function isValidBank($bankID) { return $this->contextValidation->isValidBank($bankID); } - + /** * Every bank has one main agency. * @@ -165,7 +165,7 @@ public function getAgencies($bankID) { return $this->getBank($bankID)->getAgencies(); } - + /** * With this method you get the Bank objects for certain IDs. Note * that a call to this method with an identical id will return the same @@ -203,7 +203,7 @@ public function isValidBIC($bic) { return $this->backend->isValidBIC(BICUtil::normalize($bic)); } - + /** * Returns the third call back parameter for filter_var() for validating * a bank. @@ -218,7 +218,7 @@ public function getValidBankFilterCallback() { return $this->contextValidation->getValidBankFilterCallback(); } - + /** * Returns the third call back parameter for filter_var() for validating * a bank account. diff --git a/classes/configuration/Configuration.php b/classes/configuration/Configuration.php index 6302367..c16e5f8 100644 --- a/classes/configuration/Configuration.php +++ b/classes/configuration/Configuration.php @@ -44,7 +44,7 @@ class Configuration * * Set to null if you don't want to use an update plan. */ - public function setUpdatePlan(UpdatePlan $updatePlan = null) + public function setUpdatePlan(?UpdatePlan $updatePlan = null) { $this->updatePlan = $updatePlan; } @@ -100,7 +100,7 @@ public function getDataBackendContainer() { return $this->backendContainer; } - + /** * Sets the encoding. */ diff --git a/classes/dataBackend/file/FileDataBackend.php b/classes/dataBackend/file/FileDataBackend.php index 4be6d60..b85894e 100644 --- a/classes/dataBackend/file/FileDataBackend.php +++ b/classes/dataBackend/file/FileDataBackend.php @@ -16,9 +16,12 @@ */ class FileDataBackend extends DataBackend { - + // @codingStandardsIgnoreStart - const DOWNLOAD_URI = "http://www.bundesbank.de/Redaktion/DE/Standardartikel/Aufgaben/Unbarer_Zahlungsverkehr/bankleitzahlen_download.html"; + // The parent contains something like this: + // https://www.bundesbank.de/resource/blob/602632/31fec41357f012d537ce62045395929a/mL/blz-aktuell-txt-data.txt + const DOWNLOAD_BASE_URI = "https://www.bundesbank.de"; + const DOWNLOAD_PARENT_URI= self::DOWNLOAD_BASE_URI . "/de/aufgaben/unbarer-zahlungsverkehr/serviceangebot/bankleitzahlen/download-bankleitzahlen-602592"; // @codingStandardsIgnoreEnd /** @@ -30,7 +33,7 @@ class FileDataBackend extends DataBackend * @var FileParser */ private $parser; - + /** * @var Index_FixedSize */ @@ -49,7 +52,7 @@ public function __construct($file = null) $this->parser = new FileParser($file); $this->fileUtil = new FileUtil(); } - + /** * @return FixedSizeIndex */ @@ -61,7 +64,7 @@ private function getIndex() FileParser::BANKID_OFFSET, FileParser::BANKID_LENGTH ); - + } return $this->index; } @@ -159,34 +162,19 @@ public function install() public function update() { $downloader = new Downloader(); - $content = $downloader->downloadContent(self::DOWNLOAD_URI); - - $uriPicker = new FallbackURIPicker(); - $path = $uriPicker->pickURI($content); - - if (strlen($path) > 0 && $path{0} != "/") { - $path = sprintf("/%s/%s", dirname(self::DOWNLOAD_URI), $path); - } - $pathParts = explode('/', $path); - foreach ($pathParts as $i => $part) { - switch ($part) { - case '..': - unset($pathParts[$i-1]); - // fall-through as the current part ("..") should be removed as well. - - case '.': - unset($pathParts[$i]); - break; + $parentContent = $downloader->downloadContent(self::DOWNLOAD_PARENT_URI); + if (preg_match('|href="([^"]+/blz-aktuell-txt-data.txt)"|', $parentContent, $matches)) { + $downloadUri = $matches[1]; + if (!str_starts_with($downloadUri, 'https://')) { + $downloadUri = self::DOWNLOAD_BASE_URI . $downloadUri; } - + } else { + throw new DownloaderException("Failed opening parent page " . self::DOWNLOAD_PARENT_URI . " containing download-uri"); } - $path = implode('/', $pathParts); - $urlParts = parse_url(self::DOWNLOAD_URI); - $url = sprintf("%s://%s%s", $urlParts["scheme"], $urlParts["host"], $path); // download file - $file = $downloader->downloadFile($url); + $file = $downloader->downloadFile($downloadUri); // Validate file format. $validator = new FileValidator(); @@ -245,7 +233,7 @@ public function getNewBank($bankID) { try { $result = $this->getIndex()->search($bankID); - + if ($result == null) { throw new BankNotFoundException($bankID); @@ -261,7 +249,7 @@ public function getNewBank($bankID) } catch (IndexException $e) { throw new DataBackendIOException($e->getMessage(), $e->getCode(), $e); - + } } @@ -419,7 +407,7 @@ public function getBICAgencies($bic) } return $agencies; } - + public function free() { parent::free(); diff --git a/classes/dataBackend/file/download/Downloader.php b/classes/dataBackend/file/download/Downloader.php index 283c5e2..d9eeca7 100644 --- a/classes/dataBackend/file/download/Downloader.php +++ b/classes/dataBackend/file/download/Downloader.php @@ -25,7 +25,7 @@ class Downloader public function __construct() { $this->handle = curl_init(); - if (! is_resource($this->handle)) { + if (! is_resource($this->handle) && !($this->handle instanceof \CurlHandle)) { throw new DownloaderException("Failed initializing curl"); } @@ -92,6 +92,7 @@ public function downloadFile($uri) } curl_setopt($this->handle, CURLOPT_FILE, $fp); + curl_setopt($this->handle, CURLOPT_FOLLOWLOCATION, 1); if (! $this->download($uri)) { fclose($fp); diff --git a/classes/dataBackend/pdo/PDODataBackend.php b/classes/dataBackend/pdo/PDODataBackend.php index 72bfb83..c2617be 100644 --- a/classes/dataBackend/pdo/PDODataBackend.php +++ b/classes/dataBackend/pdo/PDODataBackend.php @@ -524,7 +524,7 @@ public function getLastUpdate() } catch (\PDOException $e) { $stmt->closeCursor(); - throw new DataBackendIOException($e->getMessage(), $e->getCode(), $e); + throw new DataBackendIOException($e->getMessage(), (int)$e->getCode(), $e); } } @@ -538,37 +538,15 @@ public function getLastUpdate() public function isInstalled() { try { - switch ($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) { - case "sqlite": - $query = - "SELECT count(*) FROM sqlite_master - WHERE type='table' AND name = '{$this->prefix}meta'"; - break; - - default: - $query = - "SELECT CASE WHEN EXISTS( - (SELECT * FROM information_schema.tables - WHERE table_name='{$this->prefix}meta') - ) THEN 1 ELSE 0 END"; - break; - - } - + $query = "SELECT COUNT(*) FROM {$this->prefix}meta"; $stmt = $this->statementContainer->prepare($query); $stmt->execute(); $result = $stmt->fetch(); - if ($result === false) { - throw new DataBackendException(); - - } $stmt->closeCursor(); - return $result[0] == 1; - + return !($result === false); } catch (\PDOException $e) { $stmt->closeCursor(); - throw new DataBackendIOException($e->getMessage(), 0, $e); - + return false; } } diff --git a/classes/validator/Validator.php b/classes/validator/Validator.php index a7ea34c..4f088c6 100644 --- a/classes/validator/Validator.php +++ b/classes/validator/Validator.php @@ -74,7 +74,7 @@ protected function checkType($account) { if (is_string($account)) { return; - + } trigger_error( "Only validation of strings are defined." @@ -82,7 +82,7 @@ protected function checkType($account) E_USER_WARNING ); } - + /** * Validates a bank account. * @@ -101,7 +101,7 @@ public function isValid($account) try { if ($account == null) { return false; - + } $this->checkType($account); $this->init($account); @@ -148,7 +148,7 @@ abstract protected function getResult(); */ protected function getChecknumber() { - return $this->account{$this->getNormalizedPosition($this->checknumberPosition)}; + return $this->account[$this->getNormalizedPosition($this->checknumberPosition)]; } /** @@ -184,7 +184,7 @@ protected function crossSum($int) $str_int = (string) $int; for ($i = 0; $i < strlen($str_int); $i++) { //$sum = bcadd($str_int{$i}, $sum); - $sum += $str_int{$i}; + $sum += $str_int[$i]; } return $sum; @@ -217,7 +217,7 @@ protected function getESER8() } $bankID = $this->bank->getBankID(); - if ($bankID{3} != 5) { + if ($bankID[3] != 5) { throw new ValidatorESERException(); } @@ -230,7 +230,7 @@ protected function getESER8() } $accountPart = ltrim(substr($account, 2), '0'); - $eser = $blzPart.$account{0}.$account{1}.$accountPart; + $eser = $blzPart.$account[0].$account[1].$accountPart; return $eser; } @@ -249,7 +249,7 @@ protected function getESER9() throw new ValidatorESERException(); } - if ($bankID{3} != 5) { + if ($bankID[3] != 5) { throw new ValidatorESERException(); } @@ -257,9 +257,9 @@ protected function getESER9() $blzPart0 = substr($bankID, -4, 2); $blzPart1 = substr($bankID, -1); - $accountPart0 = $account{0}; - $t = $account{1}; - $p = $account{2}; + $accountPart0 = $account[0]; + $t = $account[1]; + $p = $account[2]; $accountTail = ltrim(substr($account, 3), '0'); $eser = $blzPart0.$t.$blzPart1.$accountPart0.$p.$accountTail; @@ -273,7 +273,7 @@ protected function getEserChecknumberPosition() protected function getEserChecknumber() { - return $this->account{$this->getEserChecknumberPosition()}; + return $this->account[$this->getEserChecknumberPosition()]; } protected function isBetween($a, $b) diff --git a/classes/validator/ValidatorIteration.php b/classes/validator/ValidatorIteration.php index 20832d2..ee069a5 100644 --- a/classes/validator/ValidatorIteration.php +++ b/classes/validator/ValidatorIteration.php @@ -104,7 +104,7 @@ protected function validate() for ($this->i = 0; $this->i < $length; $this->i++) { - $this->number = (int)$this->account{$this->position}; + $this->number = (int)$this->account[$this->position]; $this->iterationStep(); $this->position += $stepping; diff --git a/classes/validator/validators/Validator16.php b/classes/validator/validators/Validator16.php index e7b47e3..3a8d551 100644 --- a/classes/validator/validators/Validator16.php +++ b/classes/validator/validators/Validator16.php @@ -34,7 +34,7 @@ public function __construct(Bank $bank) protected function getResult() { return $this->accumulator % 11 === 1 - ? $this->getChecknumber() === $this->account{$this->getNormalizedPosition($this->checknumberPosition) - 1} + ? $this->getChecknumber() === $this->account[$this->getNormalizedPosition($this->checknumberPosition) - 1] : parent::getResult(); } } diff --git a/classes/validator/validators/Validator25.php b/classes/validator/validators/Validator25.php index 6e9bbc7..bf74dd7 100644 --- a/classes/validator/validators/Validator25.php +++ b/classes/validator/validators/Validator25.php @@ -40,9 +40,10 @@ protected function getResult() { $result = 11 - ($this->accumulator % 11); switch ($result) { + case 10: $result = 0; - if ($this->account{1} != 8 && $this->account{1} != 9) { + if ($this->account[1] != 8 && $this->account[1] != 9) { return false; } diff --git a/classes/validator/validators/Validator35.php b/classes/validator/validators/Validator35.php index 261dd3e..c2185e6 100644 --- a/classes/validator/validators/Validator35.php +++ b/classes/validator/validators/Validator35.php @@ -40,7 +40,7 @@ protected function getResult() { $result = $this->accumulator % 11; if ($result === 10) { - return $this->account{9} === $this->account{8}; + return $this->account[9] === $this->account[8]; } return (string)$result === $this->getCheckNumber(); diff --git a/classes/validator/validators/Validator41.php b/classes/validator/validators/Validator41.php index 728330e..ad03dec 100644 --- a/classes/validator/validators/Validator41.php +++ b/classes/validator/validators/Validator41.php @@ -35,7 +35,7 @@ protected function init($account) { parent::init($account); - if ($this->account{3} == 9) { + if ($this->account[3] == 9) { $this->setEnd(3); } else { diff --git a/classes/validator/validators/Validator45.php b/classes/validator/validators/Validator45.php index faf778a..0bf4bed 100644 --- a/classes/validator/validators/Validator45.php +++ b/classes/validator/validators/Validator45.php @@ -36,8 +36,8 @@ public function __construct(Bank $bank) */ protected function getResult() { - return $this->account{0} === '0' - || $this->account{4} === '1' + return $this->account[0] === '0' + || $this->account[4] === '1' || parent::getResult(); } } diff --git a/classes/validator/validators/Validator51.php b/classes/validator/validators/Validator51.php index 3f0e2a9..14d7dc6 100644 --- a/classes/validator/validators/Validator51.php +++ b/classes/validator/validators/Validator51.php @@ -93,7 +93,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? $this->exceptionValidators : $this->defaultValidators; } @@ -104,7 +104,7 @@ protected function continueValidation(Validator $validator) return true; } - switch ($this->account{9}) { + switch ($this->account[9]) { case 7: case 8: case 9: diff --git a/classes/validator/validators/Validator52.php b/classes/validator/validators/Validator52.php index 346ed29..ca552f5 100644 --- a/classes/validator/validators/Validator52.php +++ b/classes/validator/validators/Validator52.php @@ -49,7 +49,7 @@ public function __construct(Bank $bank) public function isValid($account) { try { - return strlen($account) == 10 && $account{0} == 9 + return strlen($account) == 10 && $account[0] == 9 ? $this->validator20->isValid($account) : parent::isValid($account); diff --git a/classes/validator/validators/Validator56.php b/classes/validator/validators/Validator56.php index a6a1a99..654bd77 100644 --- a/classes/validator/validators/Validator56.php +++ b/classes/validator/validators/Validator56.php @@ -39,7 +39,7 @@ protected function iterationStep() protected function getResult() { $result = 11 - ($this->accumulator % 11); - if ($this->account{0} == 9 && $result >= 10) { + if ($this->account[0] == 9 && $result >= 10) { $result -= 3; } diff --git a/classes/validator/validators/Validator61.php b/classes/validator/validators/Validator61.php index ffe562c..c9f4322 100644 --- a/classes/validator/validators/Validator61.php +++ b/classes/validator/validators/Validator61.php @@ -37,7 +37,7 @@ public function init($account) parent::init($account); - if ($this->account{8} == 8) { + if ($this->account[8] == 8) { $this->setWeights(array(2, 1, 2, 1, 2, 1, 2, 0, 1, 2)); $this->setEnd(-1); diff --git a/classes/validator/validators/Validator63.php b/classes/validator/validators/Validator63.php index 2900ef5..c916b9a 100644 --- a/classes/validator/validators/Validator63.php +++ b/classes/validator/validators/Validator63.php @@ -55,6 +55,6 @@ protected function iterationStep() protected function getResult() { $result = (10 - ($this->accumulator % 10)) % 10; - return $this->account{0} == '0' && (string)$result === $this->getCheckNumber(); + return $this->account[0] == '0' && (string)$result === $this->getCheckNumber(); } } diff --git a/classes/validator/validators/Validator65.php b/classes/validator/validators/Validator65.php index 14c1024..8080e97 100644 --- a/classes/validator/validators/Validator65.php +++ b/classes/validator/validators/Validator65.php @@ -37,7 +37,7 @@ protected function init($account) { parent::init($account); - if ($this->account{8} == 9) { + if ($this->account[8] == 9) { $this->setEnd(-1); } else { diff --git a/classes/validator/validators/Validator66.php b/classes/validator/validators/Validator66.php index 742d27f..91054bf 100644 --- a/classes/validator/validators/Validator66.php +++ b/classes/validator/validators/Validator66.php @@ -41,11 +41,11 @@ protected function iterationStep() protected function getResult() { // update 2014-03-03 - if ($this->account{1} == '9') { + if ($this->account[1] == '9') { return true; } $result = (11 - $this->accumulator % 11) % 10; - return $this->account{0} == '0' && (string)$result === $this->getCheckNumber(); + return $this->account[0] == '0' && (string)$result === $this->getCheckNumber(); } } diff --git a/classes/validator/validators/Validator68.php b/classes/validator/validators/Validator68.php index 05245d5..18e56cd 100644 --- a/classes/validator/validators/Validator68.php +++ b/classes/validator/validators/Validator68.php @@ -60,8 +60,9 @@ protected function init($account) protected function getResult() { switch (strlen($this->account)) { + case 10: - return $this->account{3} == 9 && $this->validator10->isValid($this->account); + return $this->account[3] == 9 && $this->validator10->isValid($this->account); case 9: if ($this->account >= 400000000 && $this->account <= 499999999) { diff --git a/classes/validator/validators/Validator70.php b/classes/validator/validators/Validator70.php index b55d4fb..412ab28 100644 --- a/classes/validator/validators/Validator70.php +++ b/classes/validator/validators/Validator70.php @@ -33,7 +33,7 @@ public function __construct(Bank $bank) protected function iterationStep() { - if ($this->position <= 2 && ($this->account{3} == 5 || substr($this->account, 3, 2) == 69)) { + if ($this->position <= 2 && ($this->account[3] == 5 || substr($this->account, 3, 2) == 69)) { return; } diff --git a/classes/validator/validators/Validator73.php b/classes/validator/validators/Validator73.php index 82a46c4..e0306b3 100644 --- a/classes/validator/validators/Validator73.php +++ b/classes/validator/validators/Validator73.php @@ -59,7 +59,7 @@ protected function init($account) { parent::init($account); - if ($this->account{2} == 9) { + if ($this->account[2] == 9) { $this->validators = $this->exceptionValidators; } else { diff --git a/classes/validator/validators/Validator74.php b/classes/validator/validators/Validator74.php index 2006d39..6b3d5d6 100644 --- a/classes/validator/validators/Validator74.php +++ b/classes/validator/validators/Validator74.php @@ -37,18 +37,30 @@ public function isValid($account) } protected function getResult() + { + return $this->variantOne() || $this->variantTwo(); + } + + private function variantOne() { if (parent::getResult()) { return true; - } elseif (strlen(ltrim($this->account, '0')) == 6) { - $nextHalfDecade = round($this->accumulator/10) * 10 + 5; - $check = ($nextHalfDecade - $this->accumulator) % 10; - return (string) $check === $this->getChecknumber(); - - } else { - return false; + $nextHalfDecade = round($this->accumulator / 10) * 10 + 5; + $check = ($nextHalfDecade - $this->accumulator) % 10; + return (string)$check === $this->getChecknumber(); } + + return false; + } + + private function variantTwo() + { + $validator = new Validator04($this->bank); + $validator->setWeights([2, 3, 4, 5, 6, 7, 2, 3, 4]); + $validator->setDivisor(11); + + return $validator->isValid($this->account); } -} +} \ No newline at end of file diff --git a/classes/validator/validators/Validator75.php b/classes/validator/validators/Validator75.php index 1231341..fa27972 100644 --- a/classes/validator/validators/Validator75.php +++ b/classes/validator/validators/Validator75.php @@ -45,7 +45,7 @@ public function isValid($account) } if ($length == 9) { - if ($account{0} == 9) { + if ($account[0] == 9) { $account = substr($account, 1, 6); } else { diff --git a/classes/validator/validators/Validator76.php b/classes/validator/validators/Validator76.php index 6f84846..f4d6801 100644 --- a/classes/validator/validators/Validator76.php +++ b/classes/validator/validators/Validator76.php @@ -57,7 +57,7 @@ protected function iterationStep() protected function getResult() { $result = $this->accumulator % 11; - return array_search((int)$this->account{0}, array(0, 4, 6, 7, 8, 9)) !== false + return array_search((int)$this->account[0], array(0, 4, 6, 7, 8, 9)) !== false && $result != 10 && (string)$result === $this->getCheckNumber(); } diff --git a/classes/validator/validators/Validator79.php b/classes/validator/validators/Validator79.php index 0931624..a3973a7 100644 --- a/classes/validator/validators/Validator79.php +++ b/classes/validator/validators/Validator79.php @@ -63,10 +63,10 @@ protected function init($account) protected function validate() { - if (array_search($this->account{0}, array(1, 2, 9)) !== false) { + if (array_search($this->account[0], array(1, 2, 9)) !== false) { $this->validator = $this->mode2; - } elseif ($this->account{0} == 0) { + } elseif ($this->account[0] == 0) { $this->validator = null; } else { diff --git a/classes/validator/validators/Validator80.php b/classes/validator/validators/Validator80.php index e852e93..16f4e7b 100644 --- a/classes/validator/validators/Validator80.php +++ b/classes/validator/validators/Validator80.php @@ -54,7 +54,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? $this->exceptionValidators : $this->defaultValidators; } diff --git a/classes/validator/validators/Validator81.php b/classes/validator/validators/Validator81.php index fd4ae39..3e8663a 100644 --- a/classes/validator/validators/Validator81.php +++ b/classes/validator/validators/Validator81.php @@ -50,7 +50,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? $this->exceptionValidators : $this->defaultValidators; } diff --git a/classes/validator/validators/Validator83.php b/classes/validator/validators/Validator83.php index 1fd435c..c76b387 100644 --- a/classes/validator/validators/Validator83.php +++ b/classes/validator/validators/Validator83.php @@ -73,6 +73,6 @@ protected function init($account) protected function continueValidation(Validator $validator) { - return $validator !== $this->modeC || $this->account{9} < 7; + return $validator !== $this->modeC || $this->account[9] < 7; } } diff --git a/classes/validator/validators/Validator84.php b/classes/validator/validators/Validator84.php index 4824949..f69c0c9 100644 --- a/classes/validator/validators/Validator84.php +++ b/classes/validator/validators/Validator84.php @@ -59,7 +59,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? $this->exceptionValidators : $this->defaultValidators; } diff --git a/classes/validator/validators/Validator85.php b/classes/validator/validators/Validator85.php index 69b8d44..42f89a0 100644 --- a/classes/validator/validators/Validator85.php +++ b/classes/validator/validators/Validator85.php @@ -75,6 +75,6 @@ protected function init($account) protected function continueValidation(Validator $validator) { - return $validator !== $this->modeC || $this->account{9} < 7; + return $validator !== $this->modeC || $this->account[9] < 7; } } diff --git a/classes/validator/validators/Validator86.php b/classes/validator/validators/Validator86.php index 082518b..a6ef028 100644 --- a/classes/validator/validators/Validator86.php +++ b/classes/validator/validators/Validator86.php @@ -55,7 +55,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? $this->exceptionValidators : $this->defaultValidators; } diff --git a/classes/validator/validators/Validator87.php b/classes/validator/validators/Validator87.php index 48dcff8..3cbd8a0 100644 --- a/classes/validator/validators/Validator87.php +++ b/classes/validator/validators/Validator87.php @@ -59,7 +59,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? $this->exceptionValidators : $this->defaultValidators; } diff --git a/classes/validator/validators/Validator87a.php b/classes/validator/validators/Validator87a.php index 1790aab..4b77ce3 100644 --- a/classes/validator/validators/Validator87a.php +++ b/classes/validator/validators/Validator87a.php @@ -40,7 +40,6 @@ protected function validate() */ protected function getResult() { - $accountID = $this->account; $i = 0; $c2 = 0; $d2 = 0; @@ -50,8 +49,8 @@ protected function getResult() $tab2 = array(7, 1, 5, 9, 8); $konto = array(); - for ($i = 0; $i < strlen($accountID); $i++) { - $konto[$i+1] = $accountID{$i}; + for ($i = 0; $i < strlen($this->account); $i++) { + $konto[$i+1] = $this->account[$i]; } $i = 4; @@ -63,17 +62,13 @@ protected function getResult() while ($i < 10) { switch ($konto[$i]) { - case 0: - $konto[$i] = 5; + case 0: $konto[$i] = 5; break; - case 1: - $konto[$i] = 6; + case 1: $konto[$i] = 6; break; - case 5: - $konto[$i] = 10; + case 5: $konto[$i] = 10; break; - case 6: - $konto[$i] = 1; + case 6: $konto[$i] = 1; break; } diff --git a/classes/validator/validators/Validator88.php b/classes/validator/validators/Validator88.php index 19f4bc3..180bd38 100644 --- a/classes/validator/validators/Validator88.php +++ b/classes/validator/validators/Validator88.php @@ -36,6 +36,6 @@ protected function init($account) { parent::init($account); - $this->setEnd($this->account{2} == 9 ? 2: 3); + $this->setEnd($this->account[2] == 9 ? 2: 3); } } diff --git a/classes/validator/validators/Validator90.php b/classes/validator/validators/Validator90.php index 5ca298c..e10c46b 100644 --- a/classes/validator/validators/Validator90.php +++ b/classes/validator/validators/Validator90.php @@ -63,7 +63,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? array($this->modeF) : $this->defaultValidators; } diff --git a/classes/validator/validators/Validator90c.php b/classes/validator/validators/Validator90c.php index c39acbe..a9f6f7d 100644 --- a/classes/validator/validators/Validator90c.php +++ b/classes/validator/validators/Validator90c.php @@ -43,6 +43,6 @@ protected function getResult() $result = $result == 7 ? 0 : $result % 10; - return $this->account{9} < 7 && (string)$result === $this->getCheckNumber(); + return $this->account[9] < 7 && (string)$result === $this->getCheckNumber(); } } diff --git a/classes/validator/validators/Validator90d.php b/classes/validator/validators/Validator90d.php index 3d6227a..f1868eb 100644 --- a/classes/validator/validators/Validator90d.php +++ b/classes/validator/validators/Validator90d.php @@ -43,6 +43,6 @@ protected function getResult() $result = $result == 9 ? 0 : $result % 10; - return $this->account{9} != 9 && (string)$result === $this->getCheckNumber(); + return $this->account[9] != 9 && (string)$result === $this->getCheckNumber(); } } diff --git a/classes/validator/validators/ValidatorA5.php b/classes/validator/validators/ValidatorA5.php index 7e71356..4ee2e28 100644 --- a/classes/validator/validators/ValidatorA5.php +++ b/classes/validator/validators/ValidatorA5.php @@ -38,7 +38,7 @@ public function __construct(Bank $bank) protected function continueValidation(Validator $validator) { if ($validator === $this->validators[1]) { - return $this->account{0} !== '9'; + return $this->account[0] !== '9'; } return true; diff --git a/classes/validator/validators/ValidatorA6.php b/classes/validator/validators/ValidatorA6.php index e33d914..7e0195a 100644 --- a/classes/validator/validators/ValidatorA6.php +++ b/classes/validator/validators/ValidatorA6.php @@ -57,7 +57,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = $this->account{1} === '8' + $this->validator = $this->account[1] === '8' ? $this->mode1 : $this->mode2; } diff --git a/classes/validator/validators/ValidatorA8.php b/classes/validator/validators/ValidatorA8.php index 815303f..c4b9721 100644 --- a/classes/validator/validators/ValidatorA8.php +++ b/classes/validator/validators/ValidatorA8.php @@ -63,7 +63,7 @@ protected function init($account) { parent::init($account); - $this->validators = $this->account{2} == 9 + $this->validators = $this->account[2] == 9 ? $this->exceptionValidators : $this->defaultValidators; } diff --git a/classes/validator/validators/ValidatorB0.php b/classes/validator/validators/ValidatorB0.php index 03aad10..5104b62 100644 --- a/classes/validator/validators/ValidatorB0.php +++ b/classes/validator/validators/ValidatorB0.php @@ -56,7 +56,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = array_search($this->account{7}, array(1, 2, 3, 6)) !== false + $this->validator = array_search($this->account[7], array(1, 2, 3, 6)) !== false ? $this->mode1 : $this->mode2; } @@ -67,7 +67,7 @@ protected function validate() protected function getResult() { return strlen(ltrim($this->account, '0')) === 10 - && $this->account{0} !== '8' + && $this->account[0] !== '8' && $this->validator->isValid($this->account); } } diff --git a/classes/validator/validators/ValidatorB1.php b/classes/validator/validators/ValidatorB1.php index f9d4f05..27246c9 100644 --- a/classes/validator/validators/ValidatorB1.php +++ b/classes/validator/validators/ValidatorB1.php @@ -29,9 +29,7 @@ public function __construct(Bank $bank) parent::__construct($bank); $this->validators[] = new Validator05($bank); - $this->validators[0]->setWeights(array(7, 3, 1)); - $this->validators[] = new Validator01($bank); - $this->validators[1]->setWeights(array(3, 7, 1)); + $this->validators[] = new Validator00($bank); } -} +} \ No newline at end of file diff --git a/classes/validator/validators/ValidatorB2.php b/classes/validator/validators/ValidatorB2.php index f81deee..8a6d2af 100644 --- a/classes/validator/validators/ValidatorB2.php +++ b/classes/validator/validators/ValidatorB2.php @@ -57,7 +57,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = $this->account{0} <= 7 + $this->validator = $this->account[0] <= 7 ? $this->mode1 : $this->mode2; } diff --git a/classes/validator/validators/ValidatorB3.php b/classes/validator/validators/ValidatorB3.php index 36fe3c8..2ddfacd 100644 --- a/classes/validator/validators/ValidatorB3.php +++ b/classes/validator/validators/ValidatorB3.php @@ -57,7 +57,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = $this->account{0} != 9 + $this->validator = $this->account[0] != 9 ? $this->mode1 : $this->mode2; } diff --git a/classes/validator/validators/ValidatorB4.php b/classes/validator/validators/ValidatorB4.php index ac2418f..fed53cd 100644 --- a/classes/validator/validators/ValidatorB4.php +++ b/classes/validator/validators/ValidatorB4.php @@ -57,7 +57,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = $this->account{0} == 9 + $this->validator = $this->account[0] == 9 ? $this->mode1 : $this->mode2; } diff --git a/classes/validator/validators/ValidatorB5.php b/classes/validator/validators/ValidatorB5.php index cc6c4e4..1f56eca 100644 --- a/classes/validator/validators/ValidatorB5.php +++ b/classes/validator/validators/ValidatorB5.php @@ -41,7 +41,7 @@ public function __construct(Bank $bank) protected function continueValidation(Validator $validator) { if ($validator === $this->validators[1]) { - return $this->account{0} < 8; + return $this->account[0] < 8; } return true; diff --git a/classes/validator/validators/ValidatorB6.php b/classes/validator/validators/ValidatorB6.php index 025cc55..84554f6 100644 --- a/classes/validator/validators/ValidatorB6.php +++ b/classes/validator/validators/ValidatorB6.php @@ -57,7 +57,7 @@ public function __construct(Bank $bank) protected function validate() { - if ($this->account{0} !== '0' || preg_match("/^0269[1-9]/", $this->account)) { + if ($this->account[0] !== '0' || preg_match("/^0269[1-9]/", $this->account)) { $this->validator = $this->mode1; } else { diff --git a/classes/validator/validators/ValidatorC1.php b/classes/validator/validators/ValidatorC1.php index 2e1d7f6..547fc41 100644 --- a/classes/validator/validators/ValidatorC1.php +++ b/classes/validator/validators/ValidatorC1.php @@ -56,7 +56,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = $this->account{0} != '5' + $this->validator = $this->account[0] != '5' ? $this->mode1 : $this->mode2; } diff --git a/classes/validator/validators/ValidatorC3.php b/classes/validator/validators/ValidatorC3.php index bf312f5..ce07838 100644 --- a/classes/validator/validators/ValidatorC3.php +++ b/classes/validator/validators/ValidatorC3.php @@ -57,7 +57,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = $this->account{0} != '9' + $this->validator = $this->account[0] != '9' ? $this->mode1 : $this->mode2; } diff --git a/classes/validator/validators/ValidatorC4.php b/classes/validator/validators/ValidatorC4.php index bea79de..216213d 100644 --- a/classes/validator/validators/ValidatorC4.php +++ b/classes/validator/validators/ValidatorC4.php @@ -57,7 +57,7 @@ public function __construct(Bank $bank) protected function validate() { - $this->validator = $this->account{0} != '9' + $this->validator = $this->account[0] != '9' ? $this->mode1 : $this->mode2; } diff --git a/classes/validator/validators/ValidatorC5.php b/classes/validator/validators/ValidatorC5.php index 7fba790..ad38f5e 100644 --- a/classes/validator/validators/ValidatorC5.php +++ b/classes/validator/validators/ValidatorC5.php @@ -70,25 +70,26 @@ protected function validate() $length = strlen($account); switch ($length) { + case 6: case 9: - if ($account{0} < 9) { + if ($account[0] < 9) { $this->validator = $this->mode1; } break; case 8: - if ($account{0} >= 3 && $account{0} <= 5) { + if ($account[0] >= 3 && $account[0] <= 5) { $this->validator = $this->mode4; } break; case 10: - if ($account{0} == 1 || $account{0} >= 4 && $account{0} <= 6 || $account{0} == 9) { + if ($account[0] == 1 || $account[0] >= 4 && $account[0] <= 6 || $account[0] == 9) { $this->validator = $this->mode2; - } elseif ($account{0} == 3) { + } elseif ($account[0] == 3) { $this->validator = $this->mode3; } else { diff --git a/classes/validator/validators/ValidatorC6.php b/classes/validator/validators/ValidatorC6.php index bf6253a..8c5862f 100644 --- a/classes/validator/validators/ValidatorC6.php +++ b/classes/validator/validators/ValidatorC6.php @@ -64,8 +64,8 @@ public function __construct(Bank $bank) protected function validate() { - $transformation = array_key_exists($this->account{0}, self::$transformation) - ? self::$transformation[$this->account{0}] + $transformation = array_key_exists($this->account[0], self::$transformation) + ? self::$transformation[$this->account[0]] : ''; $this->transformedAccount = $transformation . substr($this->account, 1); $this->validator->setNormalizedSize(9 + strlen($transformation)); @@ -76,7 +76,7 @@ protected function validate() */ protected function getResult() { - return in_array($this->account{0}, array_keys(self::$transformation)) + return in_array($this->account[0], array_keys(self::$transformation)) ? $this->validator->isValid($this->transformedAccount) : false; } diff --git a/classes/validator/validators/ValidatorD1.php b/classes/validator/validators/ValidatorD1.php index 9d7d964..6f74647 100644 --- a/classes/validator/validators/ValidatorD1.php +++ b/classes/validator/validators/ValidatorD1.php @@ -93,6 +93,6 @@ protected function getResult() */ private function getTransformationIndex() { - return $this->account{0}; + return $this->account[0]; } } diff --git a/classes/validator/validators/ValidatorD4.php b/classes/validator/validators/ValidatorD4.php index ebc328f..7b0bc54 100644 --- a/classes/validator/validators/ValidatorD4.php +++ b/classes/validator/validators/ValidatorD4.php @@ -61,7 +61,7 @@ protected function validate() */ protected function getResult() { - return $this->account{0} != 0 + return $this->account[0] != 0 && $this->validator->isValid($this->transformedAccount); } } diff --git a/classes/validator/validators/ValidatorD8.php b/classes/validator/validators/ValidatorD8.php index 0b2b6e5..293c0a4 100644 --- a/classes/validator/validators/ValidatorD8.php +++ b/classes/validator/validators/ValidatorD8.php @@ -53,7 +53,7 @@ protected function validate() */ protected function getResult() { - if ($this->account{0} != 0) { + if ($this->account[0] != 0) { return $this->validator->isValid($this->account); } diff --git a/classes/validator/validators/ValidatorE2.php b/classes/validator/validators/ValidatorE2.php index b615be3..8fc16d5 100644 --- a/classes/validator/validators/ValidatorE2.php +++ b/classes/validator/validators/ValidatorE2.php @@ -43,7 +43,7 @@ class ValidatorE2 extends Validator protected function validate() { - if (in_array($this->account{0}, [6, 7, 8, 9])) { + if (in_array($this->account[0], [6, 7, 8, 9])) { $this->result = false; return; } @@ -51,7 +51,7 @@ protected function validate() $validator = new Validator00($this->bank); $validator->doNormalization = false; - $prefixedAccount = self::$prefixes[$this->account{0}] . substr($this->account, 1); + $prefixedAccount = self::$prefixes[$this->account[0]] . substr($this->account, 1); $this->result = $validator->isValid($prefixedAccount); } diff --git a/classes/validator/validators/ValidatorE3.php b/classes/validator/validators/ValidatorE3.php new file mode 100644 index 0000000..1a2f3bc --- /dev/null +++ b/classes/validator/validators/ValidatorE3.php @@ -0,0 +1,31 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +class ValidatorE3 extends ValidatorChain +{ + public function __construct(Bank $bank) + { + parent::__construct($bank); + $this->validators[] = new Validator00($bank); + $this->validators[] = new Validator21($bank); + } + +} \ No newline at end of file diff --git a/classes/validator/validators/ValidatorE4.php b/classes/validator/validators/ValidatorE4.php new file mode 100644 index 0000000..2e1d866 --- /dev/null +++ b/classes/validator/validators/ValidatorE4.php @@ -0,0 +1,31 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +class ValidatorE4 extends ValidatorChain +{ + public function __construct(Bank $bank) + { + parent::__construct($bank); + $this->validators[] = new Validator02($bank); + $this->validators[] = new Validator00($bank); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 04eda14..022a7ed 100644 --- a/composer.json +++ b/composer.json @@ -1,24 +1,37 @@ { - "name": "malkusch/bav", + "name": "rotdrop/bav", "type": "library", "description": "BAV provides validation for German Bank Accounts (Konto)", "keywords": ["bank", "account", "bankaccount", "validation", "check", "konto"], - "homepage": "http://bav.malkusch.de/", + "homepage": "http://github.com/rotdrop/bav/", "license": "WTFPL", + "version": "dev-master", "authors": [ { "name": "Markus Malkusch", "email": "markus@malkusch.de", "homepage": "http://markus.malkusch.de", "role": "Developer" + }, + { + "name": "Markus Zierhut", + "email": "markus@zierhut.net", + "homepage": "https://markus.zierhut.name", + "role": "Developer" + }, + { + "name": "Claus-Justus Heine", + "email": "himself@claus-justus-heine.de", + "homepage": "https://claus-justus-heine.de", + "role": "Developer" } ], "autoload": { "files": ["autoloader/autoloader.php"] }, "require": { - "php": ">=5.4", - "malkusch/php-index": "~0.1" + "php": ">=7.4", + "malkusch/php-index": "dev-master" }, "suggest": { "ext-PDO": "Allows storing bank information in a database", @@ -37,5 +50,13 @@ "bin": [ "bin/bav-update.php", "bin/bav-install.php" - ] + ], + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/bav-php/php-index" + } + ], + "minimum-stability": "dev", + "prefer-stable": true }