From 8e81cf36ff28fb76a7881dad9217f1f04188e354 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Mar 2025 10:21:15 +0100 Subject: [PATCH 1/3] Cast creditcard number to string --- src/Common/CreditCard.php | 6 ++++-- src/Common/Helper.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Common/CreditCard.php b/src/Common/CreditCard.php index 45a0847..a1f97d0 100644 --- a/src/Common/CreditCard.php +++ b/src/Common/CreditCard.php @@ -377,7 +377,7 @@ public function getNumber() public function setNumber($value) { // strip non-numeric characters - return $this->setParameter('number', preg_replace('/\D/', '', $value)); + return $this->setParameter('number', preg_replace('/\D/', '', (string) $value)); } /** @@ -412,8 +412,10 @@ public function getNumberMasked($mask = 'X') */ public function getBrand() { + $number = (string) $this->getNumber(); + foreach ($this->getSupportedBrands() as $brand => $val) { - if (preg_match($val, $this->getNumber())) { + if (preg_match($val, $number)) { return $brand; } } diff --git a/src/Common/Helper.php b/src/Common/Helper.php index e03dfb5..7886aec 100644 --- a/src/Common/Helper.php +++ b/src/Common/Helper.php @@ -63,7 +63,7 @@ protected static function convertToLowercase($str) public static function validateLuhn($number) { $str = ''; - foreach (array_reverse(str_split($number)) as $i => $c) { + foreach (array_reverse(str_split((string) $number)) as $i => $c) { $str .= $i % 2 ? $c * 2 : $c; } From a6d9eac42b91942f8c94e37aeb35b9cc2c480733 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Mar 2025 10:21:22 +0100 Subject: [PATCH 2/3] Set properties for test --- tests/Common/GatewayFactoryTest.php | 3 +++ tests/Common/ItemBagTest.php | 3 +++ tests/Common/ItemTest.php | 3 +++ 3 files changed, 9 insertions(+) diff --git a/tests/Common/GatewayFactoryTest.php b/tests/Common/GatewayFactoryTest.php index 25dba51..45cccb4 100644 --- a/tests/Common/GatewayFactoryTest.php +++ b/tests/Common/GatewayFactoryTest.php @@ -7,6 +7,9 @@ class GatewayFactoryTest extends TestCase { + /** @var GatewayFactory */ + protected $factory; + public static function setUpBeforeClass() : void { m::mock('alias:Omnipay\\SpareChange\\TestGateway'); diff --git a/tests/Common/ItemBagTest.php b/tests/Common/ItemBagTest.php index 4552b9c..460690e 100644 --- a/tests/Common/ItemBagTest.php +++ b/tests/Common/ItemBagTest.php @@ -6,6 +6,9 @@ class ItemBagTest extends TestCase { + /** @var ItemBag */ + protected $bag; + public function setUp() : void { $this->bag = new ItemBag; diff --git a/tests/Common/ItemTest.php b/tests/Common/ItemTest.php index 4e22db1..c653e64 100644 --- a/tests/Common/ItemTest.php +++ b/tests/Common/ItemTest.php @@ -6,6 +6,9 @@ class ItemTest extends TestCase { + /** @var Item */ + protected $item; + public function setUp() : void { $this->item = new Item; From f02c12a955ed62e167b849950b59c7bd9add3460 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Mar 2025 10:22:00 +0100 Subject: [PATCH 3/3] Cast htmlentities to string --- src/Common/Message/AbstractResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/Message/AbstractResponse.php b/src/Common/Message/AbstractResponse.php index e958f4b..d78f21a 100644 --- a/src/Common/Message/AbstractResponse.php +++ b/src/Common/Message/AbstractResponse.php @@ -215,7 +215,7 @@ public function getRedirectResponse() $hiddenFields .= sprintf( '', htmlentities($key, ENT_QUOTES, 'UTF-8', false), - htmlentities($value, ENT_QUOTES, 'UTF-8', false) + htmlentities((string) $value, ENT_QUOTES, 'UTF-8', false) )."\n"; }