Passed
Push — master ( 1167f2...7f7b1f )
by Manuel
01:41
created

WSCryptDecryptSoapClient::getDefaultCABundle()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.439
c 0
b 0
f 0
cc 5
eloc 25
nc 5
nop 0
1
<?php
2
3
/*
4
 * This file is part of the GestPayWS library.
5
 *
6
 * (c) Manuel Dalla Lana <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EndelWar\GestPayWS;
13
14
class WSCryptDecryptSoapClient
15
{
16
    protected $wsdlUrl = [
17
        'test' => 'https://sandbox.gestpay.net/gestpay/GestPayWS/WsCryptDecrypt.asmx?wsdl',
18
        'production' => 'https://ecomms2s.sella.it/gestpay/GestPayWS/WsCryptDecrypt.asmx?wsdl',
19
    ];
20
    public $wsdlEnvironment;
21
    protected $streamContextOption = [];
22
    protected $certificatePeerName = [
23
        'test' => 'sandbox.gestpay.net',
24
        'production' => 'ecomms2s.sella.it',
25
    ];
26
    /** @var \soapClient $soapClient */
27
    protected $soapClient;
28
    public $version = '1.3.1';
29
30
    /**
31
     * WSCryptDecryptSoapClient constructor.
32
     * @param bool|false $testEnv enable the test environment
33
     * @param null $caFile path to Certification Authority bundle file
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $caFile is correct as it would always require null to be passed?
Loading history...
34
     */
35
    public function __construct($testEnv = false, $caFile = null)
0 ignored issues
show
Unused Code introduced by
The parameter $caFile is not used and could be removed. ( Ignorable by Annotation )

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

35
    public function __construct($testEnv = false, /** @scrutinizer ignore-unused */ $caFile = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        $soapClientDefaultOption = [
38
            'user_agent' => 'EndelWar-GestPayWS/' . $this->version . ' (+https://github.com/endelwar/GestPayWS)',
39
            'stream_context' => $this->getStreamContext($testEnv),
40
            'connection_timeout' => 3000,
41
        ];
42
        if ($testEnv) {
43
            $soapClientEnvironmentOption = $this->setTestEnvironment();
44
        } else {
45
            $soapClientEnvironmentOption = $this->setProductionEnvironment();
46
        }
47
        $soapClientOption = array_merge($soapClientDefaultOption, $soapClientEnvironmentOption);
48
        $this->soapClient = new \soapClient($this->wsdlUrl[$this->wsdlEnvironment], $soapClientOption);
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    private function setTestEnvironment()
55
    {
56
        $this->wsdlEnvironment = 'test';
57
        $soapClientTestOption = [
58
            'trace' => true,
59
            'cache_wsdl' => WSDL_CACHE_NONE,
60
        ];
61
62
        return $soapClientTestOption;
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    private function setProductionEnvironment()
69
    {
70
        $this->wsdlEnvironment = 'production';
71
72
        return [];
73
    }
74
75
    /**
76
     * @param bool $testEnv
77
     * @return resource
78
     */
79
    private function getStreamContext($testEnv = false)
80
    {
81
        if ($testEnv) {
82
            $host = $this->certificatePeerName['test'];
83
        } else {
84
            $host = $this->certificatePeerName['production'];
85
        }
86
87
        $this->streamContextOption['ssl']['crypto_method'] = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
88
89
        $this->streamContextOption['ssl']['allow_self_signed'] = true;
90
        $this->streamContextOption['ssl']['verify_peer'] = true;
91
        $this->streamContextOption['ssl']['SNI_enabled'] = true;
92
93
        // Disable TLS compression to prevent CRIME attacks.
94
        $this->streamContextOption['ssl']['disable_compression'] = true;
95
96
        $this->streamContextOption['ssl']['peer_name'] = $host;
97
        $this->streamContextOption['ssl']['verify_peer_name'] = true;
98
99
        return stream_context_create($this->streamContextOption);
100
    }
101
102
    /**
103
     * @return \soapClient
104
     */
105
    public function getSoapClient()
106
    {
107
        return $this->soapClient;
108
    }
109
}
110