Senior
4 ตุลาคม 2569

หาบั๊กให้เจอ: Laravel

โค้ดหนึ่งชิ้น หาบั๊กให้เจอ หรือพิสูจน์ว่าไม่มีบั๊ก

php
1<?php
2
3namespace App\Payments;
4
5interface PaymentGatewayFactoryInterface
6{
7    public function create(): PaymentGatewayInterface;
8}
9
10class StripeGatewayFactory implements PaymentGatewayFactoryInterface
11{
12    public function create(): PaymentGatewayInterface
13    {
14        return new StripeGateway(config('services.stripe.secret'));
15    }
16}
17
18class PaymentService
19{
20    public function __construct(private PaymentGatewayFactoryInterface $factory) {}
21
22    public function charge(int $cents): void
23    {
24        $this->factory->create()->charge($cents);
25    }
26}
27

คลิกบรรทัดที่เป็นต้นเหตุของปัญหา

คำตัดสินของคุณ

วันละหนึ่งครั้ง คำตอบจะแสดงทันทีหลังจากนั้น

รักษาสถิติต่อเนื่องของคุณ

สร้างบัญชีเพื่อเก็บสถิติต่อเนื่องและติดตามความคืบหน้า

สร้างบัญชี