Completed
Push — master ( 4a584e...bcb0a1 )
by Andrii
08:31
created

AbstractRequest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 22.22%

Importance

Changes 7
Bugs 1 Features 1
Metric Value
wmc 11
c 7
b 1
f 1
lcom 3
cbo 2
dl 0
loc 100
ccs 4
cts 18
cp 0.2222
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
getWorker() 0 1 ?
A getCurrency() 0 4 1
A getAmount() 0 4 1
A getFee() 0 4 2
A getSum() 0 4 2
A send() 0 4 1
A getType() 0 4 1
A getData() 0 4 1
A __call() 0 8 2
1
<?php
2
3
/*
4
 * Generalization over Omnipay and Payum
5
 *
6
 * @link      https://github.com/hiqdev/php-merchant
7
 * @package   php-merchant
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\php\merchant;
13
14
/**
15
 * AbstractRequest class.
16
 */
17
abstract class AbstractRequest implements RequestInterface
18
{
19
    /**
20
     * @var AbstractMerchant
21
     */
22
    public $merchant;
23
24
    /**
25
     * @var string The type of request. For example:
26
     *  - `purchase`
27
     *  - `completePurchase`
28
     */
29
    public $type;
30
31
    /**
32
     * @var array the data that will be sent to the payment system.
33
     * Might be additionally processed by the implementation of [[AbstractRequest]] class.
34
     */
35
    public $data = [];
36
37
    /**
38
     * The instance of payment processing library.
39
     * @return \Omnipay\Common\Message\AbstractRequest|\Payum\Core\Model\Payment
40
     */
41
    abstract public function getWorker();
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getCurrency()
47
    {
48
        return $this->getWorker()->getCurrency();
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getAmount()
55
    {
56
        return $this->getWorker()->getAmount();
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getFee()
63
    {
64
        return $this->data['fee'] ?: '0';
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getSum()
71
    {
72
        return $this->data['sum'] ?: $this->getAmount() - $this->getFee();
73
    }
74
75
    /**
76
     * @return AbstractResponse
77
     */
78
    public function send()
79
    {
80
        return $this->merchant->response($this);
81
    }
82
83
    /**
84
     * Concrete requests can build type in other way.
85
     *
86
     * @return string
87
     */
88 1
    public function getType()
89
    {
90 1
        return Helper::id2camel($this->type);
91
    }
92
93
    /**
94
     * @return array
95
     */
96 1
    public function getData()
97
    {
98 1
        return $this->data;
99
    }
100
101
    /**
102
     * Use worker's method when possible.
103
     *
104
     * @param $name
105
     * @param $args
106
     * @return mixed|null
107
     */
108
    public function __call($name, $args)
0 ignored issues
show
Duplication introduced by
This method 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...
109
    {
110
        if (method_exists($this->getWorker(), $name)) {
111
            return call_user_func_array([$this->getWorker(), $name], $args);
112
        }
113
114
        return null;
115
    }
116
}
117