diff --git a/src/Z38/SwissPayment/AccountInterface.php b/src/Z38/SwissPayment/AccountInterface.php index fed6e06..c533010 100644 --- a/src/Z38/SwissPayment/AccountInterface.php +++ b/src/Z38/SwissPayment/AccountInterface.php @@ -18,7 +18,7 @@ interface AccountInterface public function format(); /** - * Returns a XML representation to identify the account + * Returns an XML representation to identify the account * * @param DOMDocument $doc * diff --git a/src/Z38/SwissPayment/BIC.php b/src/Z38/SwissPayment/BIC.php index 1f2f90d..5bb416e 100644 --- a/src/Z38/SwissPayment/BIC.php +++ b/src/Z38/SwissPayment/BIC.php @@ -2,12 +2,15 @@ namespace Z38\SwissPayment; +use DOMDocument; +use InvalidArgumentException; + /** * BIC */ class BIC implements FinancialInstitutionInterface { - const PATTERN = '/^[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}$/'; + private const PATTERN = '/^[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}$/'; /** * @var string @@ -19,12 +22,12 @@ class BIC implements FinancialInstitutionInterface * * @param string $bic * - * @throws \InvalidArgumentException When the BIC does contain invalid characters or the length does not match. + * @throws InvalidArgumentException When the BIC does contain invalid characters or the length does not match. */ public function __construct($bic) { if (!preg_match(self::PATTERN, $bic)) { - throw new \InvalidArgumentException('BIC is not properly formatted.'); + throw new InvalidArgumentException('BIC is not properly formatted.'); } $this->bic = $bic; @@ -43,7 +46,7 @@ public function format() /** * {@inheritdoc} */ - public function asDom(\DOMDocument $doc) + public function asDom(DOMDocument $doc) { $xml = $doc->createElement('FinInstnId'); $xml->appendChild($doc->createElement('BIC', $this->format())); diff --git a/src/Z38/SwissPayment/FinancialInstitutionAddress.php b/src/Z38/SwissPayment/FinancialInstitutionAddress.php index 364bcbd..25f386c 100644 --- a/src/Z38/SwissPayment/FinancialInstitutionAddress.php +++ b/src/Z38/SwissPayment/FinancialInstitutionAddress.php @@ -2,6 +2,9 @@ namespace Z38\SwissPayment; +use DOMDocument; +use InvalidArgumentException; + /** * FinancialInstitutionAddress holds information to identify a FI by name and address */ @@ -23,7 +26,7 @@ class FinancialInstitutionAddress implements FinancialInstitutionInterface * @param string $name Name of the FI * @param PostalAddressInterface $address Address of the FI * - * @throws \InvalidArgumentException When the name is invalid. + * @throws InvalidArgumentException When the name is invalid. */ public function __construct($name, PostalAddressInterface $address) { @@ -34,7 +37,7 @@ public function __construct($name, PostalAddressInterface $address) /** * {@inheritdoc} */ - public function asDom(\DOMDocument $doc) + public function asDom(DOMDocument $doc) { $xml = $doc->createElement('FinInstnId'); $xml->appendChild(Text::xml($doc, 'Nm', $this->name)); diff --git a/src/Z38/SwissPayment/FinancialInstitutionInterface.php b/src/Z38/SwissPayment/FinancialInstitutionInterface.php index 2d9c39f..bc683e1 100644 --- a/src/Z38/SwissPayment/FinancialInstitutionInterface.php +++ b/src/Z38/SwissPayment/FinancialInstitutionInterface.php @@ -2,17 +2,20 @@ namespace Z38\SwissPayment; +use DOMDocument; +use DOMElement; + /** * General interface for financial institutions */ interface FinancialInstitutionInterface { /** - * Returns a XML representation to identify the financial institution + * Returns an XML representation to identify the financial institution * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMElement The built DOM element + * @return DOMElement The built DOM element */ - public function asDom(\DOMDocument $doc); + public function asDom(DOMDocument $doc); } diff --git a/src/Z38/SwissPayment/IBAN.php b/src/Z38/SwissPayment/IBAN.php index 5f930d5..e1e37a5 100644 --- a/src/Z38/SwissPayment/IBAN.php +++ b/src/Z38/SwissPayment/IBAN.php @@ -3,14 +3,14 @@ namespace Z38\SwissPayment; use DOMDocument; +use InvalidArgumentException; /** * IBAN */ class IBAN implements AccountInterface { - const MAX_LENGTH = 34; - const PATTERN = '/^[A-Z]{2,2}[0-9]{2,2}[A-Z0-9]{1,30}$/'; + private const PATTERN = '/^[A-Z]{2,2}[0-9]{2,2}[A-Z0-9]{1,30}$/'; /** * @var string @@ -22,16 +22,16 @@ class IBAN implements AccountInterface * * @param string $iban * - * @throws \InvalidArgumentException When the IBAN does contain invalid characters or the checksum calculation fails. + * @throws InvalidArgumentException When the IBAN does contain invalid characters or the checksum calculation fails. */ public function __construct($iban) { $cleanedIban = str_replace(' ', '', strtoupper($iban)); if (!preg_match(self::PATTERN, $cleanedIban)) { - throw new \InvalidArgumentException('IBAN is not properly formatted.'); + throw new InvalidArgumentException('IBAN is not properly formatted.'); } if (!self::check($cleanedIban)) { - throw new \InvalidArgumentException('IBAN has an invalid checksum.'); + throw new InvalidArgumentException('IBAN has an invalid checksum.'); } $this->iban = $cleanedIban; diff --git a/src/Z38/SwissPayment/IID.php b/src/Z38/SwissPayment/IID.php index 0b82d63..5a4ea9f 100644 --- a/src/Z38/SwissPayment/IID.php +++ b/src/Z38/SwissPayment/IID.php @@ -20,7 +20,7 @@ class IID implements FinancialInstitutionInterface * * @param string $iid * - * @throws \InvalidArgumentException When the IID does contain invalid characters or the length does not match. + * @throws InvalidArgumentException When the IID does contain invalid characters or the length does not match. */ public function __construct($iid) { @@ -37,7 +37,7 @@ public function __construct($iid) * * @param IBAN $iban * - * @throws \InvalidArgumentException When the supplied IBAN is not from a supported country. + * @return IID */ public static function fromIBAN(IBAN $iban) { diff --git a/src/Z38/SwissPayment/ISRParticipant.php b/src/Z38/SwissPayment/ISRParticipant.php index be68f6f..7d88c51 100644 --- a/src/Z38/SwissPayment/ISRParticipant.php +++ b/src/Z38/SwissPayment/ISRParticipant.php @@ -20,7 +20,7 @@ class ISRParticipant implements AccountInterface * * @param string $number * - * @throws \InvalidArgumentException When the participation number is not valid. + * @throws InvalidArgumentException When the participation number is not valid. */ public function __construct($number) { diff --git a/src/Z38/SwissPayment/Message/AbstractMessage.php b/src/Z38/SwissPayment/Message/AbstractMessage.php index 92f88b5..2f73744 100644 --- a/src/Z38/SwissPayment/Message/AbstractMessage.php +++ b/src/Z38/SwissPayment/Message/AbstractMessage.php @@ -2,6 +2,8 @@ namespace Z38\SwissPayment\Message; +use DOMDocument; +use DOMElement; use Z38\SwissPayment\Text; /** @@ -12,11 +14,11 @@ abstract class AbstractMessage implements MessageInterface /** * Builds the DOM of the actual message * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMElement + * @return DOMElement */ - abstract protected function buildDom(\DOMDocument $doc); + abstract protected function buildDom(DOMDocument $doc); /** * Gets the name of the schema @@ -35,14 +37,14 @@ abstract protected function getSchemaLocation(); /** * Builds a DOM document of the message * - * @return \DOMDocument + * @return DOMDocument */ public function asDom() { $schema = $this->getSchemaName(); $location = $this->getSchemaLocation(); - $doc = new \DOMDocument('1.0', 'UTF-8'); + $doc = new DOMDocument('1.0', 'UTF-8'); $root = $doc->createElement('Document'); $root->setAttribute('xmlns', $schema); if ($location !== null) { @@ -86,11 +88,11 @@ public function getSoftwareVersion() /** * Creates a DOM element which contains details about the software used to create the message * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMElement + * @return DOMElement */ - protected function buildContactDetails(\DOMDocument $doc) + protected function buildContactDetails(DOMDocument $doc) { $root = $doc->createElement('CtctDtls'); diff --git a/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php b/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php index 9292e41..d96492f 100644 --- a/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php +++ b/src/Z38/SwissPayment/Message/CustomerCreditTransfer.php @@ -2,6 +2,9 @@ namespace Z38\SwissPayment\Message; +use DateTime; +use DOMDocument; +use InvalidArgumentException; use Z38\SwissPayment\Money; use Z38\SwissPayment\PaymentInformation\PaymentInformation; use Z38\SwissPayment\Text; @@ -27,7 +30,7 @@ class CustomerCreditTransfer extends AbstractMessage protected $payments; /** - * @var \DateTime + * @var DateTime */ protected $creationTime; @@ -37,24 +40,24 @@ class CustomerCreditTransfer extends AbstractMessage * @param string $id Identifier of the message (should usually be unique over a period of at least 90 days) * @param string $initiatingParty Name of the initiating party * - * @throws \InvalidArgumentException When any of the inputs contain invalid characters or are too long. + * @throws InvalidArgumentException When any of the inputs contain invalid characters or are too long. */ public function __construct($id, $initiatingParty) { $this->id = Text::assertIdentifier($id); $this->initiatingParty = Text::assert($initiatingParty, 70); $this->payments = []; - $this->creationTime = new \DateTime(); + $this->creationTime = new DateTime(); } /** * Manually sets the creation time * - * @param \DateTime $creationTime The desired creation time + * @param DateTime $creationTime The desired creation time * * @return CustomerCreditTransfer This message */ - public function setCreationTime(\DateTime $creationTime) + public function setCreationTime(DateTime $creationTime) { $this->creationTime = $creationTime; @@ -104,7 +107,7 @@ protected function getSchemaLocation() /** * {@inheritdoc} */ - protected function buildDom(\DOMDocument $doc) + protected function buildDom(DOMDocument $doc) { $transactionCount = 0; $transactionSum = new Money\MixedMoney(0); diff --git a/src/Z38/SwissPayment/Message/MessageInterface.php b/src/Z38/SwissPayment/Message/MessageInterface.php index 1cdfad1..5bcbe56 100644 --- a/src/Z38/SwissPayment/Message/MessageInterface.php +++ b/src/Z38/SwissPayment/Message/MessageInterface.php @@ -8,7 +8,7 @@ interface MessageInterface { /** - * Returns a XML representation of the message + * Returns an XML representation of the message * * @return string The XML source */ diff --git a/src/Z38/SwissPayment/Money/MixedMoney.php b/src/Z38/SwissPayment/Money/MixedMoney.php index a63548a..f7cac7a 100644 --- a/src/Z38/SwissPayment/Money/MixedMoney.php +++ b/src/Z38/SwissPayment/Money/MixedMoney.php @@ -41,7 +41,7 @@ final protected function getDecimals() } /** - * Returns the sum of this and an other amount of money + * Returns the sum of this and another amount of money * * @param Money $addend The addend * @@ -55,7 +55,7 @@ public function plus(Money $addend) } /** - * Returns the subtraction of this and an other amount of money + * Returns the subtraction of this and another amount of money * * @param Money $subtrahend The subtrahend * diff --git a/src/Z38/SwissPayment/Money/Money.php b/src/Z38/SwissPayment/Money/Money.php index 1cf5da3..7c9897e 100644 --- a/src/Z38/SwissPayment/Money/Money.php +++ b/src/Z38/SwissPayment/Money/Money.php @@ -2,6 +2,8 @@ namespace Z38\SwissPayment\Money; +use InvalidArgumentException; + /** * Base class for all currencies */ @@ -66,54 +68,54 @@ public function getAmount() } /** - * Returns the sum of this and an other amount of money + * Returns the sum of this and another amount of money * * @param Money $addend The addend * * @return Money The sum * - * @throws \InvalidArgumentException When the currencies do not match + * @throws InvalidArgumentException When the currencies do not match */ public function plus(self $addend) { if ($this->getCurrency() !== $addend->getCurrency()) { - throw new \InvalidArgumentException('Can not add different currencies'); + throw new InvalidArgumentException('Can not add different currencies'); } return new static($this->cents + $addend->getAmount()); } /** - * Returns the subtraction of this and an other amount of money + * Returns the subtraction of this and another amount of money * * @param Money $subtrahend The subtrahend * * @return Money The difference * - * @throws \InvalidArgumentException When the currencies do not match + * @throws InvalidArgumentException When the currencies do not match */ public function minus(self $subtrahend) { if ($this->getCurrency() !== $subtrahend->getCurrency()) { - throw new \InvalidArgumentException('Can not subtract different currencies'); + throw new InvalidArgumentException('Can not subtract different currencies'); } return new static($this->cents - $subtrahend->getAmount()); } /** - * Compares this instance with an other instance. + * Compares this instance with another instance. * * @param Money $b The instance to which this instance is to be compared. * * @return int -1, 0 or 1 as this instance is less than, equal to, or greater than $b * - * @throws \InvalidArgumentException When the currencies do not match + * @throws InvalidArgumentException When the currencies do not match */ public function compareTo(self $b) { if ($this->getCurrency() !== $b->getCurrency()) { - throw new \InvalidArgumentException('Can not compare different currencies'); + throw new InvalidArgumentException('Can not compare different currencies'); } if ($this->getAmount() < $b->getAmount()) { diff --git a/src/Z38/SwissPayment/PaymentInformation/CategoryPurposeCode.php b/src/Z38/SwissPayment/PaymentInformation/CategoryPurposeCode.php index eb27b44..013b284 100644 --- a/src/Z38/SwissPayment/PaymentInformation/CategoryPurposeCode.php +++ b/src/Z38/SwissPayment/PaymentInformation/CategoryPurposeCode.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\PaymentInformation; use DOMDocument; +use DOMElement; use InvalidArgumentException; /** @@ -33,11 +34,11 @@ public function __construct($code) } /** - * Returns a XML representation of this purpose + * Returns an XML representation of this purpose * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMElement The built DOM element + * @return DOMElement The built DOM element */ public function asDom(DOMDocument $doc) { diff --git a/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php b/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php index 5c334c4..129e3c8 100644 --- a/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php +++ b/src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php @@ -2,6 +2,11 @@ namespace Z38\SwissPayment\PaymentInformation; +use DateTime; +use DOMDocument; +use DOMElement; +use InvalidArgumentException; +use LogicException; use Z38\SwissPayment\BIC; use Z38\SwissPayment\FinancialInstitutionInterface; use Z38\SwissPayment\IBAN; @@ -46,7 +51,7 @@ class PaymentInformation protected $categoryPurpose; /** - * @var \DateTime + * @var DateTime */ protected $executionDate; @@ -73,18 +78,18 @@ class PaymentInformation * @param BIC|IID $debtorAgent BIC or IID of the debtor's financial institution * @param IBAN $debtorIBAN IBAN of the debtor's account * - * @throws \InvalidArgumentException When any of the inputs contain invalid characters or are too long. + * @throws InvalidArgumentException When any of the inputs contain invalid characters or are too long. */ public function __construct($id, $debtorName, FinancialInstitutionInterface $debtorAgent, IBAN $debtorIBAN) { if (!$debtorAgent instanceof BIC && !$debtorAgent instanceof IID) { - throw new \InvalidArgumentException('The debtor agent must be an instance of BIC or IID.'); + throw new InvalidArgumentException('The debtor agent must be an instance of BIC or IID.'); } $this->id = Text::assertIdentifier($id); $this->transactions = []; $this->batchBooking = true; - $this->executionDate = new \DateTime(); + $this->executionDate = new DateTime(); $this->debtorName = Text::assert($debtorName, 70); $this->debtorAgent = $debtorAgent; $this->debtorIBAN = $debtorIBAN; @@ -134,11 +139,11 @@ public function getTransactionSum() * Sets the required execution date. * Where appropriate, the value data is automatically modified to the next possible banking/Post Office working day. * - * @param \DateTime $executionDate + * @param DateTime $executionDate * * @return PaymentInformation This payment instruction */ - public function setExecutionDate(\DateTime $executionDate) + public function setExecutionDate(DateTime $executionDate) { $this->executionDate = $executionDate; @@ -207,11 +212,11 @@ public function setCategoryPurpose(CategoryPurposeCode $categoryPurpose) /** * Builds a DOM tree of this payment instruction * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMElement The built DOM tree + * @return DOMElement The built DOM tree */ - public function asDom(\DOMDocument $doc) + public function asDom(DOMDocument $doc) { $root = $doc->createElement('PmtInf'); @@ -219,6 +224,9 @@ public function asDom(\DOMDocument $doc) $root->appendChild($doc->createElement('PmtMtd', 'TRF')); $root->appendChild($doc->createElement('BtchBookg', ($this->batchBooking ? 'true' : 'false'))); + $localInstrument = null; + $serviceLevel = null; + if ($this->hasPaymentTypeInformation()) { $paymentType = $doc->createElement('PmtTpInf'); $localInstrument = $this->localInstrument ?: $this->inferLocalInstrument(); @@ -260,10 +268,10 @@ public function asDom(\DOMDocument $doc) foreach ($this->transactions as $transaction) { if ($this->hasPaymentTypeInformation()) { if ($transaction->getLocalInstrument() !== $localInstrument) { - throw new \LogicException('You can not set the local instrument on B- and C-level.'); + throw new LogicException('You can not set the local instrument on B- and C-level.'); } if ($transaction->getServiceLevel() !== $serviceLevel) { - throw new \LogicException('You can not set the service level on B- and C-level.'); + throw new LogicException('You can not set the service level on B- and C-level.'); } } $root->appendChild($transaction->asDom($doc, $this)); @@ -272,6 +280,9 @@ public function asDom(\DOMDocument $doc) return $root; } + /** + * @return string|null + */ private function inferServiceLevel() { if (!count($this->transactions)) { @@ -281,6 +292,9 @@ private function inferServiceLevel() return $this->transactions[0]->getServiceLevel(); } + /** + * @return string|null + */ private function inferLocalInstrument() { if (!count($this->transactions)) { diff --git a/src/Z38/SwissPayment/PostalAccount.php b/src/Z38/SwissPayment/PostalAccount.php index 21e90db..2f65337 100644 --- a/src/Z38/SwissPayment/PostalAccount.php +++ b/src/Z38/SwissPayment/PostalAccount.php @@ -10,7 +10,7 @@ */ class PostalAccount implements AccountInterface { - const PATTERN = '/^[0-9]{2}-[1-9][0-9]{0,5}-[0-9]$/'; + private const PATTERN = '/^[0-9]{2}-[1-9][0-9]{0,5}-[0-9]$/'; /** * @var int @@ -74,7 +74,8 @@ public function asDom(DOMDocument $doc) } /** - * @internal + * @param $number + * @return bool */ public static function validateCheckDigit($number) { diff --git a/src/Z38/SwissPayment/PostalAddressInterface.php b/src/Z38/SwissPayment/PostalAddressInterface.php index 749883f..cc57235 100644 --- a/src/Z38/SwissPayment/PostalAddressInterface.php +++ b/src/Z38/SwissPayment/PostalAddressInterface.php @@ -2,17 +2,20 @@ namespace Z38\SwissPayment; +use DOMDocument; +use DOMElement; + /** * PostalAddressInterface */ interface PostalAddressInterface { /** - * Returns a XML representation of the address + * Returns an XML representation of the address * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMElement The built DOM element + * @return DOMElement The built DOM element */ - public function asDom(\DOMDocument $doc); + public function asDom(DOMDocument $doc); } diff --git a/src/Z38/SwissPayment/StructuredPostalAddress.php b/src/Z38/SwissPayment/StructuredPostalAddress.php index 7de3efa..1598cb4 100644 --- a/src/Z38/SwissPayment/StructuredPostalAddress.php +++ b/src/Z38/SwissPayment/StructuredPostalAddress.php @@ -2,6 +2,9 @@ namespace Z38\SwissPayment; +use DOMDocument; +use InvalidArgumentException; + /** * This class holds a structured representation of a postal address */ @@ -41,7 +44,7 @@ class StructuredPostalAddress implements PostalAddressInterface * @param string $town Town name * @param string $country Country code (ISO 3166-1 alpha-2) * - * @throws \InvalidArgumentException When the address contains invalid characters or is too long. + * @throws InvalidArgumentException When the address contains invalid characters or is too long. */ public function __construct($street, $buildingNo, $postCode, $town, $country = 'CH') { @@ -77,7 +80,7 @@ public static function sanitize($street, $buildingNo, $postCode, $town, $country /** * {@inheritdoc} */ - public function asDom(\DOMDocument $doc) + public function asDom(DOMDocument $doc) { $root = $doc->createElement('PstlAdr'); diff --git a/src/Z38/SwissPayment/Text.php b/src/Z38/SwissPayment/Text.php index 0e51b77..76a93a5 100644 --- a/src/Z38/SwissPayment/Text.php +++ b/src/Z38/SwissPayment/Text.php @@ -3,12 +3,17 @@ namespace Z38\SwissPayment; use DOMDocument; +use DOMElement; +use DOMException; use InvalidArgumentException; +/** + * This class permits to sanitize all texts + */ class Text { - const TEXT_NON_CH = '/[^A-Za-z0-9 .,:\'\/()?+\-!"#%&*;<>÷=@_$£[\]{}\` ́~àáâäçèéêëìíîïñòóôöùúûüýßÀÁÂÄÇÈÉÊËÌÍÎÏÒÓÔÖÙÚÛÜÑ]+/u'; - const TEXT_NON_SWIFT = '/[^A-Za-z0-9 .,:\'\/()?+\-]+/'; + private const TEXT_NON_CH = '/[^A-Za-z0-9 .,:\'\/()?+\-!"#%&*;<>÷=@_$£[\]{}\` ́~àáâäçèéêëìíîïñòóôöùúûüýßÀÁÂÄÇÈÉÊËÌÍÎÏÒÓÔÖÙÚÛÜÑ]+/u'; + private const TEXT_NON_SWIFT = '/[^A-Za-z0-9 .,:\'\/()?+\-]+/'; /** * Sanitizes and trims a string to conform to the Swiss character @@ -44,7 +49,9 @@ public static function sanitizeOptional($input, $maxLength) } /** - * @internal + * @param $input + * @param $maxLength + * @return string|null */ public static function assertOptional($input, $maxLength) { @@ -56,7 +63,9 @@ public static function assertOptional($input, $maxLength) } /** - * @internal + * @param $input + * @param $maxLength + * @return string */ public static function assert($input, $maxLength) { @@ -64,7 +73,8 @@ public static function assert($input, $maxLength) } /** - * @internal + * @param $input + * @return string */ public static function assertIdentifier($input) { @@ -77,7 +87,8 @@ public static function assertIdentifier($input) } /** - * @internal + * @param $input + * @return mixed */ public static function assertCountryCode($input) { @@ -88,6 +99,12 @@ public static function assertCountryCode($input) return $input; } + /** + * @param $input + * @param $maxLength + * @param $pattern + * @return string + */ protected static function assertNotPattern($input, $maxLength, $pattern) { $length = function_exists('mb_strlen') ? mb_strlen($input, 'UTF-8') : strlen($input); @@ -102,7 +119,11 @@ protected static function assertNotPattern($input, $maxLength, $pattern) } /** - * @internal + * @param DOMDocument $doc + * @param $tag + * @param $content + * @return DOMElement|false + * @throws DOMException */ public static function xml(DOMDocument $doc, $tag, $content) { diff --git a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransfer.php index e899ec9..e009c1d 100644 --- a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransfer.php @@ -32,7 +32,7 @@ class BankCreditTransfer extends CreditTransfer * @param IBAN $creditorIBAN IBAN of the creditor * @param BIC|IID $creditorAgent BIC or IID of the creditor's financial institution * - * @throws \InvalidArgumentException When the amount is not in EUR or CHF or when the creditor agent is not BIC or IID. + * @throws InvalidArgumentException When the amount is not in EUR or CHF or when the creditor agent is not BIC or IID. */ public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, $creditorAddress, IBAN $creditorIBAN, FinancialInstitutionInterface $creditorAgent) { diff --git a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php index 747df9d..e2a1b89 100644 --- a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php +++ b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php @@ -8,7 +8,6 @@ use Z38\SwissPayment\FinancialInstitutionInterface; use Z38\SwissPayment\IBAN; use Z38\SwissPayment\Money; -use Z38\SwissPayment\PostalAccount; /** * BankCreditTransfer contains all the information about a type 3 transaction diff --git a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php index 2fe3260..7d39f18 100644 --- a/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php +++ b/src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php @@ -29,7 +29,9 @@ class BankCreditTransferWithQRR extends BankCreditTransfer * @param $creditorName * @param $creditorAddress * @param IBAN $creditorIBAN IBAN of the creditor - * @param FinancialInstitutionInterface $creditorAgent BIC or IID of the creditor's financial institution + * @param FinancialInstitutionInterface $creditorAgent BIC or IID + * of the creditor's financial institution + * You can build the IID from the IBAN number for QRR (Only CH+LI) * @param string $creditorReference QR reference number (QRR) */ public function __construct( @@ -47,7 +49,7 @@ public function __construct( } $this->creditorReference = $creditorReference; - if (!preg_match('/^CH[0-9]{2}3/', $creditorIBAN->normalize())) { + if (!preg_match('/^(CH|LI)[0-9]{2}3/', $creditorIBAN->normalize())) { throw new InvalidArgumentException('The IBAN must be a QR-IBAN'); } diff --git a/src/Z38/SwissPayment/TransactionInformation/CreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/CreditTransfer.php index 303f26b..333a7d0 100644 --- a/src/Z38/SwissPayment/TransactionInformation/CreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/CreditTransfer.php @@ -2,6 +2,10 @@ namespace Z38\SwissPayment\TransactionInformation; +use DOMDocument; +use DOMElement; +use DOMNode; +use InvalidArgumentException; use Z38\SwissPayment\Money\Money; use Z38\SwissPayment\PaymentInformation\PaymentInformation; use Z38\SwissPayment\PostalAddressInterface; @@ -66,7 +70,7 @@ abstract class CreditTransfer * @param string $creditorName Name of the creditor * @param PostalAddressInterface|null $creditorAddress Address of the creditor * - * @throws \InvalidArgumentException When any of the inputs contain invalid characters or are too long. + * @throws InvalidArgumentException When any of the inputs contain invalid characters or are too long. */ public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddressInterface $creditorAddress = null) { @@ -118,7 +122,7 @@ public function setPurpose(PurposeCode $purpose) * * @return CreditTransfer This credit transfer * - * @throws \InvalidArgumentException When the information contains invalid characters or is too long. + * @throws InvalidArgumentException When the information contains invalid characters or is too long. */ public function setRemittanceInformation($remittanceInformation) { @@ -140,22 +144,22 @@ public function getAmount() /** * Builds a DOM tree of this transaction * - * @param \DOMDocument $doc + * @param DOMDocument $doc * @param PaymentInformation $paymentInformation Information on B-level * - * @return \DOMElement The built DOM tree + * @return DOMElement The built DOM tree */ - abstract public function asDom(\DOMDocument $doc, PaymentInformation $paymentInformation); + abstract public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation); /** * Builds a DOM tree of this transaction and adds header nodes * - * @param \DOMDocument $doc + * @param DOMDocument $doc * @param PaymentInformation $paymentInformation The corresponding B-level element * - * @return \DOMNode The built DOM node + * @return DOMElement The built DOM node */ - protected function buildHeader(\DOMDocument $doc, PaymentInformation $paymentInformation) + protected function buildHeader(DOMDocument $doc, PaymentInformation $paymentInformation) { $root = $doc->createElement('CdtTrfTxInf'); @@ -191,11 +195,11 @@ protected function buildHeader(\DOMDocument $doc, PaymentInformation $paymentInf /** * Builds a DOM node of the Creditor field * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMNode The built DOM node + * @return DOMNode The built DOM node */ - protected function buildCreditor(\DOMDocument $doc) + protected function buildCreditor(DOMDocument $doc) { $creditor = $doc->createElement('Cdtr'); $creditor->appendChild(Text::xml($doc, 'Nm', $this->creditorName)); @@ -209,10 +213,10 @@ protected function buildCreditor(\DOMDocument $doc) /** * Appends the purpose to the transaction * - * @param \DOMDocument $doc - * @param \DOMElement $transaction + * @param DOMDocument $doc + * @param DOMElement $transaction */ - protected function appendPurpose(\DOMDocument $doc, \DOMElement $transaction) + protected function appendPurpose(DOMDocument $doc, DOMElement $transaction) { if ($this->purpose !== null) { $purposeNode = $doc->createElement('Purp'); @@ -224,10 +228,10 @@ protected function appendPurpose(\DOMDocument $doc, \DOMElement $transaction) /** * Appends the remittance information to the transaction * - * @param \DOMDocument $doc - * @param \DOMElement $transaction + * @param DOMDocument $doc + * @param DOMElement $transaction */ - protected function appendRemittanceInformation(\DOMDocument $doc, \DOMElement $transaction) + protected function appendRemittanceInformation(DOMDocument $doc, DOMElement $transaction) { if (!empty($this->remittanceInformation)) { $remittanceNode = $doc->createElement('RmtInf'); diff --git a/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php index 661bb48..d6028da 100644 --- a/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\TransactionInformation; use DOMDocument; +use InvalidArgumentException; use Z38\SwissPayment\AccountInterface; use Z38\SwissPayment\BIC; use Z38\SwissPayment\FinancialInstitutionAddress; @@ -41,7 +42,7 @@ public function __construct($instructionId, $endToEndId, Money $amount, $credito parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress); if (!$creditorAgent instanceof BIC && !$creditorAgent instanceof FinancialInstitutionAddress) { - throw new \InvalidArgumentException('The creditor agent must be an instance of BIC or FinancialInstitutionAddress.'); + throw new InvalidArgumentException('The creditor agent must be an instance of BIC or FinancialInstitutionAddress.'); } $this->creditorAccount = $creditorAccount; diff --git a/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php index c5daa12..9e3b268 100644 --- a/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php @@ -9,7 +9,7 @@ use Z38\SwissPayment\PostalAccount; /** - * IS1CreditTransfer contains all the information about a IS 1-stage (type 2.1) transaction. + * IS1CreditTransfer contains all the information about an IS 1-stage (type 2.1) transaction. */ class IS1CreditTransfer extends CreditTransfer { @@ -23,7 +23,7 @@ class IS1CreditTransfer extends CreditTransfer * * @param PostalAccount $creditorAccount Postal account of the creditor * - * @throws \InvalidArgumentException When the amount is not in EUR or CHF. + * @throws InvalidArgumentException When the amount is not in EUR or CHF. */ public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, $creditorAddress, PostalAccount $creditorAccount) { diff --git a/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php index 5c42e9f..6c32f4c 100644 --- a/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php @@ -11,7 +11,7 @@ use Z38\SwissPayment\Text; /** - * IS2CreditTransfer contains all the information about a IS 2-stage (type 2.2) transaction. + * IS2CreditTransfer contains all the information about an IS 2-stage (type 2.2) transaction. */ class IS2CreditTransfer extends CreditTransfer { @@ -37,7 +37,7 @@ class IS2CreditTransfer extends CreditTransfer * @param string $creditorAgentName Name of the creditor's financial institution * @param PostalAccount $creditorAgentPostal Postal account of the creditor's financial institution * - * @throws \InvalidArgumentException When the amount is not in EUR or CHF. + * @throws InvalidArgumentException When the amount is not in EUR or CHF. */ public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal) { diff --git a/src/Z38/SwissPayment/TransactionInformation/ISRCreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/ISRCreditTransfer.php index 32bd8de..9695c9c 100644 --- a/src/Z38/SwissPayment/TransactionInformation/ISRCreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/ISRCreditTransfer.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\TransactionInformation; use DOMDocument; +use DOMElement; use InvalidArgumentException; use LogicException; use Z38\SwissPayment\ISRParticipant; @@ -13,7 +14,7 @@ use Z38\SwissPayment\Text; /** - * ISRCreditTransfer contains all the information about a ISR (type 1) transaction. + * ISRCreditTransfer contains all the information about an ISR (type 1) transaction. */ class ISRCreditTransfer extends CreditTransfer { @@ -101,7 +102,7 @@ public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation) /** * {@inheritdoc} */ - protected function appendRemittanceInformation(\DOMDocument $doc, \DOMElement $transaction) + protected function appendRemittanceInformation(DOMDocument $doc, DOMElement $transaction) { $remittanceInformation = $doc->createElement('RmtInf'); diff --git a/src/Z38/SwissPayment/TransactionInformation/PurposeCode.php b/src/Z38/SwissPayment/TransactionInformation/PurposeCode.php index 6c8960e..9659398 100644 --- a/src/Z38/SwissPayment/TransactionInformation/PurposeCode.php +++ b/src/Z38/SwissPayment/TransactionInformation/PurposeCode.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\TransactionInformation; use DOMDocument; +use DOMElement; use InvalidArgumentException; /** @@ -20,7 +21,7 @@ class PurposeCode * * @param string $code * - * @throws \InvalidArgumentException When the code is not valid + * @throws InvalidArgumentException When the code is not valid */ public function __construct($code) { @@ -33,11 +34,11 @@ public function __construct($code) } /** - * Returns a XML representation of this purpose + * Returns an XML representation of this purpose * - * @param \DOMDocument $doc + * @param DOMDocument $doc * - * @return \DOMElement The built DOM element + * @return DOMElement The built DOM element */ public function asDom(DOMDocument $doc) { diff --git a/src/Z38/SwissPayment/UnstructuredPostalAddress.php b/src/Z38/SwissPayment/UnstructuredPostalAddress.php index ae3d6e3..8be9cc6 100644 --- a/src/Z38/SwissPayment/UnstructuredPostalAddress.php +++ b/src/Z38/SwissPayment/UnstructuredPostalAddress.php @@ -2,8 +2,11 @@ namespace Z38\SwissPayment; +use DOMDocument; +use InvalidArgumentException; + /** - * This class holds a unstructured representation of a postal address + * This class holds an unstructured representation of a postal address */ class UnstructuredPostalAddress implements PostalAddressInterface { @@ -24,7 +27,7 @@ class UnstructuredPostalAddress implements PostalAddressInterface * @param string $addressLine2 Postcode and town * @param string $country Country code (ISO 3166-1 alpha-2) * - * @throws \InvalidArgumentException When the address contains invalid characters or is too long. + * @throws InvalidArgumentException When the address contains invalid characters or is too long. */ public function __construct($addressLine1 = null, $addressLine2 = null, $country = 'CH') { @@ -59,7 +62,7 @@ public static function sanitize($addressLine1 = null, $addressLine2 = null, $cou /** * {@inheritdoc} */ - public function asDom(\DOMDocument $doc) + public function asDom(DOMDocument $doc) { $root = $doc->createElement('PstlAdr'); diff --git a/tests/Z38/SwissPayment/Tests/BICTest.php b/tests/Z38/SwissPayment/Tests/BICTest.php index ce4a84f..4759125 100644 --- a/tests/Z38/SwissPayment/Tests/BICTest.php +++ b/tests/Z38/SwissPayment/Tests/BICTest.php @@ -2,8 +2,12 @@ namespace Z38\SwissPayment\Tests; +use InvalidArgumentException; use Z38\SwissPayment\BIC; +/** + * @coversDefaultClass \Z38\SwissPayment\BIC + */ class BICTest extends TestCase { /** @@ -43,6 +47,9 @@ public function testFormat($bic) self::assertEquals($bic, $instance->format()); } + /** + * @return string[][] + */ public function validSamples() { return [ @@ -52,12 +59,17 @@ public function validSamples() ]; } + /** + * @param $iban + * @param $valid + * @return void + */ protected function check($iban, $valid) { $exception = false; try { - $temp = new BIC($iban); - } catch (\InvalidArgumentException $e) { + new BIC($iban); + } catch (InvalidArgumentException $e) { $exception = true; } self::assertTrue($exception != $valid); diff --git a/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php b/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php index 4a5954f..7a32447 100644 --- a/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php +++ b/tests/Z38/SwissPayment/Tests/GeneralAccountTest.php @@ -2,8 +2,12 @@ namespace Z38\SwissPayment\Tests; +use InvalidArgumentException; use Z38\SwissPayment\GeneralAccount; +/** + * @coversDefaultClass \Z38\SwissPayment\GeneralAccount + */ class GeneralAccountTest extends TestCase { /** @@ -20,8 +24,8 @@ public function testValid() */ public function testInvalid() { - $this->expectException(\InvalidArgumentException::class); - $instance = new GeneralAccount('0123456789012345678901234567890123456789'); + $this->expectException(InvalidArgumentException::class); + new GeneralAccount('0123456789012345678901234567890123456789'); } /** diff --git a/tests/Z38/SwissPayment/Tests/IBANTest.php b/tests/Z38/SwissPayment/Tests/IBANTest.php index 3d50931..33fa042 100644 --- a/tests/Z38/SwissPayment/Tests/IBANTest.php +++ b/tests/Z38/SwissPayment/Tests/IBANTest.php @@ -2,8 +2,12 @@ namespace Z38\SwissPayment\Tests; +use InvalidArgumentException; use Z38\SwissPayment\IBAN; +/** + * @coversDefaultClass \Z38\SwissPayment\IBAN + */ class IBANTest extends TestCase { /** @@ -72,6 +76,9 @@ public function testToString($iban) self::assertEquals($instance->format(), (string) $instance); } + /** + * @return string[][] + */ public function samplesValid() { return [ @@ -81,12 +88,17 @@ public function samplesValid() ]; } + /** + * @param $iban + * @param $valid + * @return void + */ protected function check($iban, $valid) { $exception = false; try { - $temp = new IBAN($iban); - } catch (\InvalidArgumentException $e) { + new IBAN($iban); + } catch (InvalidArgumentException $e) { $exception = true; } self::assertTrue($exception != $valid); diff --git a/tests/Z38/SwissPayment/Tests/IIDTest.php b/tests/Z38/SwissPayment/Tests/IIDTest.php index ac16bb6..65c91cf 100644 --- a/tests/Z38/SwissPayment/Tests/IIDTest.php +++ b/tests/Z38/SwissPayment/Tests/IIDTest.php @@ -4,6 +4,7 @@ use DOMDocument; use DOMXPath; +use InvalidArgumentException; use Z38\SwissPayment\IBAN; use Z38\SwissPayment\IID; @@ -21,6 +22,9 @@ public function testValid($iid) $this->assertInstanceOf('Z38\SwissPayment\IID', new IID($iid)); } + /** + * @return string[][] + */ public function validSamples() { return [ @@ -35,10 +39,13 @@ public function validSamples() */ public function testInvalidLength($iid) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new IID($iid); } + /** + * @return string[][] + */ public function invalidSamples() { return [ @@ -69,6 +76,9 @@ public function testFromIBAN($iban, $iid) $this->assertSame($iid, $instance->format()); } + /** + * @return string[][] + */ public function fromIBANSamples() { return [ @@ -82,7 +92,7 @@ public function fromIBANSamples() */ public function testFromIBANForeign() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); IID::fromIBAN(new IBAN('GB29 NWBK 6016 1331 9268 19')); } diff --git a/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php b/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php index bc13b01..a253105 100644 --- a/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php +++ b/tests/Z38/SwissPayment/Tests/ISRParticipantTest.php @@ -2,6 +2,7 @@ namespace Z38\SwissPayment\Tests; +use InvalidArgumentException; use Z38\SwissPayment\ISRParticipant; /** @@ -24,7 +25,7 @@ public function testValid($number) */ public function testInvalid($number) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new ISRParticipant($number); } @@ -37,6 +38,9 @@ public function testFormat() self::assertEquals('01-162-8', $instance->format()); } + /** + * @return string[][] + */ public function validSamples() { return [ @@ -46,6 +50,9 @@ public function validSamples() ]; } + /** + * @return string[][] + */ public function invalidSamples() { return [ diff --git a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php index fb3a301..35fe49d 100644 --- a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php @@ -2,6 +2,8 @@ namespace Z38\SwissPayment\Tests\Message; +use DOMDocument; +use DOMXPath; use Z38\SwissPayment\BIC; use Z38\SwissPayment\FinancialInstitutionAddress; use Z38\SwissPayment\GeneralAccount; @@ -27,11 +29,17 @@ use Z38\SwissPayment\TransactionInformation\SEPACreditTransfer; use Z38\SwissPayment\UnstructuredPostalAddress; +/** + * @coversDefaultClass \Z38\SwissPayment\Message\CustomerCreditTransfer + */ class CustomerCreditTransferTest extends TestCase { - const SCHEMA = 'http://www.six-interbank-clearing.com/de/pain.001.001.03.ch.02.xsd'; - const SCHEMA_PATH = 'pain.001.001.03.ch.02.xsd'; + private const SCHEMA = 'http://www.six-interbank-clearing.com/de/pain.001.001.03.ch.02.xsd'; + private const SCHEMA_PATH = 'pain.001.001.03.ch.02.xsd'; + /** + * @return CustomerCreditTransfer + */ protected function buildMessage() { $message = new CustomerCreditTransfer('message-000', 'InnoMuster AG'); @@ -257,9 +265,9 @@ public function testGroupHeader() { $xml = $this->buildMessage()->asXml(); - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $doc->loadXML($xml); - $xpath = new \DOMXPath($doc); + $xpath = new DOMXPath($doc); $xpath->registerNamespace('pain001', self::SCHEMA); $nbOfTxs = $xpath->evaluate('string(//pain001:GrpHdr/pain001:NbOfTxs)'); @@ -274,7 +282,7 @@ public function testSchemaValidation() $xml = $this->buildMessage()->asXml(); $schemaPath = __DIR__.'/../../../../'.self::SCHEMA_PATH; - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $doc->loadXML($xml); libxml_use_internal_errors(true); diff --git a/tests/Z38/SwissPayment/Tests/Money/MixedTest.php b/tests/Z38/SwissPayment/Tests/Money/MixedTest.php index bb74404..7e516e2 100644 --- a/tests/Z38/SwissPayment/Tests/Money/MixedTest.php +++ b/tests/Z38/SwissPayment/Tests/Money/MixedTest.php @@ -5,6 +5,9 @@ use Z38\SwissPayment\Money; use Z38\SwissPayment\Tests\TestCase; +/** + * @coversDefaultClass \Z38\SwissPayment\Money\MixedMoney + */ class MixedTest extends TestCase { /** diff --git a/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php b/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php index 35570bc..d13ef1b 100644 --- a/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php +++ b/tests/Z38/SwissPayment/Tests/Money/MoneyTest.php @@ -2,9 +2,14 @@ namespace Z38\SwissPayment\Tests\Money; +use InvalidArgumentException; +use stdClass; use Z38\SwissPayment\Money; use Z38\SwissPayment\Tests\TestCase; +/** + * @coversDefaultClass \Z38\SwissPayment\Money\Money + */ class MoneyTest extends TestCase { /** @@ -65,9 +70,9 @@ public function testEquals() self::assertTrue($instance->equals($instance)); self::assertTrue($instance->equals(new Money\CHF(-451))); - self::assertFalse($instance->equals(false)); + self::assertNotFalse($instance); self::assertFalse($instance->equals(null)); - self::assertFalse($instance->equals(new \stdClass())); + self::assertFalse($instance->equals(new stdClass())); self::assertFalse($instance->equals(new Money\EUR(-451))); self::assertFalse($instance->equals(new Money\CHF(-41))); } @@ -91,7 +96,7 @@ public function testBinaryOperands($a, $b, $expectedSum, $expectedDiff, $expecte */ public function testInvalidPlus($a, $b) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $a->plus($b); } @@ -101,7 +106,7 @@ public function testInvalidPlus($a, $b) */ public function testInvalidMinus($a, $b) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $a->minus($b); } @@ -111,10 +116,13 @@ public function testInvalidMinus($a, $b) */ public function testInvalidCompareTo($a, $b) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $a->compareTo($b); } + /** + * @return array[] + */ public function validSamplePairs() { return [ @@ -125,6 +133,9 @@ public function validSamplePairs() ]; } + /** + * @return array[] + */ public function invalidSamplePairs() { return [ diff --git a/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php b/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php index 818a91a..cf6d16b 100644 --- a/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php +++ b/tests/Z38/SwissPayment/Tests/PaymentInformation/CategoryPurposeCodeTest.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\Tests\PaymentInformation; use DOMDocument; +use InvalidArgumentException; use Z38\SwissPayment\PaymentInformation\CategoryPurposeCode; use Z38\SwissPayment\Tests\TestCase; @@ -20,6 +21,9 @@ public function testValid($code) self::assertInstanceOf('Z38\SwissPayment\PaymentInformation\CategoryPurposeCode', new CategoryPurposeCode($code)); } + /** + * @return string[][] + */ public function validSamples() { return [ @@ -34,10 +38,13 @@ public function validSamples() */ public function testInvalid($code) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new CategoryPurposeCode($code); } + /** + * @return string[][] + */ public function invalidSamples() { return [ diff --git a/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php b/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php index 0cab342..3beba04 100644 --- a/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php +++ b/tests/Z38/SwissPayment/Tests/PaymentInformation/PaymentInformationTest.php @@ -4,6 +4,7 @@ use DOMDocument; use DOMXPath; +use InvalidArgumentException; use Z38\SwissPayment\BIC; use Z38\SwissPayment\FinancialInstitutionInterface; use Z38\SwissPayment\IBAN; @@ -25,10 +26,10 @@ class PaymentInformationTest extends TestCase */ public function testInvalidDebtorAgent() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $debtorAgent = $this->createMock(FinancialInstitutionInterface::class); - $payment = new PaymentInformation( + new PaymentInformation( 'id000', 'name', $debtorAgent, diff --git a/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php b/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php index 6861e4e..73ba945 100644 --- a/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php +++ b/tests/Z38/SwissPayment/Tests/PaymentInformation/SEPAPaymentInformationTest.php @@ -2,6 +2,9 @@ namespace Z38\SwissPayment\Tests\PaymentInformation; +use DOMDocument; +use DOMXPath; +use LogicException; use Z38\SwissPayment\BIC; use Z38\SwissPayment\IBAN; use Z38\SwissPayment\Money; @@ -53,11 +56,11 @@ public function testAsDomWithSEPATransaction() new BIC('COBADEFFXXX') )); - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $dom = $payment->asDom($doc); $doc->appendChild($dom); - $xpath = new \DOMXPath($doc); + $xpath = new DOMXPath($doc); self::assertEquals('SEPA', $xpath->evaluate('string(/PmtInf/PmtTpInf/SvcLvl/Cd)')); self::assertEquals(0, $xpath->evaluate('count(//CdtTrfTxInf/PmtTpInf)')); } @@ -67,7 +70,7 @@ public function testAsDomWithSEPATransaction() */ public function testAsDomWithNonSEPATransaction() { - $this->expectException(\LogicException::class); + $this->expectException(LogicException::class); $this->expectExceptionMessage('You can not set the service level on B- and C-level.'); $payment = new SEPAPaymentInformation( 'id000', @@ -85,7 +88,7 @@ public function testAsDomWithNonSEPATransaction() new BIC('UBSWCHZH80A') )); - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $payment->asDom($doc); } } diff --git a/tests/Z38/SwissPayment/Tests/PostalAccountTest.php b/tests/Z38/SwissPayment/Tests/PostalAccountTest.php index aa28445..aab9f3f 100644 --- a/tests/Z38/SwissPayment/Tests/PostalAccountTest.php +++ b/tests/Z38/SwissPayment/Tests/PostalAccountTest.php @@ -2,6 +2,7 @@ namespace Z38\SwissPayment\Tests; +use InvalidArgumentException; use Z38\SwissPayment\PostalAccount; /** @@ -18,6 +19,9 @@ public function testValid($postalAccount) self::assertInstanceOf('Z38\SwissPayment\PostalAccount', new PostalAccount($postalAccount)); } + /** + * @return string[][] + */ public function validSamples() { return [ @@ -37,11 +41,14 @@ public function validSamples() */ public function testInvalidFormat($postalAccount) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Postal account number is not properly formatted.'); new PostalAccount($postalAccount); } + /** + * @return string[][] + */ public function invalidFormatSamples() { return [ @@ -59,11 +66,14 @@ public function invalidFormatSamples() */ public function testInvalidCheckDigit($postalAccount) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Postal account number has an invalid check digit.'); new PostalAccount($postalAccount); } + /** + * @return string[][] + */ public function invalidCheckDigitSamples() { return [ diff --git a/tests/Z38/SwissPayment/Tests/TestCase.php b/tests/Z38/SwissPayment/Tests/TestCase.php index cfabf21..04db3af 100644 --- a/tests/Z38/SwissPayment/Tests/TestCase.php +++ b/tests/Z38/SwissPayment/Tests/TestCase.php @@ -4,6 +4,9 @@ use PHPUnit\Framework\TestCase as BaseTestCase; +/** + * + */ abstract class TestCase extends BaseTestCase { } diff --git a/tests/Z38/SwissPayment/Tests/TextTest.php b/tests/Z38/SwissPayment/Tests/TextTest.php index 89aa1c8..551e219 100644 --- a/tests/Z38/SwissPayment/Tests/TextTest.php +++ b/tests/Z38/SwissPayment/Tests/TextTest.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\Tests; use DOMDocument; +use InvalidArgumentException; use Z38\SwissPayment\Text; /** @@ -10,11 +11,9 @@ */ class TextTest extends TestCase { - /** - */ public function testAssertTooLong() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); Text::assert('abcd', 3); } @@ -30,30 +29,30 @@ public function testAssertUnicode() public function testAssertInvalid() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); Text::assert('°', 10); } - public function testAssertIdentiferBeginsWithSlash() + public function testAssertIdentifierBeginsWithSlash() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); Text::assertIdentifier('/abc'); } - public function testAssertIdentiferContainsDoubleSlash() + public function testAssertIdentifierContainsDoubleSlash() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); Text::assertIdentifier('ab//c'); } - public function testAssertIdentiferContainsSlash() + public function testAssertIdentifierContainsSlash() { self::assertSame('ab/c', Text::assertIdentifier('ab/c')); } public function testAssertCountryCodeUppercase() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); Text::assertCountryCode('ch'); } @@ -65,6 +64,9 @@ public function testSanitize($input, $expected) self::assertSame($expected, Text::sanitize($input, 3)); } + /** + * @return string[][] + */ public function sanitizeSamples() { return [ diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php index 3f28325..276a34d 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php @@ -2,6 +2,7 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; +use InvalidArgumentException; use Z38\SwissPayment\BIC; use Z38\SwissPayment\FinancialInstitutionInterface; use Z38\SwissPayment\IBAN; @@ -22,8 +23,8 @@ public function testInvalidCreditorAgent() { $creditorAgent = $this->createMock(FinancialInstitutionInterface::class); - $this->expectException(\InvalidArgumentException::class); - $transfer = new BankCreditTransfer( + $this->expectException(InvalidArgumentException::class); + new BankCreditTransfer( 'id000', 'name', new Money\CHF(100), @@ -39,8 +40,8 @@ public function testInvalidCreditorAgent() */ public function testInvalidAmount() { - $this->expectException(\InvalidArgumentException::class); - $transfer = new BankCreditTransfer( + $this->expectException(InvalidArgumentException::class); + new BankCreditTransfer( 'id000', 'name', new Money\USD(100), diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php index 93fc4ec..fcf44bb 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/ForeignCreditTransferTest.php @@ -2,6 +2,7 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; +use InvalidArgumentException; use Z38\SwissPayment\FinancialInstitutionInterface; use Z38\SwissPayment\IBAN; use Z38\SwissPayment\Money; @@ -19,10 +20,10 @@ class ForeignCreditTransferTest extends TestCase */ public function testInvalidCreditorAgent() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $creditorAgent = $this->createMock(FinancialInstitutionInterface::class); - $transfer = new ForeignCreditTransfer( + new ForeignCreditTransfer( 'id000', 'name', new Money\CHF(100), diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php index 754ce7b..3289469 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS1CreditTransferTest.php @@ -2,6 +2,7 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; +use InvalidArgumentException; use Z38\SwissPayment\Money; use Z38\SwissPayment\PostalAccount; use Z38\SwissPayment\StructuredPostalAddress; @@ -18,8 +19,8 @@ class IS1CreditTransferTest extends TestCase */ public function testInvalidAmount() { - $this->expectException(\InvalidArgumentException::class); - $transfer = new IS1CreditTransfer( + $this->expectException(InvalidArgumentException::class); + new IS1CreditTransfer( 'id000', 'name', new Money\USD(100), diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php index 1b0692a..baa56dd 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/IS2CreditTransferTest.php @@ -2,6 +2,7 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; +use InvalidArgumentException; use Z38\SwissPayment\IBAN; use Z38\SwissPayment\Money; use Z38\SwissPayment\PostalAccount; @@ -19,8 +20,8 @@ class IS2CreditTransferTest extends TestCase */ public function testInvalidAmount() { - $this->expectException(\InvalidArgumentException::class); - $transfer = new IS2CreditTransfer( + $this->expectException(InvalidArgumentException::class); + new IS2CreditTransfer( 'id000', 'name', new Money\USD(100), diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php index a638b06..10d7696 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/ISRCreditTransferTest.php @@ -2,6 +2,8 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; +use InvalidArgumentException; +use LogicException; use Z38\SwissPayment\ISRParticipant; use Z38\SwissPayment\Money; use Z38\SwissPayment\StructuredPostalAddress; @@ -18,8 +20,8 @@ class ISRCreditTransferTest extends TestCase */ public function testInvalidAmount() { - $this->expectException(\InvalidArgumentException::class); - $transfer = new ISRCreditTransfer( + $this->expectException(InvalidArgumentException::class); + new ISRCreditTransfer( 'id000', 'name', new Money\USD(100), @@ -33,8 +35,8 @@ public function testInvalidAmount() */ public function testInvalidCreditorReference() { - $this->expectException(\InvalidArgumentException::class); - $transfer = new ISRCreditTransfer( + $this->expectException(InvalidArgumentException::class); + new ISRCreditTransfer( 'id000', 'name', new Money\CHF(100), @@ -48,7 +50,7 @@ public function testInvalidCreditorReference() */ public function testSetRemittanceInformation() { - $this->expectException(\LogicException::class); + $this->expectException(LogicException::class); $transfer = new ISRCreditTransfer( 'id000', 'name', diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php index 604709d..19fa37b 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/PurposeCodeTest.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; use DOMDocument; +use InvalidArgumentException; use Z38\SwissPayment\Tests\TestCase; use Z38\SwissPayment\TransactionInformation\PurposeCode; @@ -20,6 +21,9 @@ public function testValid($code) self::assertInstanceOf('Z38\SwissPayment\TransactionInformation\PurposeCode', new PurposeCode($code)); } + /** + * @return string[][] + */ public function validSamples() { return [ @@ -36,10 +40,13 @@ public function validSamples() */ public function testInvalid($code) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new PurposeCode($code); } + /** + * @return string[][] + */ public function invalidSamples() { return [