GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SoapSettings   C
last analyzed

Complexity

Total Complexity 56

Size/Duplication

Total Lines 692
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 56
lcom 1
cbo 1
dl 0
loc 692
ccs 137
cts 137
cp 1
rs 5.1807
c 0
b 0
f 0

48 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthentication() 0 4 1
A setAuthentication() 0 6 1
A getCacheWsdl() 0 4 1
A setCacheWsdl() 0 6 1
A getClassMap() 0 4 1
A setClassMap() 0 6 1
A getCompression() 0 4 1
A getConnectionTimeout() 0 4 1
A setConnectionTimeout() 0 9 2
A getContext() 0 4 1
A setContext() 0 6 1
A getEncoding() 0 4 1
A setEncoding() 0 6 1
A hasExceptions() 0 4 1
A setExceptions() 0 6 1
A getFeatures() 0 4 1
A isKeepAlive() 0 4 1
A setKeepAlive() 0 6 1
A getLogin() 0 4 1
A getLocalCert() 0 4 1
A setLocalCert() 0 6 1
A getPassphrase() 0 4 1
A setLogin() 0 4 1
A setPassphrase() 0 6 1
A getPassword() 0 4 1
A setPassword() 0 6 1
A getProxyHost() 0 4 1
A setProxyHost() 0 6 1
A getProxyLogin() 0 4 1
A setProxyLogin() 0 6 1
A getProxyPassword() 0 4 1
A setProxyPassword() 0 6 1
A getProxyPort() 0 4 1
A setProxyPort() 0 6 1
A getSoapVersion() 0 4 1
A getSslMethod() 0 4 1
A getTypeMap() 0 4 1
A setTypeMap() 0 6 1
A getUri() 0 4 1
A setUri() 0 6 1
A getUserAgent() 0 4 1
A setUserAgent() 0 6 1
A toArray() 0 4 1
A loadFromArray() 0 13 3
A setCompression() 0 8 2
A setFeatures() 0 8 2
A setSoapVersion() 0 6 2
A setSslMethod() 0 8 3

How to fix   Complexity   

Complex Class

Complex classes like SoapSettings 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 SoapSettings, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace WebservicesNl\Protocol\Soap\Client;
4
5
use WebservicesNl\Common\Exception\Client\InputException;
6
7
/**
8
 * Class SoapSettings.
9
 *
10
 * Container for all the SoapClient settings. For HTTP authentication, the login and password options can be used to
11
 * supply credentials. For making an HTTP connection through a proxy server, the options are:
12
 *  - proxy_host
13
 *  - proxy_port
14
 *  - proxy_login
15
 *  - proxy_password
16
 *
17
 *  For HTTPS client certificate authentication use local_cert and passphrase options
18
 *
19
 * @link http://php.net/manual/en/soapclient.soapclient.php
20
 */
21
class SoapSettings
22
{
23
    const DEFAULT_CONNECTION_TIMEOUT = 5;
24
    const USER_AGENT = 'WebservicesNlSoapClient/PHP/2.0';
25
26
    /**
27
     * An authentication may be supplied in the authentication option.
28
     * The authentication method may be either SOAP_AUTHENTICATION_BASIC (default) or SOAP_AUTHENTICATION_DIGEST.
29
     *
30
     * @var int
31
     */
32
    private $authentication = SOAP_AUTHENTICATION_BASIC;
33
34
    /**
35
     * The cache_wsdl option is one of WSDL_CACHE_NONE, WSDL_CACHE_DISK, WSDL_CACHE_MEMORY or WSDL_CACHE_BOTH.
36
     *
37
     * @var int
38
     */
39
    private $cacheWsdl = WSDL_CACHE_NONE;
40
41
    /**
42
     * Optional Class map.
43
     *
44
     * @var array | null
45
     */
46
    private $classMap;
47
48
    /**
49
     * The compression option allows to use compression of HTTP SOAP requests and responses.
50
     *
51
     * @var int
52
     */
53
    private $compression = SOAP_COMPRESSION_ACCEPT;
54
55
    /**
56
     * The connection_timeout option defines a timeout in seconds for the connection to the SOAP service.
57
     *
58
     * This option does not define a timeout for services with slow responses. To limit the time to wait for calls to
59
     * finish the default_socket_timeout setting is available.
60
     *
61
     * @var int
62
     */
63
    private $connectionTimeout = self::DEFAULT_CONNECTION_TIMEOUT;
64
65
    /**
66
     * The stream_context option is a resource for context.
67
     *
68
     * @var resource
69
     */
70
    private $context;
71
72
    /**
73
     * The encoding option defines internal character encoding.
74
     * This option does not change the encoding of SOAP requests (it is always utf-8), but converts strings into it.
75
     *
76
     * @var
77
     */
78
    private $encoding = 'UTF-8';
79
80
    /**
81
     * The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault.
82
     *
83
     * @var bool
84
     */
85
    private $exceptions = true;
86
87
    /**
88
     * The features option is a bitmask of SOAP_SINGLE_ELEMENT_ARRAYS, SOAP_USE_XSI_ARRAY_TYPE, SOAP_WAIT_ONE_WAY_CALLS.
89
     *
90
     * @var int
91
     */
92
    private $features = SOAP_SINGLE_ELEMENT_ARRAYS;
93
94
    /**
95
     * Optional value defining whether to send the Connection: 'Keep-Alive' or Connection: 'close'.
96
     *
97
     * @var bool
98
     */
99
    private $keepAlive = true;
100
101
    /**
102
     * login username for HTTP Authentication. (optional).
103
     *
104
     * @var string
105
     */
106
    private $login;
107
108
    /**
109
     * path to cert_key.pem.
110
     *
111
     * @var string
112
     */
113
    private $localCert;
114
115
    /**
116
     * Passphrase for localCert pem.
117
     *
118
     * @var string
119
     */
120
    private $passphrase;
121
122
    /**
123
     * @var string
124
     */
125
    private $password;
126
127
    /**
128
     * @var string
129
     */
130
    private $proxyHost;
131
132
    /**
133
     * @var string
134
     */
135
    private $proxyLogin;
136
    /**
137
     * @var string
138
     */
139
    private $proxyPassword;
140
141
    /**
142
     * @var string
143
     */
144
    private $proxyPort;
145
146
    /**
147
     * All possible SOAP SSL methods.
148
     *
149
     * @var array
150
     */
151
    public static $sslMethods =
152
        [
153
            SOAP_SSL_METHOD_TLS,
154
            SOAP_SSL_METHOD_SSLv2,
155
            SOAP_SSL_METHOD_SSLv3,
156
            SOAP_SSL_METHOD_SSLv23,
157
        ];
158
159
    /**
160
     * The ssl_method option is one of SOAP_SSL_METHOD_TLS, SOAP_SSL_METHOD_SSLv2, SOAP_SSL_METHOD_SSLv3 or
161
     * SOAP_SSL_METHOD_SSLv23.
162
     *
163
     * (Only PHP 5.5+)
164
     *
165
     */
166
    private $sslMethod = SOAP_SSL_METHOD_TLS;
167
168
    /**
169
     * @var array|null
170
     *                 The typemap option is an array of type mappings.
171
     *                 Type mapping is an array with keys type_name, type_ns (namespace URI),
172
     *                 from_xml (callback accepting one string parameter) and to_xml
173
     *                 (callback accepting one object parameter).
174
     *
175
     * Example array("type_ns"   => "http://schemas.nothing.com",
176
     *               "type_name" => "book",
177
     *               "from_xml"  => "some_function_name" callback accepting one string parameter
178
     *               "to_xml"    => "some_function_name" callback accepting one string parameter")
179
     */
180
    private $typeMap;
181
182
    /**
183
     * Soap Version (either SOAP_1_1 or SOAP_1_2).
184
     *
185
     * @var int
186
     */
187
    private $soapVersion = SOAP_1_1;
188
189
    /**
190
     * Must be set in non-WSDL mode.
191
     *
192
     * @var string
193
     */
194
    private $uri;
195
196
    /**
197
     * The user_agent option specifies string to use in User-Agent header.
198
     *
199
     * @var string
200
     */
201
    private $userAgent = self::USER_AGENT;
202
203
    /**
204
     * Load config object from array.
205
     *
206
     * @param array $options
207
     *
208
     * @return SoapSettings
209
     */
210 7
    public static function loadFromArray(array $options)
211
    {
212 7
        $options = array_filter($options);
213 7
        $config = new static();
214 7
        foreach ($options as $key => $value) {
215 6
            $name = 'set' . ucfirst(strtolower($key));
216 6
            if (method_exists($config, $name)) {
217 6
                $config->{$name}($value);
218 6
            }
219 7
        }
220
221 7
        return $config;
222
    }
223
224
    /**
225
     * Return the Authentication flag.
226
     *
227
     * @return int
228
     */
229 1
    public function getAuthentication()
230
    {
231 1
        return $this->authentication;
232
    }
233
234
    /**
235
     * Set the authentication flag.
236
     *
237
     * @param int $authentication
238
     *
239
     * @return SoapSettings
240
     */
241 1
    public function setAuthentication($authentication)
242
    {
243 1
        $this->authentication = $authentication;
244
245 1
        return $this;
246
    }
247
248
    /**
249
     * Return the Cache WSDL bit flag.
250
     *
251
     * @return int
252
     */
253 1
    public function getCacheWsdl()
254
    {
255 1
        return $this->cacheWsdl;
256
    }
257
258
    /**
259
     * @param int $cacheWsdl
260
     *
261
     * @return SoapSettings
262
     */
263 1
    public function setCacheWsdl($cacheWsdl)
264
    {
265 1
        $this->cacheWsdl = $cacheWsdl;
266
267 1
        return $this;
268
    }
269
270
    /**
271
     * Returns class mapping.
272
     *
273
     * @return array|null
274
     */
275 1
    public function getClassMap()
276
    {
277 1
        return $this->classMap;
278
    }
279
280
    /**
281
     * @param array $classMap
282
     *
283
     * @return SoapSettings
284
     */
285 1
    public function setClassMap($classMap)
286
    {
287 1
        $this->classMap = $classMap;
288
289 1
        return $this;
290
    }
291
292
    /**
293
     * Return Compression flag.
294
     *
295
     * @return int
296
     */
297 1
    public function getCompression()
298
    {
299 1
        return $this->compression;
300
    }
301
302
    /**
303
     * @param int $compression
304
     *
305
     * @return SoapSettings
306
     */
307 1
    public function setCompression($compression)
308
    {
309 1
        if (in_array($compression, [SOAP_COMPRESSION_ACCEPT, SOAP_COMPRESSION_GZIP, SOAP_COMPRESSION_DEFLATE], true)) {
310 1
            $this->compression = $compression;
311 1
        }
312
313 1
        return $this;
314
    }
315
316
    /**
317
     * @return int
318
     */
319 1
    public function getConnectionTimeout()
320
    {
321 1
        return $this->connectionTimeout;
322
    }
323
324
    /**
325
     * @param int $connectionTimeout
326
     *
327
     * @return SoapSettings
328
     *
329
     * @throws InputException
330
     */
331 2
    public function setConnectionTimeout($connectionTimeout)
332
    {
333 2
        if (!is_int($connectionTimeout)) {
334 1
            throw new InputException('Not a valid timeout');
335
        }
336 1
        $this->connectionTimeout = $connectionTimeout;
337
338 1
        return $this;
339
    }
340
341
    /**
342
     * @return resource
343
     */
344 1
    public function getContext()
345
    {
346 1
        return $this->context;
347
    }
348
349
    /**
350
     * @param resource $context
351
     *
352
     * @return SoapSettings
353
     */
354 1
    public function setContext($context)
355
    {
356 1
        $this->context = $context;
357
358 1
        return $this;
359
    }
360
361
    /**
362
     * @return string
363
     */
364 1
    public function getEncoding()
365
    {
366 1
        return $this->encoding;
367
    }
368
369
    /**
370
     * @param string $encoding
371
     *
372
     * @return SoapSettings
373
     */
374 1
    public function setEncoding($encoding)
375
    {
376 1
        $this->encoding = $encoding;
377
378 1
        return $this;
379
    }
380
381
    /**
382
     * @return bool
383
     */
384 1
    public function hasExceptions()
385
    {
386 1
        return $this->exceptions;
387
    }
388
389
    /**
390
     * @param bool $exceptions
391
     *
392
     * @return SoapSettings
393
     */
394 1
    public function setExceptions($exceptions)
395
    {
396 1
        $this->exceptions = $exceptions;
397
398 1
        return $this;
399
    }
400
401
    /**
402
     * @return int
403
     */
404 1
    public function getFeatures()
405
    {
406 1
        return $this->features;
407
    }
408
409
    /**
410
     * Set SoapFeatures bit mask.
411
     *
412
     * @param int $features
413
     *
414
     * @return SoapSettings
415
     */
416 1
    public function setFeatures($features)
417
    {
418 1
        if (in_array($features, [SOAP_SINGLE_ELEMENT_ARRAYS, SOAP_USE_XSI_ARRAY_TYPE, SOAP_WAIT_ONE_WAY_CALLS], true)) {
419 1
            $this->features |= $features;
420 1
        }
421
422 1
        return $this;
423
    }
424
425
    /**
426
     * @return bool
427
     */
428 1
    public function isKeepAlive()
429
    {
430 1
        return $this->keepAlive;
431
    }
432
433
    /**
434
     * @param bool $keepAlive
435
     *
436
     * @return SoapSettings
437
     */
438 1
    public function setKeepAlive($keepAlive)
439
    {
440 1
        $this->keepAlive = $keepAlive;
441
442 1
        return $this;
443
    }
444
445
    /**
446
     * @return string
447
     */
448 1
    public function getLogin()
449
    {
450 1
        return $this->login;
451
    }
452
453
    /**
454
     * @return string
455
     */
456 1
    public function getLocalCert()
457
    {
458 1
        return $this->localCert;
459
    }
460
461
    /**
462
     * @param string $localCert
463
     *
464
     * @return SoapSettings
465
     */
466 1
    public function setLocalCert($localCert)
467
    {
468 1
        $this->localCert = $localCert;
469
470 1
        return $this;
471
    }
472
473
    /**
474
     * @return string
475
     */
476 1
    public function getPassphrase()
477
    {
478 1
        return $this->passphrase;
479
    }
480
481
    /**
482
     * @param string $login
483
     */
484 1
    public function setLogin($login)
485
    {
486 1
        $this->login = $login;
487 1
    }
488
489
    /**
490
     * @param string $passPhrase
491
     *
492
     * @return SoapSettings
493
     */
494 1
    public function setPassphrase($passPhrase)
495
    {
496 1
        $this->passphrase = $passPhrase;
497
498 1
        return $this;
499
    }
500
501
    /**
502
     * @return string
503
     */
504 1
    public function getPassword()
505
    {
506 1
        return $this->password;
507
    }
508
509
    /**
510
     * @param string $password
511
     *
512
     * @return SoapSettings
513
     */
514 7
    public function setPassword($password)
515
    {
516 7
        $this->password = $password;
517
518 7
        return $this;
519
    }
520
521
    /**
522
     * @return string
523
     */
524 1
    public function getProxyHost()
525
    {
526 1
        return $this->proxyHost;
527
    }
528
529
    /**
530
     * @param string $proxyHost
531
     *
532
     * @return SoapSettings
533
     */
534 1
    public function setProxyHost($proxyHost)
535
    {
536 1
        $this->proxyHost = $proxyHost;
537
538 1
        return $this;
539
    }
540
541
    /**
542
     * @return string
543
     */
544 1
    public function getProxyLogin()
545
    {
546 1
        return $this->proxyLogin;
547
    }
548
549
    /**
550
     * @param string $proxyLogin
551
     *
552
     * @return SoapSettings
553
     */
554 1
    public function setProxyLogin($proxyLogin)
555
    {
556 1
        $this->proxyLogin = $proxyLogin;
557
558 1
        return $this;
559
    }
560
561
    /**
562
     * @return string
563
     */
564 1
    public function getProxyPassword()
565
    {
566 1
        return $this->proxyPassword;
567
    }
568
569
    /**
570
     * @param string $proxyPassword
571
     *
572
     * @return SoapSettings
573
     */
574 1
    public function setProxyPassword($proxyPassword)
575
    {
576 1
        $this->proxyPassword = $proxyPassword;
577
578 1
        return $this;
579
    }
580
581
    /**
582
     * @return string
583
     */
584 1
    public function getProxyPort()
585
    {
586 1
        return $this->proxyPort;
587
    }
588
589
    /**
590
     * @param string $proxyPort
591
     *
592
     * @return SoapSettings
593
     */
594 1
    public function setProxyPort($proxyPort)
595
    {
596 1
        $this->proxyPort = $proxyPort;
597
598 1
        return $this;
599
    }
600
601
    /**
602
     * @return int
603
     */
604 7
    public function getSoapVersion()
605
    {
606 7
        return $this->soapVersion;
607
    }
608
609
    /**
610
     * Defaults to 1.
611
     *
612
     * @param int $soapVersion
613
     */
614 1
    public function setSoapVersion($soapVersion)
615
    {
616 1
        if (in_array($soapVersion, [SOAP_1_1, SOAP_1_2], false)) {
617 1
            $this->soapVersion = $soapVersion;
618 1
        }
619 1
    }
620
621
    /**
622
     * @return int
623
     */
624 1
    public function getSslMethod()
625
    {
626 1
        return $this->sslMethod;
627
    }
628
629
    /**
630
     * php 5.4+.
631
     *
632
     * @param int $sslMethod
633
     *
634
     * @return SoapSettings
635
     */
636 1
    public function setSslMethod($sslMethod)
637
    {
638 1
        if (PHP_VERSION_ID >= 50400 && in_array($sslMethod, self::$sslMethods, true)) {
639 1
            $this->sslMethod = $sslMethod;
640 1
        }
641
642 1
        return $this;
643
    }
644
645
    /**
646
     * @return array|null
647
     */
648 1
    public function getTypeMap()
649
    {
650 1
        return $this->typeMap;
651
    }
652
653
    /**
654
     * @param array|null $typeMap
655
     *
656
     * @return SoapSettings
657
     */
658 1
    public function setTypeMap($typeMap)
659
    {
660 1
        $this->typeMap = $typeMap;
661
662 1
        return $this;
663
    }
664
665
    /**
666
     * @return string
667
     */
668 1
    public function getUri()
669
    {
670 1
        return $this->uri;
671
    }
672
673
    /**
674
     * @param string $uri
675
     *
676
     * @return SoapSettings
677
     */
678 1
    public function setUri($uri)
679
    {
680 1
        $this->uri = $uri;
681
682 1
        return $this;
683
    }
684
685
    /**
686
     * @return string
687
     */
688 1
    public function getUserAgent()
689
    {
690 1
        return $this->userAgent;
691
    }
692
693
    /**
694
     * @param string $userAgent
695
     *
696
     * @return SoapSettings
697
     */
698 1
    public function setUserAgent($userAgent)
699
    {
700 1
        $this->userAgent = $userAgent;
701
702 1
        return $this;
703
    }
704
705
    /**
706
     * @return array
707
     */
708 15
    public function toArray()
709
    {
710 15
        return get_object_vars($this);
711
    }
712
}
713