From 59f96afd7bc0b84d865c5a481dac2daacdf62f94 Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Tue, 6 Jun 2023 13:48:26 +0100 Subject: [PATCH 1/2] =?UTF-8?q?CLA-32=20=E2=80=93=20truncate=20name=20fiel?= =?UTF-8?q?ds=20to=20meet=20schema=20validation=20requirements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Individual.php | 11 ++++++----- tests/GovTalk/GiftAid/IndividualTest.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Individual.php b/src/Individual.php index 8d9967b..d97abe1 100644 --- a/src/Individual.php +++ b/src/Individual.php @@ -15,12 +15,13 @@ class Individual public function __construct($title, $name, $surname, $phone, $houseNum, $postcode, $overseas = false) { $this->title = $title; - $this->surname = $surname; - $this->forename = $name; $this->phone = $phone; - $this->houseNum = $houseNum; $this->postcode = $postcode; $this->isOverseas = $overseas; + + $this->setForename($name); + $this->setSurname($surname); + $this->setHouseNum($houseNum); } public function getTitle() @@ -40,7 +41,7 @@ public function getSurname() public function setSurname($value) { - $this->surname = $value; + $this->surname = substr($value, 0, 35); } public function getForename() @@ -50,7 +51,7 @@ public function getForename() public function setForename($value) { - $this->forename = $value; + $this->forename = substr($value, 0, 35); } public function getPhone() diff --git a/tests/GovTalk/GiftAid/IndividualTest.php b/tests/GovTalk/GiftAid/IndividualTest.php index b0f6199..62ee1c8 100644 --- a/tests/GovTalk/GiftAid/IndividualTest.php +++ b/tests/GovTalk/GiftAid/IndividualTest.php @@ -42,6 +42,22 @@ public function testIndividualCreation() $this->assertEquals($this->individual->getIsOverseas(), 'no'); } + public function testIndividualCreationWithLongNameAndAddressValues() + { + $testIndividual = new Individual( + title: '', + name: str_repeat('a', 36), + surname: str_repeat('b', 36), + houseNum: str_repeat('c', 41), + postcode: 'N11XX', + phone: '07777 777777', + ); + + $this->assertEquals(35, strlen($testIndividual->getForename())); + $this->assertEquals(35, strlen($testIndividual->getSurname())); + $this->assertEquals(40, strlen($testIndividual->getHouseNum())); + } + public function testForeignIndividualCreation() { $this->assertEquals($this->foreign->getTitle(), 'Ds'); From c7d0b936df3240bd2d09a4d08b03c87f496890af Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Tue, 6 Jun 2023 16:50:28 +0100 Subject: [PATCH 2/2] =?UTF-8?q?CLA-32=20=E2=80=93=20make=20substring=20for?= =?UTF-8?q?matting=20multibyte-safe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + src/Individual.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ea15727..d37185e 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "require": { "php": "^8.0", "ext-dom": "*", + "ext-mbstring": "*", "ext-simplexml": "*", "ext-xmlwriter": "*", "ext-zlib": "*", diff --git a/src/Individual.php b/src/Individual.php index d97abe1..a4f8730 100644 --- a/src/Individual.php +++ b/src/Individual.php @@ -41,7 +41,7 @@ public function getSurname() public function setSurname($value) { - $this->surname = substr($value, 0, 35); + $this->surname = mb_substr($value, 0, 35); } public function getForename() @@ -51,7 +51,7 @@ public function getForename() public function setForename($value) { - $this->forename = substr($value, 0, 35); + $this->forename = mb_substr($value, 0, 35); } public function getPhone() @@ -71,7 +71,7 @@ public function getHouseNum() public function setHouseNum($value) { - $this->houseNum = substr($value, 0, 40); + $this->houseNum = mb_substr($value, 0, 40); } public function getPostcode()