Completed
Push — master ( 664fb1...60ffba )
by
unknown
26:32
created

SoapTransport   F

Complexity

Total Complexity 75

Size/Duplication

Total Lines 615
Duplicated Lines 4.23 %

Coupling/Cohesion

Components 1
Dependencies 20

Importance

Changes 0
Metric Value
wmc 75
lcom 1
cbo 20
dl 26
loc 615
rs 2.0921
c 0
b 0
f 0

36 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B init() 0 49 6
A checkExtensionFunctions() 0 16 2
A getSoapClient() 0 22 3
B call() 0 29 4
A makeNewAttempt() 0 13 2
A isExtensionInstalled() 0 8 2
A getMagentoVersion() 0 8 2
A getExtensionVersion() 0 8 2
A isSupportedExtensionVersion() 0 5 2
C pingMagento() 0 26 7
A getAdminUrl() 0 8 2
A getServerTime() 0 4 1
A getOrders() 0 10 2
A getOrderInfo() 0 10 2
A getCarts() 0 8 2
A getCustomers() 0 10 2
A getCustomerGroups() 0 4 1
A getStores() 0 4 1
A getWebsites() 0 4 1
A getRegions() 0 4 1
A getCustomerAddresses() 0 13 2
A createCustomer() 0 10 2
A updateCustomer() 0 10 2
A createCustomerAddress() 0 7 1
A updateCustomerAddress() 0 7 1
A getCustomerAddressInfo() 0 10 2
A getCustomerInfo() 0 10 2
A getNewsletterSubscribers() 0 8 2
A createNewsletterSubscriber() 13 13 2
A updateNewsletterSubscriber() 13 13 2
A getErrorCode() 0 9 3
A getLabel() 0 4 1
A getSettingsFormType() 0 4 1
A getSettingsEntityFQCN() 0 4 1
A lookUpForServerTime() 0 12 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like SoapTransport often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SoapTransport, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Oro\Bundle\MagentoBundle\Provider\Transport;
4
5
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
6
7
use Oro\Bundle\IntegrationBundle\Entity\Transport;
8
use Oro\Bundle\IntegrationBundle\Provider\SOAPTransport as BaseSOAPTransport;
9
use Oro\Bundle\IntegrationBundle\Utils\ConverterUtils;
10
use Oro\Bundle\SecurityBundle\Encoder\Mcrypt;
11
use Oro\Bundle\MagentoBundle\Entity\MagentoSoapTransport;
12
use Oro\Bundle\MagentoBundle\Exception\ExtensionRequiredException;
13
use Oro\Bundle\MagentoBundle\Provider\Iterator\CartsBridgeIterator;
14
use Oro\Bundle\MagentoBundle\Provider\Iterator\CustomerBridgeIterator;
15
use Oro\Bundle\MagentoBundle\Provider\Iterator\CustomerGroupSoapIterator;
16
use Oro\Bundle\MagentoBundle\Provider\Iterator\CustomerSoapIterator;
17
use Oro\Bundle\MagentoBundle\Provider\Iterator\NewsletterSubscriberBridgeIterator;
18
use Oro\Bundle\MagentoBundle\Provider\Iterator\OrderBridgeIterator;
19
use Oro\Bundle\MagentoBundle\Provider\Iterator\OrderSoapIterator;
20
use Oro\Bundle\MagentoBundle\Provider\Iterator\RegionSoapIterator;
21
use Oro\Bundle\MagentoBundle\Provider\Iterator\StoresSoapIterator;
22
use Oro\Bundle\MagentoBundle\Provider\Iterator\WebsiteSoapIterator;
23
use Oro\Bundle\MagentoBundle\Service\WsdlManager;
24
use Oro\Bundle\MagentoBundle\Utils\WSIUtils;
25
26
/**
27
 * Magento SOAP transport
28
 * used to fetch and pull data to/from Magento instance
29
 * with sessionId param using SOAP requests
30
 *
31
 * @package Oro\Bundle\MagentoBundle
32
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
33
 */
34
class SoapTransport extends BaseSOAPTransport implements MagentoTransportInterface, ServerTimeAwareInterface
35
{
36
    const REQUIRED_EXTENSION_VERSION = '1.2.0';
37
38
    const ACTION_CUSTOMER_LIST = 'customerCustomerList';
39
    const ACTION_CUSTOMER_INFO = 'customerCustomerInfo';
40
    const ACTION_CUSTOMER_UPDATE = 'customerCustomerUpdate';
41
    const ACTION_CUSTOMER_DELETE = 'customerCustomerDelete';
42
    const ACTION_CUSTOMER_CREATE = 'customerCustomerCreate';
43
    const ACTION_CUSTOMER_ADDRESS_LIST = 'customerAddressList';
44
    const ACTION_CUSTOMER_ADDRESS_INFO = 'customerAddressInfo';
45
    const ACTION_CUSTOMER_ADDRESS_UPDATE = 'customerAddressUpdate';
46
    const ACTION_CUSTOMER_ADDRESS_DELETE = 'customerAddressDelete';
47
    const ACTION_CUSTOMER_ADDRESS_CREATE = 'customerAddressCreate';
48
    const ACTION_ADDRESS_LIST = 'customerAddressList';
49
    const ACTION_GROUP_LIST = 'customerGroupList';
50
    const ACTION_STORE_LIST = 'storeList';
51
    const ACTION_ORDER_LIST = 'salesOrderList';
52
    const ACTION_ORDER_INFO = 'salesOrderInfo';
53
    const ACTION_CART_INFO = 'shoppingCartInfo';
54
    const ACTION_COUNTRY_LIST = 'directoryCountryList';
55
    const ACTION_REGION_LIST = 'directoryRegionList';
56
    const ACTION_PING = 'oroPing';
57
58
    const ACTION_ORO_CART_LIST = 'oroQuoteList';
59
    const ACTION_ORO_ORDER_LIST = 'oroOrderList';
60
    const ACTION_ORO_ORDER_INFO = 'oroOrderInfo';
61
    const ACTION_ORO_CUSTOMER_LIST = 'oroCustomerList';
62
    const ACTION_ORO_CUSTOMER_INFO = 'oroCustomerInfo';
63
    const ACTION_ORO_CUSTOMER_ADDRESS_LIST = 'oroCustomerAddressList';
64
    const ACTION_ORO_CUSTOMER_ADDRESS_INFO = 'oroCustomerAddressInfo';
65
    const ACTION_ORO_CUSTOMER_CREATE = 'oroCustomerCreate';
66
    const ACTION_ORO_CUSTOMER_UPDATE = 'oroCustomerUpdate';
67
    const ACTION_ORO_NEWSLETTER_SUBSCRIBER_LIST = 'newsletterSubscriberList';
68
    const ACTION_ORO_NEWSLETTER_SUBSCRIBER_CREATE = 'newsletterSubscriberCreate';
69
    const ACTION_ORO_NEWSLETTER_SUBSCRIBER_UPDATE = 'newsletterSubscriberUpdate';
70
    const ACTION_ORO_WEBSITE_LIST = 'oroWebsiteList';
71
72
    const SOAP_FAULT_ADDRESS_DOES_NOT_EXIST = 102;
73
74
    /** @var string */
75
    protected $sessionId;
76
77
    /** @var Mcrypt */
78
    protected $encoder;
79
80
    /** @var bool */
81
    protected $isExtensionInstalled;
82
83
    /** @var string */
84
    protected $magentoVersion;
85
86
    /** @var string */
87
    protected $extensionVersion;
88
89
    /** @var bool */
90
    protected $isWsiMode = false;
91
92
    /** @var string */
93
    protected $adminUrl;
94
95
    /** @var  string */
96
    protected $serverTime;
97
98
    /** @var array */
99
    protected $dependencies = [];
100
101
    /** @var WsdlManager */
102
    protected $wsdlManager;
103
104
    /** @var array */
105
    protected $auth = [];
106
107
    /**
108
     * @var array
109
     */
110
    protected $bundleConfig;
111
112
    /**
113
     * @param Mcrypt $encoder
114
     * @param WsdlManager $wsdlManager
115
     * @param array $bundleConfig
116
     */
117
    public function __construct(Mcrypt $encoder, WsdlManager $wsdlManager, array $bundleConfig = [])
118
    {
119
        $this->encoder = $encoder;
120
        $this->wsdlManager = $wsdlManager;
121
        $this->bundleConfig = $bundleConfig;
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    public function init(Transport $transportEntity)
128
    {
129
        /**
130
         * Cache WSDL and force transport entity to use it instead of original URL.
131
         * This should be done before parent::init as settings will be cached there.
132
         */
133
        if ($transportEntity instanceof MagentoSoapTransport) {
134
            $wsdlUrl = $transportEntity->getWsdlUrl();
135
136
            // Save auth information to be able to perform requests.
137
            $urlParts = parse_url($wsdlUrl);
138
            if (isset($urlParts['user'], $urlParts['pass'])) {
139
                $this->auth['login'] = $urlParts['user'];
140
                $this->auth['password'] = $urlParts['pass'];
141
            }
142
143
            // Load WSDL to local cache.
144
            if (!$this->wsdlManager->isCacheLoaded($wsdlUrl)) {
145
                $this->wsdlManager->loadWsdl($wsdlUrl);
146
            }
147
148
            // Set cached WSDL path to transport entity.
149
            $transportEntity->setWsdlCachePath($this->wsdlManager->getCachedWsdlPath($wsdlUrl));
150
        }
151
152
        parent::init($transportEntity);
153
154
        $wsiMode = $this->settings->get('wsi_mode', false);
155
        $apiUser = $this->settings->get('api_user', false);
156
        $apiKey = $this->settings->get('api_key', false);
157
        $apiKey = $this->encoder->decryptData($apiKey);
158
159
        if (!$apiUser || !$apiKey) {
160
            throw new InvalidConfigurationException(
161
                "Magento SOAP transport require 'api_key' and 'api_user' settings to be defined."
162
            );
163
        }
164
165
        // revert initial state
166
        $this->isExtensionInstalled = null;
167
        $this->adminUrl = null;
168
        $this->isWsiMode = $wsiMode;
169
170
        /** @var string sessionId returned by Magento API login method */
171
        $this->sessionId = null;
172
        $this->sessionId = $this->call('login', ['username' => $apiUser, 'apiKey' => $apiKey]);
173
174
        $this->checkExtensionFunctions();
175
    }
176
177
    protected function checkExtensionFunctions()
178
    {
179
        $functions = (array)$this->client->__getFunctions();
180
181
        $isExtensionInstalled = (bool)array_filter(
182
            $functions,
183
            function ($definition) {
184
                return false !== strpos($definition, self::ACTION_PING);
185
            }
186
        );
187
188
        if (!$isExtensionInstalled) {
189
            $this->isExtensionInstalled = false;
190
            $this->adminUrl = false;
0 ignored issues
show
Documentation Bug introduced by
The property $adminUrl was declared of type string, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
191
        }
192
    }
193
194
    /**
195
     * Disable wsdl caching by PHP.
196
     *
197
     * {@inheritdoc}
198
     */
199
    protected function getSoapClient($wsdlUrl, array $options = [])
200
    {
201
        $options['cache_wsdl'] = WSDL_CACHE_NONE;
202
        if (!isset($options['login'], $options['password'])) {
203
            $options = array_merge($options, $this->auth);
204
        }
205
        if (!empty($this->bundleConfig['sync_settings']['skip_ssl_verification'])) {
206
            $context = stream_context_create(
207
                [
208
                    'ssl' => [
209
                        'verify_peer' => false,
210
                        'verify_peer_name' => false,
211
                        'allow_self_signed' => true
212
                    ]
213
                ]
214
            );
215
216
            $options['stream_context'] = $context;
217
        }
218
219
        return parent::getSoapClient($wsdlUrl, $options);
220
    }
221
222
    /**
223
     * {@inheritdoc}
224
     */
225
    public function call($action, $params = [])
226
    {
227
        if (null !== $this->sessionId) {
228
            $params = array_merge(['sessionId' => $this->sessionId], (array)$params);
229
        }
230
231
        if ($this->logger) {
232
            $this->logger->debug(
233
                sprintf(
234
                    '[%.1fMB/%.1fMB] Call %s action with %s parameters',
235
                    memory_get_usage() / 1024 / 1024,
236
                    memory_get_peak_usage() / 1024 / 1024,
237
                    $action,
238
                    json_encode($params)
239
                )
240
            );
241
        }
242
243
        if ($this->isWsiMode) {
244
            $result = parent::call($action, [(object)$params]);
245
            $result = WSIUtils::parseWSIResponse($result);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as \Oro\Bundle\MagentoBundl...rseWSIResponse($result) (which targets Oro\Bundle\MagentoBundle...ils::parseWSIResponse()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
246
        } else {
247
            $result = parent::call($action, $params);
248
        }
249
250
        $this->lookUpForServerTime();
251
252
        return $result;
253
    }
254
255
    /**
256
     * {@inheritdoc}
257
     */
258
    protected function makeNewAttempt($action, $params)
259
    {
260
        $this->logAttempt();
261
        sleep($this->getSleepBetweenAttempt());
262
        ++$this->attempted;
263
264
        // in case if we have WsiMode enabled we should convert object parameters to array to avoid
265
        // not correct parameters during the next attempt call
266
        return $this->call(
267
            $action,
268
            $this->isWsiMode ? (array)array_shift($params) : $params
269
        );
270
    }
271
272
    /**
273
     * {@inheritdoc}
274
     */
275
    public function isExtensionInstalled()
276
    {
277
        if (null === $this->isExtensionInstalled) {
278
            $this->pingMagento();
279
        }
280
281
        return $this->isExtensionInstalled;
282
    }
283
284
    /**
285
     * {@inheritdoc}
286
     */
287
    public function getMagentoVersion()
288
    {
289
        if (null === $this->isExtensionInstalled) {
290
            $this->pingMagento();
291
        }
292
293
        return $this->magentoVersion;
294
    }
295
296
    /**
297
     * {@inheritdoc}
298
     */
299
    public function getExtensionVersion()
300
    {
301
        if (null === $this->isExtensionInstalled) {
302
            $this->pingMagento();
303
        }
304
305
        return $this->extensionVersion;
306
    }
307
308
    /**
309
     * {@inheritdoc}
310
     */
311
    public function isSupportedExtensionVersion()
312
    {
313
        return $this->isExtensionInstalled()
314
            && version_compare($this->getExtensionVersion(), self::REQUIRED_EXTENSION_VERSION, 'ge');
315
    }
316
317
    /**
318
     * Pings magento and fill data related to Bridge Extension.
319
     *
320
     * @return $this
321
     */
322
    protected function pingMagento()
323
    {
324
        if (null === $this->isExtensionInstalled && null === $this->adminUrl) {
325
            try {
326
                $result = $this->call(self::ACTION_PING);
327
                $this->isExtensionInstalled = !empty($result->version);
328
                if ($this->isExtensionInstalled) {
329
                    $this->extensionVersion = $result->version;
330
                }
331
                if (!empty($result->mage_version)) {
332
                    $this->magentoVersion = $result->mage_version;
333
                }
334
                if (!empty($result->admin_url)) {
335
                    $this->adminUrl = $result->admin_url;
336
                } else {
337
                    $this->adminUrl = false;
0 ignored issues
show
Documentation Bug introduced by
The property $adminUrl was declared of type string, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
338
                }
339
            } catch (\Exception $e) {
340
                $this->isExtensionInstalled
341
                    = $this->adminUrl
342
                    = false;
343
            }
344
        }
345
346
        return $this;
347
    }
348
349
    /**
350
     * {@inheritdoc}
351
     */
352
    public function getAdminUrl()
353
    {
354
        if (null === $this->adminUrl) {
355
            $this->pingMagento();
356
        }
357
358
        return $this->adminUrl;
359
    }
360
361
    /**
362
     * {@inheritdoc}
363
     */
364
    public function getServerTime()
365
    {
366
        return $this->serverTime;
367
    }
368
369
    /**
370
     * {@inheritdoc}
371
     */
372
    public function getOrders()
373
    {
374
        $settings = $this->settings->all();
375
376
        if ($this->isExtensionInstalled()) {
377
            return new OrderBridgeIterator($this, $settings);
378
        } else {
379
            return new OrderSoapIterator($this, $settings);
380
        }
381
    }
382
383
    /**
384
     * {@inheritdoc}
385
     */
386
    public function getOrderInfo($incrementId)
387
    {
388
        if ($this->isSupportedExtensionVersion()) {
389
            $endpoint = self::ACTION_ORO_ORDER_INFO;
390
        } else {
391
            $endpoint = self::ACTION_ORDER_INFO;
392
        }
393
394
        return $this->call($endpoint, ['orderIncrementId' => $incrementId]);
395
    }
396
397
    /**
398
     * {@inheritdoc}
399
     */
400
    public function getCarts()
401
    {
402
        if ($this->isExtensionInstalled()) {
403
            return new CartsBridgeIterator($this, $this->settings->all());
404
        }
405
406
        throw new ExtensionRequiredException();
407
    }
408
409
    /**
410
     * {@inheritdoc}
411
     */
412
    public function getCustomers()
413
    {
414
        $settings = $this->settings->all();
415
416
        if ($this->isExtensionInstalled()) {
417
            return new CustomerBridgeIterator($this, $settings);
418
        } else {
419
            return new CustomerSoapIterator($this, $settings);
420
        }
421
    }
422
423
    /**
424
     * {@inheritdoc}
425
     */
426
    public function getCustomerGroups()
427
    {
428
        return new CustomerGroupSoapIterator($this);
429
    }
430
431
    /**
432
     * {@inheritdoc}
433
     */
434
    public function getStores()
435
    {
436
        return new StoresSoapIterator($this);
437
    }
438
439
    /**
440
     * {@inheritdoc}
441
     */
442
    public function getWebsites()
443
    {
444
        return new WebsiteSoapIterator($this);
445
    }
446
447
    /**
448
     * {@inheritdoc}
449
     */
450
    public function getRegions()
451
    {
452
        return new RegionSoapIterator($this, $this->settings->all());
453
    }
454
455
    /**
456
     * {@inheritdoc}
457
     */
458
    public function getCustomerAddresses($originId)
459
    {
460
        if ($this->isSupportedExtensionVersion()) {
461
            $endpoint = SoapTransport::ACTION_ORO_CUSTOMER_ADDRESS_LIST;
462
        } else {
463
            $endpoint = SoapTransport::ACTION_CUSTOMER_ADDRESS_LIST;
464
        }
465
466
        $addresses = $this->call($endpoint, ['customerId' => $originId]);
467
        $addresses = WSIUtils::processCollectionResponse($addresses);
468
469
        return ConverterUtils::objectToArray($addresses);
0 ignored issues
show
Documentation introduced by
$addresses is of type array, but the function expects a object<stdClass>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
470
    }
471
472
    /**
473
     * {@inheritdoc}
474
     */
475
    public function createCustomer(array $customerData)
476
    {
477
        if ($this->isSupportedExtensionVersion()) {
478
            $createEndpoint = SoapTransport::ACTION_ORO_CUSTOMER_CREATE;
479
        } else {
480
            $createEndpoint = SoapTransport::ACTION_CUSTOMER_CREATE;
481
        }
482
483
        return $this->call($createEndpoint, ['customerData' => $customerData]);
484
    }
485
486
    /**
487
     * {@inheritdoc}
488
     */
489
    public function updateCustomer($customerId, array $customerData)
490
    {
491
        if ($this->isSupportedExtensionVersion()) {
492
            $updateEndpoint = SoapTransport::ACTION_ORO_CUSTOMER_UPDATE;
493
        } else {
494
            $updateEndpoint = SoapTransport::ACTION_CUSTOMER_UPDATE;
495
        }
496
497
        return $this->call($updateEndpoint, ['customerId' => $customerId, 'customerData' => $customerData]);
498
    }
499
500
    /**
501
     * {@inheritdoc}
502
     */
503
    public function createCustomerAddress($customerId, array $item)
504
    {
505
        return $this->call(
506
            SoapTransport::ACTION_CUSTOMER_ADDRESS_CREATE,
507
            ['customerId' => $customerId, 'addressData' => $item]
508
        );
509
    }
510
511
    /**
512
     * {@inheritdoc}
513
     */
514
    public function updateCustomerAddress($customerAddressId, array $item)
515
    {
516
        return $this->call(
517
            SoapTransport::ACTION_CUSTOMER_ADDRESS_UPDATE,
518
            ['addressId' => $customerAddressId, 'addressData' => $item]
519
        );
520
    }
521
522
    /**
523
     * {@inheritdoc}
524
     */
525
    public function getCustomerAddressInfo($customerAddressId)
526
    {
527
        if ($this->isSupportedExtensionVersion()) {
528
            $endpoint = SoapTransport::ACTION_ORO_CUSTOMER_ADDRESS_INFO;
529
        } else {
530
            $endpoint = SoapTransport::ACTION_CUSTOMER_ADDRESS_INFO;
531
        }
532
533
        return ConverterUtils::objectToArray($this->call($endpoint, ['addressId' => $customerAddressId]));
534
    }
535
536
    /**
537
     * {@inheritdoc}
538
     */
539
    public function getCustomerInfo($originId)
540
    {
541
        if ($this->isSupportedExtensionVersion()) {
542
            $endpoint = SoapTransport::ACTION_ORO_CUSTOMER_INFO;
543
        } else {
544
            $endpoint = SoapTransport::ACTION_CUSTOMER_INFO;
545
        }
546
547
        return ConverterUtils::objectToArray($this->call($endpoint, ['customerId' => $originId]));
548
    }
549
550
    /**
551
     * {@inheritdoc}
552
     */
553
    public function getNewsletterSubscribers()
554
    {
555
        if ($this->isSupportedExtensionVersion()) {
556
            return new NewsletterSubscriberBridgeIterator($this, $this->settings->all());
557
        }
558
559
        throw new ExtensionRequiredException();
560
    }
561
562
    /**
563
     * {@inheritdoc}
564
     */
565 View Code Duplication
    public function createNewsletterSubscriber(array $subscriberData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
566
    {
567
        if ($this->isExtensionInstalled()) {
568
            $result = $this->call(
569
                SoapTransport::ACTION_ORO_NEWSLETTER_SUBSCRIBER_CREATE,
570
                ['subscriberData' => $subscriberData]
571
            );
572
573
            return ConverterUtils::objectToArray($result);
574
        }
575
576
        throw new ExtensionRequiredException();
577
    }
578
579
    /**
580
     * {@inheritdoc}
581
     */
582 View Code Duplication
    public function updateNewsletterSubscriber($subscriberId, array $subscriberData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
583
    {
584
        if ($this->isExtensionInstalled()) {
585
            $result = $this->call(
586
                SoapTransport::ACTION_ORO_NEWSLETTER_SUBSCRIBER_UPDATE,
587
                ['subscriberId' => $subscriberId, 'subscriberData' => $subscriberData]
588
            );
589
590
            return ConverterUtils::objectToArray($result);
591
        }
592
593
        throw new ExtensionRequiredException();
594
    }
595
596
    /**
597
     * {@inheritdoc}
598
     */
599
    public function getErrorCode(\Exception $e)
600
    {
601
        if ($e instanceof \SoapFault) {
602
            switch ($e->faultcode) {
0 ignored issues
show
Bug introduced by
The property faultcode does not seem to exist in SoapFault.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
603
                case self::SOAP_FAULT_ADDRESS_DOES_NOT_EXIST:
604
                    return self::TRANSPORT_ERROR_ADDRESS_DOES_NOT_EXIST;
605
            }
606
        }
607
    }
608
609
    /**
610
     * {@inheritdoc}
611
     */
612
    public function getLabel()
613
    {
614
        return 'oro.magento.transport.soap.label';
615
    }
616
617
    /**
618
     * {@inheritdoc}
619
     */
620
    public function getSettingsFormType()
621
    {
622
        return 'oro_magento_soap_transport_setting_form_type';
623
    }
624
625
    /**
626
     * {@inheritdoc}
627
     */
628
    public function getSettingsEntityFQCN()
629
    {
630
        return 'Oro\\Bundle\\MagentoBundle\\Entity\\MagentoSoapTransport';
631
    }
632
633
    /**
634
     * Tries to fetch date from response headers
635
     */
636
    protected function lookUpForServerTime()
637
    {
638
        if (null === $this->serverTime) {
639
            $parsedResponse = $this->getLastResponseHeaders();
640
641
            if (isset($parsedResponse['headers']['Date'])) {
642
                $this->serverTime = $parsedResponse['headers']['Date'];
643
            } else {
644
                $this->serverTime = false;
0 ignored issues
show
Documentation Bug introduced by
The property $serverTime was declared of type string, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
645
            }
646
        }
647
    }
648
}
649