Created
January 30, 2018 12:53
-
-
Save dorianneto/14f7cd42981f0c24a77a2381b95bebaa 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 format_currency($value): string { | |
return 'R$ ' . number_format($value, 2, ',', '.'); | |
} | |
function 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(); | |
return mail($to, $subject, $message, $headers); | |
} | |
function before_add_shopping_cart(array $products): array { | |
$output = [ | |
'amount' => count($products), | |
'total' => format_currency(array_sum($products)) | |
]; | |
$output['items'] = array_map('format_currency', $products); | |
email_to_sales_team(); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment