From 601b2e10ea46f09523e9da38840b0a4baadeae1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Sat, 2 Sep 2023 23:07:21 +0200 Subject: [PATCH 1/8] codestyle Change-Id: I027d3351fc77193d610b24d200c75cc733639717 --- index.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/index.php b/index.php index b4ad82b..4910f97 100644 --- a/index.php +++ b/index.php @@ -5,19 +5,21 @@ ?> - - commit hygiene example - + + commit hygiene example +
-
-
+
+ +
-
-
+
+ +
-
+
@@ -25,13 +27,15 @@ - +?> + - commit hygiene example + commit hygiene example -

getFirstName() . ' ' . $user->getLastName()?>

-

getStreet()?>
getZip()?> getCity()?> +

getFirstName() . ' ' . $user->getLastName() ?>

+

+ getStreet() ?>
+ getZip() ?> getCity() ?>

@@ -41,5 +45,3 @@ - - From fdce4b764c0d25ba9eab8e7d08eaccbdf10f2444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Sat, 2 Sep 2023 23:57:13 +0200 Subject: [PATCH 2/8] fix php require and closing tag Change-Id: I5b8aaec2274c5d4aea01a6389c73f599f98377ac --- index.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.php b/index.php index 4910f97..31951e4 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,5 @@ @@ -44,4 +44,3 @@ From 61b1b7e5b11b88f4d86fda9ce0f2853eabfe7e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Sat, 2 Sep 2023 23:57:46 +0200 Subject: [PATCH 3/8] escape output to prevent code injection Change-Id: Id3e15b4bf37e8b2c92acc4624015a55bfd9beb46 --- index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 31951e4..e7fffec 100644 --- a/index.php +++ b/index.php @@ -32,10 +32,10 @@ commit hygiene example -

getFirstName() . ' ' . $user->getLastName() ?>

+

getFirstName() . ' ' . $user->getLastName(), ENT_HTML5) ?>

- getStreet() ?>
- getZip() ?> getCity() ?> + getStreet(), ENT_HTML5) ?>
+ getZip(), ENT_HTML5) ?> getCity(), ENT_HTML5) ?>

From a9c413aa6c2355e99e2daedbcbe9d6a65c08c15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Sat, 2 Sep 2023 23:58:04 +0200 Subject: [PATCH 4/8] doctype html5 for output Change-Id: I3d46c22ed9e5184a967e85534216970e0fc1d299 --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index e7fffec..a6dfd9b 100644 --- a/index.php +++ b/index.php @@ -28,7 +28,7 @@ } else { $user = new User($_GET); ?> - + commit hygiene example From 409c534a3eb301cb2456348ebdc42441725eadee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Sat, 2 Sep 2023 23:58:22 +0200 Subject: [PATCH 5/8] simplify form labels Change-Id: I78d42f5969658c389f3525160d637cc8fc8807ef --- index.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index a6dfd9b..f7074a2 100644 --- a/index.php +++ b/index.php @@ -10,16 +10,11 @@ - -
- -
- -
- -
- -
+
+
+
+
+
From 503f4f30ffb787185f5c9d52cd677f219a8be42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Sat, 2 Sep 2023 23:59:40 +0200 Subject: [PATCH 6/8] remove "new"-button -> use browser "back" Change-Id: I454520d590b4346e52f84fa9d8eafb711e639ecc --- index.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.php b/index.php index f7074a2..adb7e30 100644 --- a/index.php +++ b/index.php @@ -32,9 +32,6 @@ getStreet(), ENT_HTML5) ?>
getZip(), ENT_HTML5) ?> getCity(), ENT_HTML5) ?>

-
- -
Date: Sun, 3 Sep 2023 00:00:24 +0200 Subject: [PATCH 7/8] abstract Address from User Change-Id: If105072e08c6a8e7686b4aa6227e2b0e630ed514 --- dto.php | 25 +++++++++++++++++++------ index.php | 10 +++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/dto.php b/dto.php index f2ad13f..920c8dc 100644 --- a/dto.php +++ b/dto.php @@ -3,16 +3,13 @@ class User { private string $firstName; private string $lastName; - private string $street; - private string $zip; - private string $city; + + private Address $address; public function __construct(array $data) { $this->firstName = $data['firstName']; $this->lastName = $data['lastName']; - $this->street = $data['street']; - $this->zip = $data['zip']; - $this->city = $data['city']; + $this->address = new Address($data['address']); } public function getFirstName(): string { @@ -23,6 +20,22 @@ public function getLastName(): string { return $this->lastName; } + public function getAddress(): Address { + return $this->address; + } +} + +class Address { + private string $street; + private string $zip; + private string $city; + + public function __construct(array $data) { + $this->street = $data['street']; + $this->zip = $data['zip']; + $this->city = $data['city']; + } + public function getStreet(): string { return $this->street; } diff --git a/index.php b/index.php index adb7e30..4aba675 100644 --- a/index.php +++ b/index.php @@ -12,9 +12,9 @@


-
-
-
+
+
+
@@ -29,8 +29,8 @@

getFirstName() . ' ' . $user->getLastName(), ENT_HTML5) ?>

- getStreet(), ENT_HTML5) ?>
- getZip(), ENT_HTML5) ?> getCity(), ENT_HTML5) ?> + getAddress()->getStreet(), ENT_HTML5) ?>
+ getAddress()->getZip(), ENT_HTML5) ?> getAddress()->getCity(), ENT_HTML5) ?>

From dae2edc6f575cddbaeedce568c97152f8efa06dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Sat, 2 Sep 2023 23:50:46 +0200 Subject: [PATCH 8/8] allow to set a separate delivery address Change-Id: Iaf90a2b6e7cf0e4af2f486170d7079f1c4300152 --- dto.php | 16 ++++++++++++---- index.php | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/dto.php b/dto.php index 920c8dc..a94ff80 100644 --- a/dto.php +++ b/dto.php @@ -4,12 +4,16 @@ class User { private string $firstName; private string $lastName; - private Address $address; + private Address $invoiceAddress; + private Address|null $deliveryAddress = null; public function __construct(array $data) { $this->firstName = $data['firstName']; $this->lastName = $data['lastName']; - $this->address = new Address($data['address']); + $this->invoiceAddress = new Address($data['invoiceAddress']); + if (empty($data['deliveryAddress']['street'])) { + $this->deliveryAddress = new Address($data['deliveryAddress']); + } } public function getFirstName(): string { @@ -20,8 +24,12 @@ public function getLastName(): string { return $this->lastName; } - public function getAddress(): Address { - return $this->address; + public function getInvoiceAddress(): Address { + return $this->invoiceAddress; + } + + public function getDeliveryAddress(): Address { + return $this->deliveryAddress ?: $this->invoiceAddress; } } diff --git a/index.php b/index.php index 4aba675..df51736 100644 --- a/index.php +++ b/index.php @@ -12,9 +12,14 @@


-
-
-
+

invoice address

+
+
+
+

delivery address (optional)

+
+
+
@@ -28,9 +33,15 @@ commit hygiene example

getFirstName() . ' ' . $user->getLastName(), ENT_HTML5) ?>

+

invoice address

- getAddress()->getStreet(), ENT_HTML5) ?>
- getAddress()->getZip(), ENT_HTML5) ?> getAddress()->getCity(), ENT_HTML5) ?> + getInvoiceAddress()->getStreet(), ENT_HTML5) ?>
+ getInvoiceAddress()->getZip(), ENT_HTML5) ?> getInvoiceAddress()->getCity(), ENT_HTML5) ?> +

+

delivery address

+

+ getDeliveryAddress()->getStreet(), ENT_HTML5) ?>
+ getDeliveryAddress()->getZip(), ENT_HTML5) ?> getDeliveryAddress()->getCity(), ENT_HTML5) ?>