Skip to content

Instantly share code, notes, and snippets.

@dorianneto
Last active January 30, 2018 12:48
Show Gist options
  • Save dorianneto/9b6e122f4f12b1d431cefe1d0cfd153e to your computer and use it in GitHub Desktop.
Save dorianneto/9b6e122f4f12b1d431cefe1d0cfd153e to your computer and use it in GitHub Desktop.
Post: Refatorando código com Extract Method
<?php
$products = [
'Geladeira' => 1500.99,
'Fogão' => 350,
'Celular' => 1190.90
];
function before_add_shopping_cart(array $products): array {
$output = [
'amount' => count($products),
'total' => 'R$ ' . number_format(array_sum($products), 2, ',', '.')
];
$output['items'] = array_map(function($value): string {
return 'R$ ' . number_format($value, 2, ',', '.');
}, $products);
// Send an email to sales team
$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment