-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cs278/initial-version
Initial version
- Loading branch information
Showing
53 changed files
with
4,378 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tools: | ||
external_code_coverage: | ||
timeout: 600 | ||
runs: 2 | ||
|
||
filter: | ||
excluded_paths: | ||
- tests/* | ||
- src/Spec/VocaLinkV380Data.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
bootstrap="vendor/autoload.php" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
<exclude> | ||
<file>src/Spec/VocaLinkV380Generator.php</file> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Cs278\BankModulus; | ||
|
||
use Cs278\BankModulus\Exception\Util as E; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class BankAccount implements BankAccountInterface | ||
{ | ||
private $sortCode; | ||
private $accountNumber; | ||
|
||
/** | ||
* @param string|SortCode $sortCode | ||
* @param string $accountNumber | ||
*/ | ||
public function __construct($sortCode, $accountNumber) | ||
{ | ||
try { | ||
if (!$sortCode instanceof SortCode) { | ||
Assert::string($sortCode, 'Sort code must be a string or instance of SortCode'); | ||
|
||
$sortCode = SortCode::create($sortCode); | ||
} | ||
|
||
Assert::string($accountNumber, 'Account number must be a string'); | ||
Assert::regex($accountNumber, '{^(?:.*\d.*){6}$}', 'Account number must contain at least 6 digits'); | ||
} catch (\InvalidArgumentException $e) { | ||
throw E::wrap($e); | ||
} | ||
|
||
$this->sortCode = $sortCode; | ||
$this->accountNumber = preg_replace('{[^0-9]}', '', $accountNumber); | ||
} | ||
|
||
/** @return SortCode */ | ||
public function getSortCode() | ||
{ | ||
return $this->sortCode; | ||
} | ||
|
||
/** @return string */ | ||
public function getAccountNumber() | ||
{ | ||
return $this->accountNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Cs278\BankModulus; | ||
|
||
interface BankAccountInterface | ||
{ | ||
/** @return SortCode */ | ||
public function getSortCode(); | ||
|
||
/** @return string */ | ||
public function getAccountNumber(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Cs278\BankModulus; | ||
|
||
use Cs278\BankModulus\Exception\Util as E; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class BankAccountNormalized implements BankAccountInterface | ||
{ | ||
private $bankAccount; | ||
private $sortCode; | ||
private $accountNumber; | ||
|
||
const LENGTH = 8; | ||
|
||
/** | ||
* @param BankAccountInterface $bankAccount | ||
* @param string|SortCode $sortCode | ||
* @param string $accountNumber | ||
*/ | ||
public function __construct(BankAccountInterface $bankAccount, $sortCode, $accountNumber) | ||
{ | ||
try { | ||
if (!$sortCode instanceof SortCode) { | ||
Assert::string($sortCode, 'Sort code must be a string or instance of SortCode'); | ||
|
||
$sortCode = SortCode::create($sortCode); | ||
} | ||
|
||
Assert::string($accountNumber, 'Account number must be a string'); | ||
} catch (\InvalidArgumentException $e) { | ||
throw E::wrap($e); | ||
} | ||
|
||
$this->bankAccount = $bankAccount; | ||
$this->sortCode = $sortCode; | ||
$this->accountNumber = preg_replace('{[^0-9]}', '', $accountNumber); | ||
|
||
if (self::LENGTH !== strlen($this->accountNumber)) { | ||
throw Exception\AccountNumberInvalidException::create($accountNumber); | ||
} | ||
} | ||
|
||
public static function createFromBankAccount(BankAccountInterface $bankAccount) | ||
{ | ||
return new self( | ||
$bankAccount, | ||
$bankAccount->getSortCode(), | ||
$bankAccount->getAccountNumber() | ||
); | ||
} | ||
|
||
/** @return BankAccountInterface */ | ||
public function getOriginalBankAccount() | ||
{ | ||
return $this->bankAccount; | ||
} | ||
|
||
/** @return SortCode */ | ||
public function getSortCode() | ||
{ | ||
return $this->sortCode; | ||
} | ||
|
||
/** @return string */ | ||
public function getAccountNumber() | ||
{ | ||
return $this->accountNumber; | ||
} | ||
|
||
/** @return string */ | ||
public function __toString() | ||
{ | ||
return $this->sortCode->format('%s%s%s').$this->accountNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Cs278\BankModulus\BankAccountNormalizer; | ||
|
||
use Cs278\BankModulus\BankAccountInterface; | ||
use Cs278\BankModulus\BankAccountNormalized; | ||
use Cs278\BankModulus\SortCode; | ||
|
||
final class CoOperativeBankNormalizer implements NormalizerInterface | ||
{ | ||
/** @return BankAccountInterface */ | ||
public function normalize(BankAccountInterface $bankAccount) | ||
{ | ||
return new BankAccountNormalized( | ||
$bankAccount, | ||
$bankAccount->getSortCode(), | ||
substr($bankAccount->getAccountNumber(), 0, 8) | ||
); | ||
} | ||
|
||
/** @return bool */ | ||
public function supports(BankAccountInterface $bankAccount) | ||
{ | ||
$accountNumber = $bankAccount->getAccountNumber(); | ||
$sortCode = $bankAccount->getSortCode(); | ||
|
||
return 10 === strlen($accountNumber) | ||
&& $sortCode->isBetween(new SortCode('080000'), new SortCode('090000')) | ||
&& !$sortCode->isBetween(new SortCode('083000'), new SortCode('084000')); // Exclude Citibank | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Cs278\BankModulus\BankAccountNormalizer; | ||
|
||
use Cs278\BankModulus\BankAccountInterface; | ||
use Cs278\BankModulus\BankAccountNormalized; | ||
|
||
final class DefaultNormalizer implements NormalizerInterface | ||
{ | ||
private $normalizers = []; | ||
|
||
public function __construct(array $normalizers = null) | ||
{ | ||
if (null === $normalizers) { | ||
$normalizers = [ | ||
new SixDigitNormalizer(), | ||
new SevenDigitNormalizer(), | ||
new SantanderNormalizer(), | ||
new NatWestNormalizer(), | ||
new CoOperativeBankNormalizer(), | ||
]; | ||
} | ||
|
||
$this->normalizers = $normalizers; | ||
} | ||
|
||
/** @return BankAccountInterface */ | ||
public function normalize(BankAccountInterface $bankAccount) | ||
{ | ||
foreach ($this->normalizers as $normalizer) { | ||
if ($normalizer->supports($bankAccount)) { | ||
return $normalizer->normalize($bankAccount); | ||
} | ||
} | ||
|
||
return BankAccountNormalized::createFromBankAccount($bankAccount); | ||
} | ||
|
||
/** @return bool */ | ||
public function supports(BankAccountInterface $bankAccount) | ||
{ | ||
// Supports anything because it checks before normalizing. | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Cs278\BankModulus\BankAccountNormalizer; | ||
|
||
use Cs278\BankModulus\BankAccountInterface; | ||
use Cs278\BankModulus\BankAccountNormalized; | ||
use Cs278\BankModulus\SortCode; | ||
|
||
final class NatWestNormalizer implements NormalizerInterface | ||
{ | ||
/** @return BankAccountInterface */ | ||
public function normalize(BankAccountInterface $bankAccount) | ||
{ | ||
return new BankAccountNormalized( | ||
$bankAccount, | ||
$bankAccount->getSortCode(), | ||
substr($bankAccount->getAccountNumber(), -8) | ||
); | ||
} | ||
|
||
/** @return bool */ | ||
public function supports(BankAccountInterface $bankAccount) | ||
{ | ||
$accountNumber = $bankAccount->getAccountNumber(); | ||
$sortCode = $bankAccount->getSortCode(); | ||
|
||
return 10 === strlen($accountNumber) | ||
&& ( | ||
$sortCode->isBetween(new SortCode('010000'), new SortCode('020000')) // ex. District Bank | ||
|| $sortCode->isBetween(new SortCode('500000'), new SortCode('600000')) // ex. National Provincial Bank | ||
|| $sortCode->isBetween(new SortCode('600000'), new SortCode('670000')) // ex. Westminster Bank | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Cs278\BankModulus\BankAccountNormalizer; | ||
|
||
use Cs278\BankModulus\BankAccountInterface; | ||
|
||
interface NormalizerInterface | ||
{ | ||
/** @return BankAccountInterface */ | ||
public function normalize(BankAccountInterface $bankAccount); | ||
|
||
/** @return bool */ | ||
public function supports(BankAccountInterface $bankAccount); | ||
} |
Oops, something went wrong.