Passed
Push — master ( 1803d2...fbfbcb )
by Gabriel
06:19
created

GatewayTrait::getLogo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits;
4
5
use ByTIC\Common\Records\Record;
6
use ByTIC\Common\Records\Traits\Media\Files\RecordTrait as HasFilesRecord;
7
use ByTIC\Payments\Gateways\Manager;
8
use ByTIC\Payments\Models\Methods\Traits\RecordTrait as PaymentMethodRecord;
9
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
10
use ByTIC\Payments\Utility\GatewayImages;
11
use Nip\Utility\Traits\NameWorksTrait;
12
use Omnipay\Common\Message\RequestInterface;
13
use Symfony\Component\HttpFoundation\Request as HttpRequest;
14
15
/**
16
 * Class Gateway
17
 * @package ByTIC\Payments\Gateways\Providers\AbstractGateway
18
 *
19
 * @property $parameters \Symfony\Component\HttpFoundation\ParameterBag
20
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $parameters at position 0 could not be parsed: Unknown type name '$parameters' at position 0 in $parameters.
Loading history...
21
trait GatewayTrait
22
{
23
    use NameWorksTrait;
24
    use MagicMessagesTrait;
25
    use HasFormsTrait;
26
    use DetectFromHttpRequestTrait;
27
    use OverwriteCompletePurchaseTrait;
28
29
30
    /**
31
     * @var null|string
32
     */
33
    protected $name = null;
34
35
    /**
36
     * @var null|string
37
     */
38
    protected $label = null;
39
40
    /**
41
     * @var Manager
42
     */
43
    protected $manager;
44
45
    /**
46
     * @var PaymentMethodRecord
47
     */
48
    protected $paymentMethod;
49
50
51
52
    /**
53
     * @param IsPurchasableModelTrait $record
54
     * @return RequestInterface
55
     */
56 7
    public function purchaseFromModel($record)
57
    {
58 7
        $parameters = $record->getPurchaseParameters();
59
60 7
        return $this->purchase($parameters);
0 ignored issues
show
Bug introduced by
The method purchase() does not exist on ByTIC\Payments\Gateways\...way\Traits\GatewayTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

60
        return $this->/** @scrutinizer ignore-call */ purchase($parameters);
Loading history...
61
    }
62
63
    /**
64
     * @return null|string
65
     */
66 1
    public function getName()
67
    {
68 1
        if ($this->name === null) {
69 1
            $this->initName();
70
        }
71
72 1
        return $this->name;
73
    }
74
75
    // ------------ GETTERS & SETTERS ------------ //
76
77
    /**
78
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
79
     */
80 1
    public function setName($name)
81
    {
82 1
        $this->name = $name;
83 1
    }
84
85 1
    public function initName()
86
    {
87 1
        $this->setName($this->generateName());
88 1
    }
89
90
    /**
91
     * @return string
92
     */
93 1
    protected function generateName()
94
    {
95 1
        return strtolower($this->getLabel());
96
    }
97
98
    /**
99
     * @return null|string
100
     */
101 1
    public function getLabel()
102
    {
103 1
        if ($this->label === null) {
104 1
            $this->initLabel();
105
        }
106
107 1
        return $this->label;
108
    }
109
110
    /**
111
     * @param null|string $label
112
     */
113 1
    public function setLabel($label)
114
    {
115 1
        $this->label = $label;
116 1
    }
117
118 1
    public function initLabel()
119
    {
120 1
        $this->setLabel($this->generateLabel());
121 1
    }
122
123
    /**
124
     * @return string
125
     */
126 1
    public function generateLabel()
127
    {
128 1
        return $this->getNamespaceParentFolder();
129
    }
130
131
    /**
132
     * @param $value
133
     * @return mixed
134
     */
135
    public function setSandbox($value)
136
    {
137
        $return = $this->setParameter('sandbox', $value);
0 ignored issues
show
Bug introduced by
The method setParameter() does not exist on ByTIC\Payments\Gateways\...way\Traits\GatewayTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

137
        /** @scrutinizer ignore-call */ 
138
        $return = $this->setParameter('sandbox', $value);
Loading history...
138
        $this->setTestMode($this->getSandbox() == 'yes');
0 ignored issues
show
Bug introduced by
The method setTestMode() does not exist on ByTIC\Payments\Gateways\...way\Traits\GatewayTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

138
        $this->/** @scrutinizer ignore-call */ 
139
               setTestMode($this->getSandbox() == 'yes');
Loading history...
139
        return $return;
140
    }
141
142
    /**
143
     * @return mixed
144
     */
145
    public function getSandbox()
146
    {
147
        return $this->getParameter('sandbox');
0 ignored issues
show
Bug introduced by
The method getParameter() does not exist on ByTIC\Payments\Gateways\...way\Traits\GatewayTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

147
        return $this->/** @scrutinizer ignore-call */ getParameter('sandbox');
Loading history...
148
    }
149
150
    /**
151
     * @return Manager
152
     */
153
    public function getManager()
154
    {
155
        return $this->manager;
156
    }
157
158
    /**
159
     * @param Manager $manager
160
     */
161
    public function setManager($manager)
162
    {
163
        $this->manager = $manager;
164
    }
165
166
    /**
167
     * @return PaymentMethodRecord|Record|HasFilesRecord
168
     */
169 1
    public function getPaymentMethod()
170
    {
171 1
        return $this->paymentMethod;
172
    }
173
174
    /**
175
     * @param PaymentMethodRecord $paymentMethod
176
     */
177 25
    public function setPaymentMethod($paymentMethod)
178
    {
179 25
        $this->paymentMethod = $paymentMethod;
180 25
    }
181
182
    /**
183
     * @param HttpRequest $httpRequest
184
     */
185 15
    public function setHttpRequest($httpRequest)
186
    {
187 15
        $this->httpRequest = $httpRequest;
0 ignored issues
show
Bug Best Practice introduced by
The property httpRequest does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
188 15
    }
189
190
    /**
191
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
192
     * @return string|null
193
     */
194
    public function getImageBand($default = null)
195
    {
196
        return GatewayImages::band($this->getName(), $default);
197
    }
198
199
    /**
200
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
201
     * @return string|null
202
     */
203
    public function getLogo($default = null)
204
    {
205
        return GatewayImages::logo($this->getName(), $default);
206
    }
207
208
    /**
209
     * @return boolean
210
     */
211
    abstract public function isActive();
212
}
213