SoapClient   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 205
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 205
rs 10
c 0
b 0
f 0
wmc 21
lcom 1
cbo 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A connect() 0 12 3
C call() 0 22 7
A getHost() 0 4 1
A setHost() 0 6 1
A getOptions() 0 4 1
A setOptions() 0 6 1
A getRequest() 0 4 1
A setRequest() 0 6 1
A getService() 0 4 1
A setService() 0 6 1
A getClient() 0 4 1
A setClient() 0 6 1
1
<?php
2
3
namespace Bludata\Soap;
4
5
use InvalidArgumentException;
6
use SoapClient as NativeSoapClient;
7
8
class SoapClient
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $host;
14
15
    /**
16
     * @var array
17
     */
18
    protected $options;
19
20
    /**
21
     * @var SoapClient
22
     */
23
    protected $client;
24
25
    /**
26
     * @var mixed
27
     */
28
    protected $service;
29
30
    /**
31
     * @var mixed
32
     */
33
    protected $request;
34
35
    /**
36
     * Cria um instancia para comunicação com WSDL utilizando SoapClient.
37
     *
38
     * @param string $host    Parametro obrigatório, endereço do WSDL
39
     * @param array  $options Parametro opcional, referente aos options que serão utilizados
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 92 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
40
     */
41
    public function __construct($host, array $options = [])
42
    {
43
        $this->setHost($host)
44
            ->setOptions($options);
45
    }
46
47
    /**
48
     * Efetua a conexão inicial com o WSDL.
49
     *
50
     * @return self
51
     */
52
    public function connect()
53
    {
54
        if (!$host = $this->getHost()) {
55
            throw new InvalidArgumentException('Host não informado');
56
        }
57
58
        if (!$this->client) {
59
            $this->client = new NativeSoapClient($host, $this->getOptions());
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SoapClient($host, $this->getOptions()) of type object<SoapClient> is incompatible with the declared type object<Bludata\Soap\SoapClient> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
        }
61
62
        return $this;
63
    }
64
65
    /**
66
     * Faz a chamada para o WSDL, de acordo com os parametros pré-configurados para o serviço.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 94 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
67
     *
68
     * @return SoapClient::__soapCall
0 ignored issues
show
Documentation introduced by
The doc-type SoapClient::__soapCall could not be parsed: Unknown type name "SoapClient::__soapCall" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
69
     */
70
    public function call()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
71
    {
72
        $host = $this->getHost();
73
        if (!$host || empty($host)) {
74
            throw new InvalidArgumentException('Host não informado');
75
        }
76
77
        $service = $this->getService();
78
        if (!$service || empty($service)) {
79
            throw new InvalidArgumentException('Serviço não informado');
80
        }
81
82
        $request = $this->getRequest();
83
        if (!$request || empty($request)) {
84
            throw new InvalidArgumentException('Request não informada');
85
        }
86
87
        $this->connect();
88
        $client = $this->getClient();
89
90
        return $client->__soapCall($service, $request);
0 ignored issues
show
Bug introduced by
The method __soapCall() does not seem to exist on object<Bludata\Soap\SoapClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
    }
92
93
    /**
94
     * Retorna o host do WSDL.
95
     *
96
     * @return string
97
     */
98
    public function getHost()
99
    {
100
        return $this->host;
101
    }
102
103
    /**
104
     * Recebe o endereço do WSDL.
105
     *
106
     * @param string $host
107
     *
108
     * @return self
109
     */
110
    public function setHost($host)
111
    {
112
        $this->host = $host;
113
114
        return $this;
115
    }
116
117
    /**
118
     * Retorna os options utilizados no SoapClient.
119
     *
120
     * @return array
121
     */
122
    public function getOptions()
123
    {
124
        return $this->options;
125
    }
126
127
    /**
128
     * Recebe os options que serão utilizados no SoapClient.
129
     *
130
     * @param array $options
131
     *
132
     * @return self
133
     */
134
    public function setOptions(array $options)
135
    {
136
        $this->options = $options;
137
138
        return $this;
139
    }
140
141
    /**
142
     * Retorna dados da requisição.
143
     *
144
     * @return mixed
145
     */
146
    public function getRequest()
147
    {
148
        return $this->request;
149
    }
150
151
    /**
152
     * Recebe dados para montar o request.
153
     *
154
     * @param array
155
     *
156
     * @return self
157
     */
158
    public function setRequest($request)
159
    {
160
        $this->request = $request;
161
162
        return $this;
163
    }
164
165
    /**
166
     * Retorna o serviço utilizado.
167
     *
168
     * @return mixed
169
     */
170
    public function getService()
171
    {
172
        return $this->service;
173
    }
174
175
    /**
176
     * Recebe o serviço que sera utilizado no WSDL.
177
     *
178
     * @param string $service
179
     *
180
     * @return self
181
     */
182
    public function setService($service)
183
    {
184
        $this->service = $service;
185
186
        return $this;
187
    }
188
189
    /**
190
     * Retorna a instancia do SoapClient que foi incializada.
191
     *
192
     * @return mixed
193
     */
194
    public function getClient()
195
    {
196
        return $this->client;
197
    }
198
199
    /**
200
     * Recebe o SoapClient que sera utilizado.
201
     *
202
     * @param SoapClient $client
0 ignored issues
show
Documentation introduced by
Should the type for parameter $client not be NativeSoapClient?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
203
     *
204
     * @return self
205
     */
206
    public function setClient(NativeSoapClient $client)
207
    {
208
        $this->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type object<SoapClient> is incompatible with the declared type object<Bludata\Soap\SoapClient> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
209
210
        return $this;
211
    }
212
}
213