Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jul 9, 2024
1 parent 2296bc6 commit 4d094c4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/controllers/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function getHandler(string $controllerName): ?string
); // Replace placeholders with regex capture groups
$pattern = '/^' . $pattern . '$/';

if (preg_match($pattern, '/' . Utility::getURL(), $matches)) {
if (preg_match($pattern, '/' . Utility::getURL())) {
return $handler;
}
}
Expand Down
16 changes: 3 additions & 13 deletions src/controllers/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,8 @@ private function handleCheckout(): void
foreach ($form_data['items'] as $item) {
$line_item = new OrderProduct(
product_id: filter_var($item['productID'], FILTER_VALIDATE_INT),
cup_size: match (strtolower($item['cupSize'])) { // Using match for enum conversion
'small' => OrderCupSize::SMALL,
'medium' => OrderCupSize::MEDIUM,
'large' => OrderCupSize::LARGE,
default => throw new Exception('Invalid cup size: ' . $item['cupSize'])
},
milk_type: match (strtolower($item['milkType'])) { // Using match for enum conversion
'almond' => OrderMilkType::ALMOND,
'coconut' => OrderMilkType::COCONUT,
'oat' => OrderMilkType::OAT,
'soy' => OrderMilkType::SOY,
default => throw new Exception('Invalid milk type: ' . $item['milkType'])
},
cup_size: OrderCupSize::from(strtolower($item['cupSize'])),
milk_type: OrderMilkType::from(strtolower($item['milkType'])),
quantity: filter_var($item['quantity'], FILTER_VALIDATE_INT)
);
$new_order->addLineItem($line_item);
Expand Down Expand Up @@ -154,6 +143,7 @@ private function handleCheckout(): void
if (!$success_mail) {
http_response_code(503);
echo json_encode(['error' => "Order was saved but email could not be sent for an unknown reason."]);
return;
}

// if everything is good, tell client to reset the document view
Expand Down
79 changes: 45 additions & 34 deletions src/views/mails/Contact.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?php

declare(strict_types=1);

/**
* View for contact us page
*
* @var string $first_name First name of sender
* @var string $last_name Last name of sender
* @var string $email Email of sender
* @var string $message Message of sender
*/
?>
<!DOCTYPE html>
<html lang="en">
Expand All @@ -10,42 +17,46 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Contact Message</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f4f4f4;
padding: 20px;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h2 {
color: #555;
}
p {
margin: 0 0 10px;
}
.footer {
margin-top: 20px;
font-size: 0.9em;
color: #888;
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f4f4f4;
padding: 20px;
}

.container {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

h2 {
color: #555;
}

p {
margin: 0 0 10px;
}

.footer {
margin-top: 20px;
font-size: 0.9em;
color: #888;
}
</style>
</head>
<body>
<div class="container">
<h2>New Contact Message</h2>
<p><strong>Name:</strong> <?= htmlspecialchars($first_name) ?> <?= htmlspecialchars($last_name) ?></p>
<p><strong>Email:</strong> <?= htmlspecialchars($email) ?></p>
<p><strong>Message:</strong></p>
<p><?= nl2br(htmlspecialchars($message)) ?></p>
<div class="footer">
<p>This message was sent via the contact form on your website.</p>
</div>
<div class="container">
<h2>New Contact Message</h2>
<p><strong>Name:</strong> <?= htmlspecialchars($first_name) ?> <?= htmlspecialchars($last_name) ?></p>
<p><strong>Email:</strong> <?= htmlspecialchars($email) ?></p>
<p><strong>Message:</strong></p>
<p><?= nl2br(htmlspecialchars($message)) ?></p>
<div class="footer">
<p>This message was sent via the contact form on your website.</p>
</div>
</div>
</body>
</html>

0 comments on commit 4d094c4

Please sign in to comment.