Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions autoloader/index/0.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions classes/BAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BAV
* @var DataBackend
*/
private $backend;

/**
* @var ContextValidation
*/
Expand All @@ -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();
Expand All @@ -52,7 +52,7 @@ public function __construct(Configuration $configuration = null)
$this->configuration = $configuration;

$this->backend = $configuration->getDataBackendContainer()->getDataBackend();

$this->contextValidation = new ContextValidation($this->backend);
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public function isValidBank($bankID)
{
return $this->contextValidation->isValidBank($bankID);
}

/**
* Every bank has one main agency.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions classes/configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public function getDataBackendContainer()
{
return $this->backendContainer;
}

/**
* Sets the encoding.
*/
Expand Down
50 changes: 19 additions & 31 deletions classes/dataBackend/file/FileDataBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -30,7 +33,7 @@ class FileDataBackend extends DataBackend
* @var FileParser
*/
private $parser;

/**
* @var Index_FixedSize
*/
Expand All @@ -49,7 +52,7 @@ public function __construct($file = null)
$this->parser = new FileParser($file);
$this->fileUtil = new FileUtil();
}

/**
* @return FixedSizeIndex
*/
Expand All @@ -61,7 +64,7 @@ private function getIndex()
FileParser::BANKID_OFFSET,
FileParser::BANKID_LENGTH
);

}
return $this->index;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -245,7 +233,7 @@ public function getNewBank($bankID)
{
try {
$result = $this->getIndex()->search($bankID);

if ($result == null) {
throw new BankNotFoundException($bankID);

Expand All @@ -261,7 +249,7 @@ public function getNewBank($bankID)

} catch (IndexException $e) {
throw new DataBackendIOException($e->getMessage(), $e->getCode(), $e);

}
}

Expand Down Expand Up @@ -419,7 +407,7 @@ public function getBICAgencies($bic)
}
return $agencies;
}

public function free()
{
parent::free();
Expand Down
3 changes: 2 additions & 1 deletion classes/dataBackend/file/download/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 4 additions & 26 deletions classes/dataBackend/pdo/PDODataBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
Expand All @@ -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;
}
}

Expand Down
24 changes: 12 additions & 12 deletions classes/validator/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ protected function checkType($account)
{
if (is_string($account)) {
return;

}
trigger_error(
"Only validation of strings are defined."
. "Note that e.g. an (int) 0020012357 evaluates to (string) '4199663'.",
E_USER_WARNING
);
}

/**
* Validates a bank account.
*
Expand All @@ -101,7 +101,7 @@ public function isValid($account)
try {
if ($account == null) {
return false;

}
$this->checkType($account);
$this->init($account);
Expand Down Expand Up @@ -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)];
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -217,7 +217,7 @@ protected function getESER8()

}
$bankID = $this->bank->getBankID();
if ($bankID{3} != 5) {
if ($bankID[3] != 5) {
throw new ValidatorESERException();

}
Expand All @@ -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;
}
Expand All @@ -249,17 +249,17 @@ protected function getESER9()
throw new ValidatorESERException();

}
if ($bankID{3} != 5) {
if ($bankID[3] != 5) {
throw new ValidatorESERException();

}

$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;
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion classes/validator/ValidatorIteration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion classes/validator/validators/Validator16.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
3 changes: 2 additions & 1 deletion classes/validator/validators/Validator25.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down
Loading