Skip to content

Commit

Permalink
[credit-card] Fixes regression in the bundle. Validation marks all fi…
Browse files Browse the repository at this point in the history
…elds as invalid.
  • Loading branch information
makasim committed Mar 7, 2016
1 parent ae14864 commit f008176
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
37 changes: 19 additions & 18 deletions Model/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class CreditCard implements CreditCardInterface

public function __construct()
{
$this->holder = SensitiveValue::ensureSensitive(null);
$this->securityCode = SensitiveValue::ensureSensitive(null);
$this->number = SensitiveValue::ensureSensitive(null);
$this->expireAt = SensitiveValue::ensureSensitive(null);
$this->securedHolder = SensitiveValue::ensureSensitive(null);
$this->securedSecurityCode = SensitiveValue::ensureSensitive(null);
$this->securedNumber = SensitiveValue::ensureSensitive(null);
$this->securedExpireAt = SensitiveValue::ensureSensitive(null);
}

/**
Expand Down Expand Up @@ -120,19 +120,19 @@ public function getBrand()
*/
public function setHolder($holder)
{
$this->holder = SensitiveValue::ensureSensitive($holder);
$this->maskedHolder = Mask::mask($this->holder->peek());
$this->securedHolder = SensitiveValue::ensureSensitive($holder);
$this->maskedHolder = Mask::mask($this->securedHolder->peek());

// BC
$this->securedHolder = $this->holder;
$this->holder = $this->securedHolder->peek();
}

/**
* {@inheritDoc}
*/
public function getHolder()
{
return $this->holder->peek();
return $this->securedHolder->peek();
}

/**
Expand All @@ -156,19 +156,19 @@ public function getMaskedHolder()
*/
public function setNumber($number)
{
$this->number = SensitiveValue::ensureSensitive($number);
$this->maskedNumber = Mask::mask($this->number->peek());
$this->securedNumber = SensitiveValue::ensureSensitive($number);
$this->maskedNumber = Mask::mask($this->securedNumber->peek());

//BC
$this->securedNumber = $this->number;
$this->number = $this->securedNumber->peek();
}

/**
* {@inheritDoc}
*/
public function getNumber()
{
return $this->number->peek();
return $this->securedNumber->peek();
}

/**
Expand All @@ -192,26 +192,26 @@ public function getMaskedNumber()
*/
public function setSecurityCode($securityCode)
{
$this->securityCode = SensitiveValue::ensureSensitive($securityCode);
$this->securedSecurityCode = SensitiveValue::ensureSensitive($securityCode);

// BC
$this->securedSecurityCode = $this->securityCode;
$this->securityCode = $this->securedSecurityCode->peek();
}

/**
* {@inheritDoc}
*/
public function getSecurityCode()
{
return $this->securityCode->peek();
return $this->securedSecurityCode->peek();
}

/**
* {@inheritDoc}
*/
public function getExpireAt()
{
return $this->expireAt->peek();
return $this->securedExpireAt->peek();
}

/**
Expand All @@ -225,16 +225,17 @@ public function setExpireAt($date = null)
throw new InvalidArgumentException('The date argument must be either instance of DateTime or null');
}

$this->expireAt = $date;
$this->securedExpireAt = $date;

// BC
$this->securedExpireAt = $this->expireAt;
$this->expireAt = $this->securedExpireAt->peek();
}

/**
* {@inheritDoc}
*/
public function secure()
{
$this->holder = $this->number = $this->expireAt = $this->securityCode = null;
}
}
8 changes: 4 additions & 4 deletions Tests/Model/CreditCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function shouldStoreHolderAsSensitiveValue()

$card->setHolder('Mahatma Gandhi');

$value = $this->readAttribute($card, 'holder');
$value = $this->readAttribute($card, 'securedHolder');
$this->assertInstanceOf(SensitiveValue::class, $value);
$this->assertEquals('Mahatma Gandhi', $value->peek());
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function shouldStoreNumberAsSensitiveValue()

$card->setNumber('1234 5678 1234 5678');

$value = $this->readAttribute($card, 'number');
$value = $this->readAttribute($card, 'securedNumber');
$this->assertInstanceOf(SensitiveValue::class, $value);
$this->assertEquals('1234 5678 1234 5678', $value->peek());
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public function shouldStoreSecurityCodeAsSensitiveValue()

$card->setSecurityCode('123');

$value = $this->readAttribute($card, 'securityCode');
$value = $this->readAttribute($card, 'securedSecurityCode');
$this->assertInstanceOf(SensitiveValue::class, $value);
$this->assertEquals('123', $value->peek());
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public function shouldStoreExpireAtAsSensitiveValue()

$card->setExpireAt($expected);

$value = $this->readAttribute($card, 'expireAt');
$value = $this->readAttribute($card, 'securedExpireAt');
$this->assertInstanceOf(SensitiveValue::class, $value);
$this->assertSame($expected, $value->peek());
}
Expand Down

0 comments on commit f008176

Please sign in to comment.