Completed
Push — master ( f61599...0b8453 )
by Andrii
08:46
created

AbstractResponse::call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 3
crap 6
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
 * Abstract Response class.
16
 */
17
abstract class AbstractResponse implements ResponseInterface
18
{
19
    /**
20
     * @var ResponseInterface
21
     */
22
    public $merchant;
23
24
    /**
25
     * @var RequestInterface
26
     */
27
    public $request;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    abstract public function redirect();
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    abstract public function isRedirect();
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    abstract public function isSuccessful();
43
44
    /**
45
     * The instance of payment processing library.
46
     * @return \Omnipay\Common\Message\AbstractResponse|\Payum\Core\Model\Response
47
     */
48
    abstract public function getWorker();
49
50
    public function call($name, $args, $default = null)
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...
51
    {
52
        if (method_exists($this->getWorker(), $name)) {
53
            return call_user_func_array([$this->getWorker(), $name], $args);
54
        }
55
56
        return $default;
57
    }
58
59
    public function __call($name, $args)
60
    {
61
        return $this->call($name, $args);
62
    }
63
64
    /**
65
     * Sum = Amount - Fee
66
     */
67
    public function getSum()
68
    {
69
        return $this->call('getSum', [], (float)$this->getAmount() - (float)$this->getFee());
0 ignored issues
show
Documentation Bug introduced by
The method getAmount does not exist on object<hiqdev\php\merchant\AbstractResponse>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
70
    }
71
72
    public function getFee()
73
    {
74
        return $this->call('getFee', [], 0);
75
    }
76
77
    public function getTime()
78
    {
79
        return $this->call('getTime', [], date('c'));
80
    }
81
}
82