Skip to content

Instantly share code, notes, and snippets.

@young-steveo
Last active June 20, 2018 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save young-steveo/e9af762d4a21ea03387e88b8b7c2dc47 to your computer and use it in GitHub Desktop.
Save young-steveo/e9af762d4a21ea03387e88b8b7c2dc47 to your computer and use it in GitHub Desktop.
Array Oriented Programming - Bad Example
<?php
final class Payment {
public function subscribe(array $transaction) : array {
// 1
$transaction = [
'payment_method' => $transaction['payment_method'] ?? 'credit-card',
'amount' => $transaction['total'] ?? $transaction['subtotal'] ?? 0.0,
'currency' => $transaction['currency_code'] ?? 'USD'
] + $transaction;
$model = new TransactionModel();
$model->create($transaction);
// 2
$processor = $model->getProcessor($transaction);
$transaction['processor_id'] = $processor['id'] ?? null;
// 3
$status = $model->process($transaction);
$transaction['status'] = $status['success'] ?? false;
// 4
unset($transaction['card-number'], $transaction['ccv']);
return $transaction;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment