Completed
Pull Request — master (#243)
by Carlos
08:39 queued 04:59
created

LuckyMoney::getMerchant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\Payment\LuckyMoney;
22
23
use EasyWeChat\Payment\Merchant;
24
25
/**
26
 * Class LuckyMoney.
27
 */
28 View Code Duplication
class LuckyMoney
2 ignored issues
show
Comprehensibility Best Practice introduced by
The type EasyWeChat\Payment\LuckyMoney\LuckyMoney has been defined more than once; this definition is ignored, only the first definition in src/Payment/luckymoney/LuckyMoney.php (L28-108) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Comprehensibility Best Practice introduced by
The type EasyWeChat\Payment\LuckyMoney\LuckyMoney has been defined more than once; this definition is ignored, only the first definition in src/Payment/luckymoney/LuckyMoney.php (L28-108) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
{
30
    /**
31
     * @var API
32
     */
33
    protected $api;
34
35
    /**
36
     * Merchant instance.
37
     *
38
     * @var \EasyWeChat\Payment\Merchant
39
     */
40
    protected $merchant;
41
42
    /**
43
     * Constructor.
44
     *
45
     * @param Merchant $merchant
46
     */
47
    public function __construct(Merchant $merchant)
48
    {
49
        $this->merchant = $merchant;
50
    }
51
52
    /**
53
     * Merchant setter.
54
     *
55
     * @param Merchant $merchant
56
     */
57
    public function setMerchant(Merchant $merchant)
58
    {
59
        $this->merchant = $merchant;
60
    }
61
62
    /**
63
     * Merchant getter.
64
     *
65
     * @return Merchant
66
     */
67
    public function getMerchant()
68
    {
69
        return $this->merchant;
70
    }
71
72
    /**
73
     * API setter.
74
     *
75
     * @param API $api
76
     */
77
    public function setAPI(API $api)
78
    {
79
        $this->api = $api;
80
    }
81
82
    /**
83
     * Return API instance.
84
     *
85
     * @return API
86
     */
87
    public function getAPI()
88
    {
89
        return $this->api ?: $this->api = new API($this->getMerchant());
90
    }
91
92
    /**
93
     * Magic call.
94
     *
95
     * @param string $method
96
     * @param array  $args
97
     *
98
     * @return mixed
99
     *
100
     * @codeCoverageIgnore
101
     */
102
    public function __call($method, $args)
103
    {
104
        if (is_callable([$this->getAPI(), $method])) {
105
            return call_user_func_array([$this->api, $method], $args);
106
        }
107
    }
108
}
109