Passed
Push — master ( aa1475...13b16c )
by Pablo
11:39
created

AbstractRequest::getMessageCatalog()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 0
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Omnipay\Redsys\Message;
4
5
use AvaiBookSports\Component\RedsysMessages\Exception\CatalogNotFoundException;
6
use AvaiBookSports\Component\RedsysMessages\Factory;
7
use AvaiBookSports\Component\RedsysMessages\Loader\CatalogLoader;
8
use Omnipay\Common\Exception\RuntimeException;
9
use Omnipay\Common\Message\AbstractRequest as MessageAbstractRequest;
10
11
abstract class AbstractRequest extends MessageAbstractRequest
12
{
13
    /** @var array */
14
    protected static $consumerLanguages = [
15
        'es' => '001', // Spanish
16
        'en' => '002', // English
17
        'ca' => '003', // Catalan - same as Valencian (010)
18
        'fr' => '004', // French
19
        'de' => '005', // German
20
        'nl' => '006', // Dutch
21
        'it' => '007', // Italian
22
        'sv' => '008', // Swedish
23
        'pt' => '009', // Portuguese
24
        'pl' => '011', // Polish
25
        'gl' => '012', // Galician
26
        'eu' => '013', // Basque
27
        'bg' => '100', // Undocumented
28
        'zh' => '156', // Undocumented
29
        'hr' => '191', // Undocumented
30
        'cs' => '203', // Undocumented
31
        'da' => '208', // Undocumented
32
        'et' => '233', // Undocumented
33
        'fi' => '246', // Undocumented
34
        'el' => '300', // Undocumented
35
        'hu' => '348', // Undocumented
36
        'ja' => '392', // Undocumented
37
        'lv' => '428', // Undocumented
38
        'lt' => '440', // Undocumented
39
        'mt' => '470', // Undocumented
40
        'ro' => '642', // Undocumented
41
        'ru' => '643', // Undocumented
42
        'sk' => '703', // Undocumented
43
        'sl' => '705', // Undocumented
44
        'tr' => '792', // Undocumented
45
    ];
46 2
47
    abstract public function getEndpoint();
48 2
49
    public function getCardholder()
50
    {
51 4
        return $this->getParameter('cardholder');
52
    }
53 4
54
    public function setCardholder($value)
55
    {
56
        return $this->setParameter('cardholder', $value);
57
    }
58
59
    /**
60
     * Get the language presented to the consumer.
61 8
     *
62
     * @return string|null ISO 639-1 code
63 8
     */
64
    public function getLanguage()
65
    {
66
        return $this->getParameter('language');
67
    }
68
69
    /**
70
     * Set the language presented to the consumer.
71 7
     *
72
     * @param string ISO 639-1 code
0 ignored issues
show
Bug introduced by
The type Omnipay\Redsys\Message\ISO was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73 7
     */
74
    public function setLanguage($value)
75 7
    {
76
        return $this->setParameter('language', $value);
77
    }
78
79
    /**
80
     * Returns Redsys language code or English by default.
81
     *
82
     * @return string
83 8
     */
84
    public function getConsumerLanguage()
85 8
    {
86
        $language = $this->getLanguage() ?: 'en';
87 8
88
        if (!array_key_exists($language, self::$consumerLanguages)) {
89
            $language = 'en';
90
            // throw new OmnipayException(sprintf('Language "%s" is not supported by the gateway', $language));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91
        }
92 8
93
        return self::$consumerLanguages[$language];
94
    }
95 19
96
    public function getHmacKey()
97 19
    {
98
        return $this->getParameter('hmacKey');
99
    }
100 30
101
    public function setHmacKey($value)
102 30
    {
103
        return $this->setParameter('hmacKey', $value);
104
    }
105 7
106
    public function getMerchantData()
107 7
    {
108
        return $this->getParameter('merchantData');
109
    }
110 7
111
    public function setMerchantData($value)
112 7
    {
113
        return $this->setParameter('merchantData', $value);
114
    }
115 14
116
    public function getMerchantId()
117 14
    {
118
        return $this->getParameter('merchantId');
119
    }
120 30
121
    public function setMerchantId($value)
122 30
    {
123
        return $this->setParameter('merchantId', $value);
124
    }
125 13
126
    public function getMerchantName()
127 13
    {
128
        return $this->getParameter('merchantName');
129
    }
130 27
131
    public function setMerchantName($value)
132 27
    {
133
        return $this->setParameter('merchantName', $value);
134
    }
135 14
136
    public function getTerminalId()
137 14
    {
138
        return $this->getParameter('terminalId');
139
    }
140 30
141
    public function setTerminalId($value)
142 30
    {
143
        return $this->setParameter('terminalId', $value);
144
    }
145
146
    /**
147
     * Override the abstract method to add requirement that it must start with 4 numeric characters.
148
     *
149
     * @param string|int $value The transaction ID (merchant order) to set for the transaction
150 18
     */
151
    public function setTransactionId($value)
152 18
    {
153
        if (strlen($value) > 12) {
154
            throw new RuntimeException('"transactionId" has a maximum length of 12 characters');
155
        }
156 18
157 18
        parent::setTransactionId($value);
158
    }
159
160
    public function getMessageCatalog()
161
    {
162
        try {
163
            return (new Factory(new CatalogLoader()))->createCatalogByLanguage($this->getLanguage() ?: 'en');
164
        } catch (CatalogNotFoundException $e) {
165
            return (new Factory(new CatalogLoader()))->createCatalogByLanguage('en');
166
        }
167
    }
168
}
169