Code Duplication    Length = 22-29 lines in 2 locations

src/PdoCouponsFactory.php 1 location

@@ 23-44 (lines=22) @@
20
     * @param string $coupons_table
21
     * @param string $php_class
22
     */
23
    public function __construct( \PDO $pdo, $coupons_table, $php_class = null)
24
    {
25
        $this->php_class = $php_class ?: Coupon::class;
26
27
        if (!is_subclass_of($this->php_class, CouponInterface::class ))
28
            throw new \InvalidArgumentException("Class name or instance of CouponInterface expected.");
29
30
        $sql = "SELECT
31
        -- id field twice here due to FETCH_UNIQUE
32
        id,
33
        id,
34
        code,
35
        coupon_sheet_id
36
37
        FROM `{$coupons_table}`
38
39
        WHERE coupon_sheet_id = :sheet_id";
40
41
        $this->stmt = $pdo->prepare( $sql );
42
        $this->stmt->setFetchMode( \PDO::FETCH_CLASS, $this->php_class );
43
44
    }
45
46
    /**
47
     * @param  int|CouponSheetInterface $sheet_id

src/PdoCouponSheetFactory.php 1 location

@@ 23-51 (lines=29) @@
20
     * @param string $coupons_table
21
     * @param string $php_class
22
     */
23
    public function __construct( \PDO $pdo, $sheets_table, $coupons_table, $php_class = null)
24
    {
25
        $this->php_class = $php_class ?: CouponSheet::class;
26
27
        if (!is_subclass_of($this->php_class, CouponSheetInterface::class ))
28
            throw new \InvalidArgumentException("Class name or instance of CouponSheetInterface expected.");
29
30
        $sql = "SELECT
31
        Sheets.id,
32
        Sheets.slug,
33
        Sheets.name,
34
        Sheets.quantity,
35
        Sheets.valid_from,
36
        Sheets.valid_until,
37
        GROUP_CONCAT(Coupons.code) AS coupons
38
39
        FROM `{$sheets_table}` Sheets
40
41
        RIGHT JOIN `{$coupons_table}` Coupons
42
        ON Coupons.coupon_sheet_id = Sheets.id
43
44
        WHERE Sheets.id   = :id
45
        OR    Sheets.slug = :id
46
        LIMIT 1";
47
48
        $this->stmt = $pdo->prepare( $sql );
49
        $this->stmt->setFetchMode( \PDO::FETCH_CLASS, $this->php_class );
50
51
    }
52
53
    /**
54
     * @param  string|int $id