Test Failed
Branch master (3f2e80)
by Gabriel
03:43 queued 01:39
created

Gateway   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 27
c 1
b 0
f 0
dl 0
loc 116
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A serverCompletePurchase() 0 2 1
A getName() 0 3 1
A setTestMode() 0 5 1
A completePurchase() 0 5 1
A setApiUrl() 0 3 1
A getApiUrl() 0 6 2
A capture() 0 5 1
A getDefaultParameters() 0 7 1
A purchase() 0 5 1
1
<?php
2
3
namespace ByTIC\Omnipay\Paylike;
4
5
use ByTIC\Omnipay\Paylike\Message\CaptureRequest;
6
use ByTIC\Omnipay\Paylike\Message\CompletePurchaseRequest;
7
use ByTIC\Omnipay\Paylike\Message\PurchaseRequest;
8
//use ByTIC\Omnipay\Paylike\Message\ServerCompletePurchaseRequest;
9
use ByTIC\Omnipay\Paylike\Traits\HasKeysTrait;
10
use Omnipay\Common\AbstractGateway;
11
use Omnipay\Common\Message\NotificationInterface;
12
use Omnipay\Common\Message\RequestInterface;
13
14
/**
15
 * Class Gateway
16
 * @package ByTIC\Omnipay\Paylike
17
 *
18
 * @method RequestInterface authorize(array $options = [])
19
 * @method RequestInterface completeAuthorize(array $options = [])
20
 * @method RequestInterface refund(array $options = [])
21
 * @method RequestInterface void(array $options = [])
22
 * @method RequestInterface createCard(array $options = [])
23
 * @method RequestInterface updateCard(array $options = [])
24
 * @method RequestInterface deleteCard(array $options = [])
25
 * @method RequestInterface fetchTransaction(array $options = [])
26
 * @method NotificationInterface acceptNotification(array $options = array())
27
 */
28
class Gateway extends AbstractGateway
29
{
30
    use HasKeysTrait;
31
32
    const VERSION = '1.0';
33
34
    /**
35
     * @var string
36
     */
37
    private $prodApiHost = 'https://api.Paylike.com';
38
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function getName()
44
    {
45
        return 'Paylike';
46
    }
47
48
    // ------------ REQUESTS ------------ //
49
50
    /**
51
     * @inheritdoc
52
     * @return PurchaseRequest
53
     */
54
    public function purchase(array $parameters = []): RequestInterface
55
    {
56
        return $this->createRequest(
57
            PurchaseRequest::class,
58
            array_merge($this->getDefaultParameters(), $parameters)
59
        );
60
    }
61
62
    /** @noinspection PhpMissingParentCallCommonInspection
63
     *
64
     * {@inheritdoc}
65
     */
66
    public function getDefaultParameters()
67
    {
68
        return [
69
            'testMode' => true, // Must be the 1st in the list!
70
            'publicKey' => $this->getPublicKey(),
71
            'privateKey' => $this->getPrivateKey(),
72
            'apiUrl' => $this->getApiUrl()
73
        ];
74
    }
75
76
    // ------------ PARAMETERS ------------ //
77
78
    /**
79
     * @param  boolean $value
80
     * @return $this|AbstractGateway
81
     */
82
    public function setTestMode($value)
83
    {
84
        $this->parameters->remove('apiUrl');
85
        $this->parameters->remove('secureUrl');
86
        return parent::setTestMode($value);
87
    }
88
89
    // ------------ Getter'n'Setters ------------ //
90
91
    /**
92
     * Get live- or testURL.
93
     */
94
    public function getApiUrl()
95
    {
96
        $defaultUrl = $this->getTestMode() === false
97
            ? $this->prodApiHost
98
            : $this->prodApiHost;
99
        return $this->parameters->get('apiUrl', $defaultUrl);
100
    }
101
102
    /**
103
     * @inheritdoc
104
     * @return CompletePurchaseRequest
105
     */
106
    public function completePurchase(array $parameters = []): RequestInterface
107
    {
108
        return $this->createRequest(
109
            CompletePurchaseRequest::class,
110
            array_merge($this->getDefaultParameters(), $parameters)
111
        );
112
    }
113
114
    /**
115
     * @inheritdoc
116
     * @return CaptureRequest
117
     */
118
    public function capture(array $parameters = []): RequestInterface
119
    {
120
        return $this->createRequest(
121
            CaptureRequest::class,
122
            array_merge($this->getDefaultParameters(), $parameters)
123
        );
124
    }
125
126
    /**
127
     * @inheritdoc
128
     */
129
    public function serverCompletePurchase(array $parameters = []): RequestInterface
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

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

129
    public function serverCompletePurchase(/** @scrutinizer ignore-unused */ array $parameters = []): RequestInterface

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
    {
131
//        return $this->createRequest(
132
//            ServerCompletePurchaseRequest::class,
133
//            array_merge($this->getDefaultParameters(), $parameters)
134
//        );
135
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Omnipay\Common\Message\RequestInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
136
137
    /**
138
     * @param $value
139
     * @return $this
140
     */
141
    public function setApiUrl($value)
142
    {
143
        return $this->setParameter('apiUrl', $value);
144
    }
145
}
146