Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStorm inspections #6

Merged
merged 1 commit into from
Dec 16, 2021
Merged
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
PHPStorm inspections
  • Loading branch information
Sébastien Despont committed Dec 9, 2021
commit 0374b1c3bc30a65dbbf69191fa603443cf2432cf
2 changes: 1 addition & 1 deletion src/Z38/SwissPayment/AccountInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 7 additions & 4 deletions src/Z38/SwissPayment/BIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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()));
Expand Down
7 changes: 5 additions & 2 deletions src/Z38/SwissPayment/FinancialInstitutionAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Z38\SwissPayment;

use DOMDocument;
use InvalidArgumentException;

/**
* FinancialInstitutionAddress holds information to identify a FI by name and address
*/
Expand All @@ -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)
{
Expand All @@ -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));
Expand Down
11 changes: 7 additions & 4 deletions src/Z38/SwissPayment/FinancialInstitutionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 5 additions & 5 deletions src/Z38/SwissPayment/IBAN.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Z38/SwissPayment/IID.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Z38/SwissPayment/ISRParticipant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
18 changes: 10 additions & 8 deletions src/Z38/SwissPayment/Message/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Z38\SwissPayment\Message;

use DOMDocument;
use DOMElement;
use Z38\SwissPayment\Text;

/**
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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');

Expand Down
15 changes: 9 additions & 6 deletions src/Z38/SwissPayment/Message/CustomerCreditTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +30,7 @@ class CustomerCreditTransfer extends AbstractMessage
protected $payments;

/**
* @var \DateTime
* @var DateTime
*/
protected $creationTime;

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

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Z38/SwissPayment/Message/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Z38/SwissPayment/Money/MixedMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down
20 changes: 11 additions & 9 deletions src/Z38/SwissPayment/Money/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Z38\SwissPayment\Money;

use InvalidArgumentException;

/**
* Base class for all currencies
*/
Expand Down Expand Up @@ -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()) {
Expand Down
Loading