Last active
July 2, 2020 20:11
-
-
Save samadfcibd/69d131c1b915925b09284334a1305e2f to your computer and use it in GitHub Desktop.
This file contains 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 | |
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