Last active
January 30, 2018 12:48
-
-
Save dorianneto/9b6e122f4f12b1d431cefe1d0cfd153e to your computer and use it in GitHub Desktop.
Post: Refatorando código com Extract Method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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