Skip to content
Closed
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
9 changes: 6 additions & 3 deletions src/Hyperwallet/Model/BankAccount.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Hyperwallet\Model;

use Hyperwallet\Util\StringToDataConverter;

/**
* Represents a V3 Bank Account
*
Expand Down Expand Up @@ -784,11 +786,12 @@ public function getDateOfBirth() {
/**
* Set the date of birth
*
* @param \DateTime|null $dateOfBirth
* @param string $dateOfBirth |null
* @return BankAccount
*/
public function setDateOfBirth(\DateTime $dateOfBirth = null) {
$this->dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d');
public function setDateOfBirth($dateOfBirth = null)
{
$this->dateOfBirth = StringToDataConverter::convertStringToDate($dateOfBirth, 'Y-m-d');
return $this;
}

Expand Down
9 changes: 6 additions & 3 deletions src/Hyperwallet/Model/BankCard.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Hyperwallet\Model;

use Hyperwallet\Util\StringToDataConverter;

/**
* Represents a V3 Bank Card
*
Expand Down Expand Up @@ -225,11 +227,12 @@ public function getDateOfExpiry() {
/**
* Set the bank card expiry date
*
* @param \DateTime $dateOfExpiry
* @param string $dateOfExpiry |null
* @return BankCard
*/
public function setDateOfExpiry(\DateTime $dateOfExpiry = null) {
$this->dateOfExpiry = $dateOfExpiry == null ? null : $dateOfExpiry->format('Y-m-d');
public function setDateOfExpiry($dateOfExpiry = null)
{
$this->dateOfExpiry = StringToDataConverter::convertStringToDate($dateOfExpiry, 'Y-m-d');
return $this;
}

Expand Down
11 changes: 7 additions & 4 deletions src/Hyperwallet/Model/Payment.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Hyperwallet\Model;

use Hyperwallet\Util\StringToDataConverter;

/**
* Represents a V3 Payment
*
Expand Down Expand Up @@ -201,11 +203,12 @@ public function getReleaseOn() {
/**
* Set the payment release date
*
* @param \DateTime $releaseOn
* @param string $releaseOn |null
* @return Payment
*/
public function setReleaseOn(\DateTime $releaseOn = null) {
$this->releaseOn = $releaseOn == null ? null : $releaseOn->format('Y-m-d\TH:i:s');
public function setReleaseOn($releaseOn = null)
{
$this->releaseOn = StringToDataConverter::convertStringToDate($releaseOn, 'Y-m-d\TH:i:s');
return $this;
}

Expand Down Expand Up @@ -240,7 +243,7 @@ public function getProgramToken() {

/**
* Set the payment program token
*
*
* @param string $programToken
* @return Payment
*/
Expand Down
11 changes: 7 additions & 4 deletions src/Hyperwallet/Model/TransferMethod.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Hyperwallet\Model;

use Hyperwallet\Util\StringToDataConverter;

/**
* Represents a V3 Transfer Method
*
Expand Down Expand Up @@ -191,7 +193,7 @@ public function getCardBrand() {
public function getDateOfExpiry() {
return $this->dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null;
}

/**
* Get the bank account id
*
Expand Down Expand Up @@ -861,11 +863,12 @@ public function getDateOfBirth() {
/**
* Set the date of birth
*
* @param \DateTime|null $dateOfBirth
* @param string $dateOfBirth |null
* @return TransferMethod
*/
public function setDateOfBirth(\DateTime $dateOfBirth = null) {
$this->dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d');
public function setDateOfBirth($dateOfBirth = null)
{
$this->dateOfBirth = StringToDataConverter::convertStringToDate($dateOfBirth, 'Y-m-d');
return $this;
}

Expand Down
9 changes: 6 additions & 3 deletions src/Hyperwallet/Model/User.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Hyperwallet\Model;

use Hyperwallet\Util\StringToDataConverter;

/**
* Represents a V3 User
*
Expand Down Expand Up @@ -362,11 +364,12 @@ public function getDateOfBirth() {
/**
* Set the date of birth
*
* @param \DateTime|null $dateOfBirth
* @param string $dateOfBirth |null
* @return User
*/
public function setDateOfBirth(\DateTime $dateOfBirth = null) {
$this->dateOfBirth = $dateOfBirth == null ? null : $dateOfBirth->format('Y-m-d');
public function setDateOfBirth($dateOfBirth = null)
{
$this->dateOfBirth = StringToDataConverter::convertStringToDate($dateOfBirth, 'Y-m-d');
return $this;
}

Expand Down
14 changes: 14 additions & 0 deletions src/Hyperwallet/Util/StringToDataConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php


namespace Hyperwallet\Util;


class StringToDataConverter
{
static function convertStringToDate($string, $format)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cover this method with tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{
$stringToDate = $string === null ? null : new \DateTime($string);
return $stringToDate == null ? null : $stringToDate->format($format);
}
}
4 changes: 2 additions & 2 deletions tests/Hyperwallet/Tests/Model/ModelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDef
$setter = $this->clazz->getMethod($setterName);

$this->assertEquals($valType, $getter->invoke($instance));
$this->assertEquals($instance, $setter->invoke($instance, $newValParam));
$this->assertEquals($instance, $setter->invoke($instance, $newVal));
$this->assertEquals($newValParam, $getter->invoke($instance));

$data2 = array();
Expand Down Expand Up @@ -173,7 +173,7 @@ protected function performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDef
$setter = $this->clazz->getMethod($setterName);

$this->assertNull($getter->invoke($instance));
$this->assertEquals($instance, $setter->invoke($instance, $newValParam));
$this->assertEquals($instance, $setter->invoke($instance, $newVal));
$this->assertEquals($newValParam, $getter->invoke($instance));

$data2 = array();
Expand Down
33 changes: 33 additions & 0 deletions tests/Hyperwallet/Tests/Util/StringToDateConverterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php


namespace Hyperwallet\Tests\Util;


use Hyperwallet\Util\StringToDataConverter;

class StringToDateConverterTest extends \PHPUnit_Framework_TestCase
{

public function testShouldConvertStringToDateIfAcceptedParameterIsNotNull()
{
$format = 'Y-m-d';
$stringToConvert = '2019-12-31';

$convertedDate = StringToDataConverter::convertStringToDate($stringToConvert, $format);
$originalDate = new \DateTime($stringToConvert);

$this->assertEquals($originalDate->format($format), $convertedDate);
}

public function testShouldReturnNullIfAcceptedParameterIsNull()
{
$format = 'Y-m-d';
$stringToConvert = null;

$convertedDate = StringToDataConverter::convertStringToDate($stringToConvert, $format);
$originalDate = null;

$this->assertEquals(null, $convertedDate);
}
}