Skip to content

Instantly share code, notes, and snippets.

@samadfcibd
Last active July 2, 2020 20:11
Show Gist options
  • Save samadfcibd/69d131c1b915925b09284334a1305e2f to your computer and use it in GitHub Desktop.
Save samadfcibd/69d131c1b915925b09284334a1305e2f to your computer and use it in GitHub Desktop.
<?php
class PaymentService
{
public function payWithPaypal()
{
// pay with paypal
}
public function payWithCreditCard()
{
// pay with credit card
}
public function payWithWireTransfer()
{
// pay with wire transfer
}
}
class PaymentController
{
public function pay(Request $request, PaymentService $paymentService)
{
$payment_type = $request->input('payment_type');
// Here OCP violates !!!
switch ($payment_type) {
case 'Paypal':
$response = $paymentService->payWithPaypal();
break;
case 'Credit Card':
$response = $paymentService->payWithCreditCard();
break;
default:
$response = $paymentService->payWithWireTransfer();
}
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment