/** * Returns true if the data is to old and needs an update * * @see DataBackend::getLastUpdate() * @return bool */ public function isOutdated(DataBackend $backend) { /* * The following code creates a sorted list with the release months (update month - $relaseThreshold) * and the current month. To build that threshold date simply pick the month before the current month from * that list. * * Note that the second parameter of the date() calls is there on purpose. This allows * to mock time() for testing. */ /* * The current month gets an increment of 0.5 for the case that the current month is a * release month (e.g. the list will look (2, 2.5, 5, 8, 11)). */ $currentMonth = date("n", time()) + 0.5; $monthList = array($currentMonth); foreach (self::$updateMonths as $month) { $releaseMonth = $month - self::$relaseThreshold; $monthList[] = $releaseMonth; } sort($monthList); // You have now something like (2, 2.5, 5, 8, 11). // Now add the cycle between the last and the first month(11, 2, 3.5, 5, 8, 11, 2). $monthList[] = self::$updateMonths[0] - self::$relaseThreshold; // this is acually not needed. array_unshift($monthList, self::$updateMonths[count(self::$updateMonths) - 1] - self::$relaseThreshold); $index = array_search($currentMonth, $monthList); assert($index > 0); $previousIndex = $index - 1; $thresholdMonth = $monthList[$previousIndex]; // flip the year if the threshold was in the last year. $year = $thresholdMonth > $currentMonth ? date("Y", time()) - 1 : date("Y", time()); $threshold = mktime(0, 0, 0, $thresholdMonth, 1, $year); return $backend->getLastUpdate() < $threshold; }
/** * Perform an update. * * If enabled (default) this method will send a E_USER_NOTICE about the update. * * @see setNotice() */ public function perform(DataBackend $backend) { $isNotice = $this->notice; $lock = new Lock(self::UPDATE_LOCK); $lock->nonblockingExecuteOnce(function () use($backend, $isNotice) { $backend->update(); if ($isNotice) { trigger_error("bav's bank data was updated sucessfully.", E_USER_NOTICE); } }); }
/** * Returns true if a bank exists. * * This method sets the bank context and should be called first. * * @throws DataBackendException * @param string $bankID * @return bool * @see DataBackend::isValidBank() */ public function isValidBank($bankID) { try { $this->initialized = true; $this->bank = $this->backend->getBank($bankID); return true; } catch (BankNotFoundException $e) { $this->bank = null; return false; } }
/** * @throws FileParserIOException * @throws FileParserNotExistsException */ protected function setUp() { if (!empty(self::$dataBackend)) { return; } $container = new FileDataBackendContainer(); #self::$dataBackend = new PDODataBackend(PDOFactory::makePDO()); self::$dataBackend = $container->getDataBackend(); foreach (self::$dataBackend->getAllBanks() as $bank) { self::$knownBanks[$bank->getValidationType()] = $bank; } }
/** * A bank may have more agencies. * * @throws DataBackendException * @return Agency[] */ public function getAgencies() { if (is_null($this->agencies)) { $this->agencies = $this->dataBackend->getAgenciesForBank($this); } return $this->agencies; }
/** * Tests DataBackend::getBICAgencies() * * @dataProvider provideTestGetBICAgencies * @see DataBackend::getBICAgencies(); */ public function testGetBICAgencies(DataBackend $backend, $bic, $expectedAgencyIds) { $agencies = $backend->getBICAgencies($bic); $getID = function (Agency $agency) { return $agency->getID(); }; $agenciesIds = array_map($getID, $agencies); sort($expectedAgencyIds); sort($agenciesIds); $this->assertEquals($expectedAgencyIds, $agenciesIds); }
/** * Returns if a bic is valid. * * @param string $bic BIC * @return bool */ public function isValidBIC($bic) { return $this->backend->isValidBIC(BICUtil::normalize($bic)); }