GatewayTrait::setName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits;
4
5
use ByTIC\Payments\Gateways\Manager;
6
use ByTIC\Payments\Models\Methods\Traits\RecordTrait as PaymentMethodRecord;
7
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
8
use ByTIC\Payments\Utility\GatewayImages;
9
use Nip\Records\AbstractModels\Record;
10
use Nip\Utility\Traits\NameWorksTrait;
11
use Omnipay\Common\Message\RequestInterface;
12
use Symfony\Component\HttpFoundation\Request as HttpRequest;
13
14
/**
15
 * Class Gateway
16
 * @package ByTIC\Payments\Gateways\Providers\AbstractGateway
17
 *
18
 * @property $parameters \Symfony\Component\HttpFoundation\ParameterBag
19
 */
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...
20
trait GatewayTrait
21
{
22
    use NameWorksTrait;
23
    use MagicMessagesTrait;
24
    use HasFormsTrait;
25
    use DetectFromHttpRequestTrait;
26
    use OverwriteCompletePurchaseTrait;
27
28
29
    /**
30
     * @var null|string
31
     */
32
    protected $name = null;
33
34
    /**
35
     * @var null|string
36
     */
37
    protected $label = null;
38
39
    /**
40
     * @var Manager
41
     */
42
    protected $manager;
43
44
    /**
45
     * @var PaymentMethodRecord
46
     */
47
    protected $paymentMethod;
48
49
50
51
    /**
52
     * @param IsPurchasableModelTrait $record
53
     * @return RequestInterface
54
     */
55
    public function purchaseFromModel($record)
56 6
    {
57
        $parameters = $record->getPurchaseParameters();
58 6
59
        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

59
        return $this->/** @scrutinizer ignore-call */ purchase($parameters);
Loading history...
60 6
    }
61
62
    /**
63
     * @return null|string
64
     */
65
    public function getName()
66 1
    {
67
        if ($this->name === null) {
68 1
            $this->initName();
69 1
        }
70
71
        return $this->name;
72 1
    }
73
74
    // ------------ GETTERS & SETTERS ------------ //
75
76
    /**
77
     * @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...
78
     */
79
    public function setName($name)
80 1
    {
81
        $this->name = $name;
82 1
    }
83 1
84
    public function initName()
85 1
    {
86
        $this->setName($this->generateName());
87 1
    }
88 1
89
    /**
90
     * @return string
91
     */
92
    protected function generateName()
93 1
    {
94
        return strtolower($this->getLabel());
95 1
    }
96
97
    /**
98
     * @return null|string
99
     */
100
    public function getLabel()
101 1
    {
102
        if ($this->label === null) {
103 1
            $this->initLabel();
104 1
        }
105
106
        return $this->label;
107 1
    }
108
109
    /**
110
     * @param null|string $label
111
     */
112
    public function setLabel($label)
113 1
    {
114
        $this->label = $label;
115 1
    }
116 1
117
    public function initLabel()
118 1
    {
119
        $this->setLabel($this->generateLabel());
120 1
    }
121 1
122
    /**
123
     * @return string
124
     */
125
    public function generateLabel()
126 1
    {
127
        return $this->getNamespaceParentFolder();
128 1
    }
129
130
    /**
131
     * @param $value
132
     * @return mixed
133
     */
134
    public function setSandbox($value)
135
    {
136
        $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

136
        /** @scrutinizer ignore-call */ 
137
        $return = $this->setParameter('sandbox', $value);
Loading history...
137
        $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

137
        $this->/** @scrutinizer ignore-call */ 
138
               setTestMode($this->getSandbox() == 'yes');
Loading history...
138
        return $return;
139
    }
140
141
    /**
142
     * @return mixed
143
     */
144
    public function getSandbox()
145
    {
146
        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

146
        return $this->/** @scrutinizer ignore-call */ getParameter('sandbox');
Loading history...
147
    }
148
149
    /**
150
     * @return Manager
151
     */
152
    public function getManager()
153
    {
154
        return $this->manager;
155
    }
156
157
    /**
158
     * @param Manager $manager
159
     */
160
    public function setManager($manager)
161
    {
162
        $this->manager = $manager;
163
    }
164
165
    /**
166
     * @return PaymentMethodRecord|Record
167
     */
168
    public function getPaymentMethod()
169 1
    {
170
        return $this->paymentMethod;
171 1
    }
172
173
    /**
174
     * @param PaymentMethodRecord $paymentMethod
175
     */
176
    public function setPaymentMethod($paymentMethod)
177 18
    {
178
        $this->paymentMethod = $paymentMethod;
179 18
    }
180 18
181
    /**
182
     * @param HttpRequest $httpRequest
183
     */
184
    public function setHttpRequest($httpRequest)
185 13
    {
186
        $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...
187 13
    }
188 13
189
    /**
190
     * @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...
191
     * @return string|null
192
     */
193
    public function getImageBand($default = null)
194
    {
195
        return GatewayImages::band($this->getName(), $default);
196
    }
197
198
    /**
199
     * @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...
200
     * @return string|null
201
     */
202
    public function getLogo($default = null)
203
    {
204
        return GatewayImages::logo($this->getName(), $default);
205
    }
206
207
    /**
208
     * @return boolean
209
     */
210
    abstract public function isActive();
211
}
212