Skip to content
This repository has been archived by the owner on Nov 7, 2021. It is now read-only.

Commit

Permalink
Add type hints for all class properties
Browse files Browse the repository at this point in the history
  • Loading branch information
z38 committed Mar 9, 2015
1 parent aca5ece commit 51383cf
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/Z38/SwissPayment/IBAN.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class IBAN
const MAX_LENGTH = 34;
const PATTERN = '/^[A-Z]{2,2}[0-9]{2,2}[A-Z0-9]{1,30}$/';

/**
* @var string
*/
protected $iban;

/**
Expand Down
19 changes: 17 additions & 2 deletions src/Z38/SwissPayment/Message/CustomerCreditTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@
*/
class CustomerCreditTransfer extends AbstractMessage
{
/**
* @var string
*/
protected $id;

/**
* @var string
*/
protected $initiatingParty;

/**
* @var array
*/
protected $payments;

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

/**
Expand All @@ -23,8 +38,8 @@ class CustomerCreditTransfer extends AbstractMessage
*/
public function __construct($id, $initiatingParty)
{
$this->id = $id;
$this->initiatingParty = $initiatingParty;
$this->id = (string) $id;
$this->initiatingParty = (string) $initiatingParty;
$this->payments = array();
$this->creationTime = new \DateTime();
}
Expand Down
3 changes: 3 additions & 0 deletions src/Z38/SwissPayment/Money/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
abstract class Money
{
/**
* @var int
*/
protected $cents;

/**
Expand Down
31 changes: 29 additions & 2 deletions src/Z38/SwissPayment/PaymentInformation/PaymentInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,39 @@
*/
class PaymentInformation
{
/**
* @var string
*/
protected $id;

/**
* @var array
*/
protected $transactions;

/**
* @var bool
*/
protected $batchBooking;

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

/**
* @var string
*/
protected $debtorName;

/**
* @var FinancialInstitutionInterface
*/
protected $debtorAgent;

/**
* @var IBAN
*/
protected $debtorIBAN;

/**
Expand All @@ -36,11 +63,11 @@ public function __construct($id, $debtorName, FinancialInstitutionInterface $deb
throw new \InvalidArgumentException('The debtor agent must be an instance of BC or BIC.');
}

$this->id = $id;
$this->id = (string) $id;
$this->transactions = array();
$this->batchBooking = true;
$this->executionDate = new \DateTime();
$this->debtorName = $debtorName;
$this->debtorName = (string) $debtorName;
$this->debtorAgent = $debtorAgent;
$this->debtorIBAN = $debtorIBAN;
}
Expand Down
24 changes: 21 additions & 3 deletions src/Z38/SwissPayment/PostalAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ class PostalAccount
{
const PATTERN = '/^[0-9]{2}-[1-9][0-9]{0,5}-[0-9]$/';

/**
* @var int
*/
protected $prefix;

/**
* @var int
*/
protected $number;

/**
* @var int
*/
protected $checkDigit;

/**
Expand All @@ -31,9 +42,9 @@ public function __construct($postalAccount)
throw new \InvalidArgumentException('Postal account number has an invalid prefix.');
}

$this->prefix = $parts[0];
$this->number = $parts[1];
$this->checkDigit = $parts[2];
$this->prefix = (int) $parts[0];
$this->number = (int) $parts[1];
$this->checkDigit = (int) $parts[2];
}

/**
Expand All @@ -46,6 +57,13 @@ public function format()
return sprintf('%d-%d-%d', $this->prefix, $this->number, $this->checkDigit);
}

/**
* Checks whether a given prefix is valid
*
* @param int $prefix The prefix to be checked
*
* @return bool True if the prefix is valid
*/
private static function checkPrefix($prefix)
{
return in_array($prefix, array(
Expand Down
27 changes: 23 additions & 4 deletions src/Z38/SwissPayment/PostalAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,29 @@
*/
class PostalAddress
{
/**
* @var string
*/
protected $street;

/**
* @var string|null
*/
protected $buildingNo;

/**
* @var string
*/
protected $postCode;

/**
* @var string
*/
protected $town;

/**
* @var string
*/
protected $country;

/**
Expand All @@ -24,11 +43,11 @@ class PostalAddress
*/
public function __construct($street, $buildingNo, $postCode, $town, $country = 'CH')
{
$this->street = $street;
$this->street = (string) $street;
$this->buildingNo = $buildingNo;
$this->postCode = $postCode;
$this->town = $town;
$this->country = $country;
$this->postCode = (string) $postCode;
$this->town = (string) $town;
$this->country = (string) $country;
}

/**
Expand Down
29 changes: 26 additions & 3 deletions src/Z38/SwissPayment/TransactionInformation/CreditTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,34 @@
*/
abstract class CreditTransfer
{
/**
* @var string
*/
protected $instructionId;

/**
* @var string
*/
protected $endToEndId;

/**
* @var string
*/
protected $creditorName;

/**
* @var PostalAddress
*/
protected $creditorAddress;

/**
* @var Money
*/
protected $amount;

/**
* @var string|null
*/
protected $remittanceInformation;

/**
Expand All @@ -28,10 +51,10 @@ abstract class CreditTransfer
*/
public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddress $creditorAddress)
{
$this->instructionId = $instructionId;
$this->endToEndId = $endToEndId;
$this->instructionId = (string) $instructionId;
$this->endToEndId = (string) $endToEndId;
$this->amount = $amount;
$this->creditorName = $creditorName;
$this->creditorName = (string) $creditorName;
$this->creditorAddress = $creditorAddress;
$this->remittanceInformation = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*/
class IS1CreditTransfer extends CreditTransfer
{
/**
* @var PostalAccount
*/
protected $creditorAccount;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@
*/
class IS2CreditTransfer extends CreditTransfer
{
/**
* @var IBAN
*/
protected $creditorIBAN;

/**
* @var string
*/
protected $creditorAgentName;

/**
* @var PostalAccount
*/
protected $creditorAgentPostal;

/**
Expand All @@ -27,7 +38,7 @@ public function __construct($instructionId, $endToEndId, Money\CHF $amount, $cre
parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);

$this->creditorIBAN = $creditorIBAN;
$this->creditorAgentName = $creditorAgentName;
$this->creditorAgentName = (string) $creditorAgentName;
$this->creditorAgentPostal = $creditorAgentPostal;
}

Expand Down

0 comments on commit 51383cf

Please sign in to comment.