Completed
Push — master ( 891443...e38f5c )
by Carlos
03:00
created

CashCoupon   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 81
loc 81
rs 10
c 0
b 0
f 0
ccs 0
cts 20
cp 0
wmc 8
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A setMerchant() 4 4 1
A getMerchant() 4 4 1
A setAPI() 4 4 1
A getAPI() 4 4 2
A __call() 6 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
/**
13
 * LuckyMoney.php.
14
 *
15
 * @author    tianyong90 <[email protected]>
16
 * @copyright 2015 overtrue <[email protected]>
17
 *
18
 * @see      https://github.com/overtrue
19
 * @see      http://overtrue.me
20
 */
21
22
namespace EasyWeChat\Payment\CashCoupon;
23
24
use EasyWeChat\Payment\Merchant;
25
26
/**
27
 * Class LuckyMoney.
28
 */
29 View Code Duplication
class CashCoupon
30
{
31
    /**
32
     * @var API
33
     */
34
    protected $api;
35
36
    /**
37
     * Merchant instance.
38
     *
39
     * @var \EasyWeChat\Payment\Merchant
40
     */
41
    protected $merchant;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param Merchant $merchant
47
     */
48
    public function __construct(Merchant $merchant)
49
    {
50
        $this->merchant = $merchant;
51
    }
52
53
    /**
54
     * Merchant setter.
55
     *
56
     * @param Merchant $merchant
57
     */
58
    public function setMerchant(Merchant $merchant)
59
    {
60
        $this->merchant = $merchant;
61
    }
62
63
    /**
64
     * Merchant getter.
65
     *
66
     * @return Merchant
67
     */
68
    public function getMerchant()
69
    {
70
        return $this->merchant;
71
    }
72
73
    /**
74
     * API setter.
75
     *
76
     * @param API $api
77
     */
78
    public function setAPI(API $api)
79
    {
80
        $this->api = $api;
81
    }
82
83
    /**
84
     * Return API instance.
85
     *
86
     * @return API
87
     */
88
    public function getAPI()
89
    {
90
        return $this->api ?: $this->api = new API($this->getMerchant());
91
    }
92
93
    /**
94
     * Magic call.
95
     *
96
     * @param string $method
97
     * @param array  $args
98
     *
99
     * @return mixed
100
     *
101
     * @codeCoverageIgnore
102
     */
103
    public function __call($method, $args)
104
    {
105
        if (is_callable([$this->getAPI(), $method])) {
106
            return call_user_func_array([$this->api, $method], $args);
107
        }
108
    }
109
}
110