Passed
Branch master (7fc895)
by João Felipe Magro
03:00
created

Transaction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Ipag\Classes;
4
5
use Ipag\Classes\Enum\Action;
6
use Ipag\Classes\Enum\Operation;
7
use Ipag\Classes\Serializer\PaymentSerializer;
8
use Ipag\Classes\Serializer\Serializer;
9
use Ipag\Ipag;
10
use stdClass;
11
12
final class Transaction extends IpagResource
13
{
14
    /**
15
     * @var Order
16
     */
17
    private $order;
18
19
    /**
20
     * @var string
21
     */
22
    private $tid;
23
24
    public function __construct(Ipag $ipag)
25
    {
26
        parent::__construct($ipag);
27
        $this->apiService = new Services\ApiActionService($this);
0 ignored issues
show
Unused Code introduced by
The call to Ipag\Classes\Services\Ap...nService::__construct() has too many arguments starting with $this. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        $this->apiService = /** @scrutinizer ignore-call */ new Services\ApiActionService($this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getTid()
34
    {
35
        return $this->tid;
36
    }
37
38
    /**
39
     * @param string $tid
40
     */
41
    public function setTid($tid)
42
    {
43
        $this->tid = $tid;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @return Order
50
     */
51
    public function getOrder()
52
    {
53
        if (is_null($this->order)) {
54
            $this->order = new Order();
55
        }
56
57
        return $this->order;
58
    }
59
60
    /**
61
     * @param Order $order
62
     */
63
    public function setOrder(Order $order)
64
    {
65
        $this->order = $order;
66
67
        return $this;
68
    }
69
70
    public function populate(stdClass $response)
71
    {
72
        return (new Services\TransactionResponseService())->populate($response);
73
    }
74
75
    public function execute()
76
    {
77
        return $this->apiService
78
            ->execute(new PaymentSerializer($this, Action::PAYMENT, Operation::PAYMENT));
79
    }
80
81
    public function consult()
82
    {
83
        return $this->apiService
84
            ->execute(new Serializer($this, Action::CONSULT, Operation::CONSULT));
85
    }
86
87
    public function cancel()
88
    {
89
        return $this->apiService
90
            ->execute(new Serializer($this, Action::CANCEL, Operation::CANCEL));
91
    }
92
93
    public function capture()
94
    {
95
        return $this->apiService
96
            ->execute(new Serializer($this, Action::CAPTURE, Operation::CAPTURE));
97
    }
98
99
    private function authenticate()
100
    {
101
        $authentication = $this->getIpag()->getAuthentication();
102
        $this->getOnlyPostClient()
103
            ->setUser($authentication->getIdentification())
0 ignored issues
show
Bug introduced by
The method setUser() does not exist on Ipag\Classes\Http\OnlyPostHttpClientInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ipag\Classes\Http\OnlyPostHttpClientInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
            ->/** @scrutinizer ignore-call */ setUser($authentication->getIdentification())
Loading history...
104
            ->setPassword($authentication->getApiKey());
105
106
        return $this;
107
    }
108
109
    public function sendHttpRequest($endpoint, $parameters)
110
    {
111
        $this->authenticate();
112
113
        return parent::sendHttpRequest($endpoint, $parameters);
114
    }
115
}
116