1- <?php declare (strict_types=1 );
2- /**
3- * This file is part of the CleverAge/ProcessBundle package.
1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ /*
6+ * This file is part of the CleverAge/SoapProcessBundle package.
47 *
5- * Copyright (C) 2017-2019 Clever-Age
8+ * Copyright (c) Clever-Age
69 *
710 * For the full copyright and license information, please view the LICENSE
811 * file that was distributed with this source code.
1316use Psr \Log \LoggerInterface ;
1417
1518/**
16- * Class Client
19+ * Class Client.
1720 *
1821 * @author Madeline Veyrenc <mveyrenc@clever-age.com>
1922 */
2023class Client implements ClientInterface
2124{
22- /** @var string */
23- private $ code ;
24-
25- /** @var string|null */
26- private $ wsdl ;
27-
28- /** @var array */
29- private $ options ;
30-
3125 /** @var array */
3226 private $ soapOptions ;
3327
34- /** @var null| \SoapHeader[] */
28+ /** @var \SoapHeader[]|null */
3529 private $ soapHeaders ;
3630
37- /** @var LoggerInterface */
38- private $ logger ;
39-
4031 /** @var \SoapClient */
4132 private $ soapClient ;
4233
@@ -54,85 +45,54 @@ class Client implements ClientInterface
5445
5546 /**
5647 * Client constructor.
57- *
58- * @param LoggerInterface $logger
59- * @param string $code
60- * @param string|null $wsdl
61- * @param array $options
6248 */
63- public function __construct (LoggerInterface $ logger , string $ code , ?string $ wsdl , array $ options )
49+ public function __construct (private readonly LoggerInterface $ logger , private readonly string $ code , private ?string $ wsdl , private array $ options )
6450 {
65- $ this ->logger = $ logger ;
66- $ this ->code = $ code ;
67- $ this ->wsdl = $ wsdl ;
68- $ this ->options = $ options ;
6951 }
7052
71- /**
72- * @return LoggerInterface
73- */
7453 public function getLogger (): LoggerInterface
7554 {
7655 return $ this ->logger ;
7756 }
7857
7958 /**
80- * {@inheritdoc}
8159 * @throws \UnexpectedValueException
8260 */
8361 public function getCode (): string
8462 {
85- if (! $ this ->code ) {
63+ if ('' === $ this -> code || ' 0 ' === $ this ->code ) {
8664 throw new \UnexpectedValueException ('Client code is not defined ' );
8765 }
8866
8967 return $ this ->code ;
9068 }
9169
92- /**
93- * {@inheritdoc}
94- */
9570 public function getWsdl (): ?string
9671 {
9772 return $ this ->wsdl ;
9873 }
9974
100- /**
101- * {@inheritdoc}
102- */
10375 public function setWsdl (?string $ wsdl ): void
10476 {
10577 $ this ->wsdl = $ wsdl ;
10678 }
10779
108- /**
109- * {@inheritdoc}
110- */
11180 public function getOptions (): array
11281 {
11382 return $ this ->options ;
11483 }
11584
116- /**
117- * {@inheritdoc}
118- */
11985 public function setOptions (array $ options ): void
12086 {
12187 $ this ->options = $ options ;
12288 }
12389
124- /**
125- * @return array|null
126- */
12790 public function getSoapOptions (): ?array
12891 {
12992 return $ this ->soapOptions ;
13093 }
13194
132- /**
133- * @param array|null $soapOptions
134- */
135- public function setSoapOptions (array $ soapOptions = null ): void
95+ public function setSoapOptions (?array $ soapOptions = null ): void
13696 {
13797 $ this ->soapOptions = $ soapOptions ;
13898 }
@@ -148,127 +108,94 @@ public function getSoapHeaders(): ?array
148108 /**
149109 * @param \SoapHeader[]|null $soapHeaders
150110 */
151- public function setSoapHeaders (array $ soapHeaders = null ): void
111+ public function setSoapHeaders (? array $ soapHeaders = null ): void
152112 {
153113 $ this ->soapHeaders = $ soapHeaders ;
154114 }
155115
156- /**
157- * @return \SoapClient|null
158- */
159116 public function getSoapClient (): ?\SoapClient
160117 {
161118 return $ this ->soapClient ;
162119 }
163120
164- /**
165- * @param \SoapClient $soapClient
166- */
167121 public function setSoapClient (\SoapClient $ soapClient ): void
168122 {
169123 $ this ->soapClient = $ soapClient ;
170124 }
171125
172- /**
173- * @return string
174- */
175126 public function getLastRequest (): ?string
176127 {
177128 return $ this ->lastRequest ;
178129 }
179130
180- /**
181- * @param string $lastRequest
182- */
183131 public function setLastRequest (?string $ lastRequest ): void
184132 {
185133 $ this ->lastRequest = $ lastRequest ;
186134 }
187135
188- /**
189- * @return string
190- */
191136 public function getLastRequestHeaders (): ?string
192137 {
193138 return $ this ->lastRequestHeaders ;
194139 }
195140
196- /**
197- * @param string $lastRequestHeaders
198- */
199141 public function setLastRequestHeaders (?string $ lastRequestHeaders ): void
200142 {
201143 $ this ->lastRequestHeaders = $ lastRequestHeaders ;
202144 }
203145
204- /**
205- * @return string
206- */
207146 public function getLastResponse (): ?string
208147 {
209148 return $ this ->lastResponse ;
210149 }
211150
212- /**
213- * @param string $lastResponse
214- */
215151 public function setLastResponse (?string $ lastResponse ): void
216152 {
217153 $ this ->lastResponse = $ lastResponse ;
218154 }
219155
220- /**
221- * @return string
222- */
223156 public function getLastResponseHeaders (): ?string
224157 {
225158 return $ this ->lastResponseHeaders ;
226159 }
227160
228- /**
229- * @param string $lastResponseHeaders
230- */
231161 public function setLastResponseHeaders (?string $ lastResponseHeaders ): void
232162 {
233163 $ this ->lastResponseHeaders = $ lastResponseHeaders ;
234164 }
235165
236166 /**
237- * {@inheritdoc}
167+ * @return bool|mixed
238168 */
239- public function call (string $ method , array $ input = [])
169+ public function call (string $ method , array $ input = []): mixed
240170 {
241171 $ this ->initializeSoapClient ();
242172
243- $ callMethod = sprintf ('soapCall%s ' , ucfirst ($ method ));
173+ $ callMethod = \ sprintf ('soapCall%s ' , ucfirst ($ method ));
244174 if (method_exists ($ this , $ callMethod )) {
245175 return $ this ->$ callMethod ($ input );
246176 }
247177
248178 $ this ->getLogger ()->notice (
249- sprintf ("Soap call '%s' on '%s' " , $ method , $ this ->getWsdl ())
179+ \ sprintf ("Soap call '%s' on '%s' " , $ method , $ this ->getWsdl ())
250180 );
251181
252182 return $ this ->doSoapCall ($ method , $ input );
253183 }
254184
255185 /**
256- * @param string $method
257- * @param array $input
258- *
259186 * @return bool|mixed
260187 */
261- protected function doSoapCall (string $ method , array $ input = [])
188+ protected function doSoapCall (string $ method , array $ input = []): mixed
262189 {
263- if (!$ this ->getSoapClient ()) {
190+ if (!$ this ->getSoapClient () instanceof \SoapClient ) {
264191 throw new \InvalidArgumentException ('Soap client is not initialized ' );
265192 }
266193 try {
267194 $ result = $ this ->getSoapClient ()->__soapCall ($ method , $ input , $ this ->getSoapOptions (), $ this ->getSoapHeaders ());
268- } /** @noinspection PhpRedundantCatchClauseInspection */ catch (\SoapFault $ e ) {
195+ } /* @noinspection PhpRedundantCatchClauseInspection */ catch (\SoapFault $ e ) {
269196 $ this ->getLastRequestTrace ();
270197 $ this ->getLogger ()->alert (
271- sprintf ("Soap call '%s' on '%s' failed : %s " , $ method , $ this ->getWsdl (), $ e ->getMessage ()),
198+ \ sprintf ("Soap call '%s' on '%s' failed : %s " , $ method , $ this ->getWsdl (), $ e ->getMessage ()),
272199 $ this ->getLastRequestTraceArray ()
273200 );
274201
@@ -277,9 +204,9 @@ protected function doSoapCall(string $method, array $input = [])
277204
278205 $ this ->getLastRequestTrace ();
279206
280- if (array_key_exists ('trace ' , $ this ->getOptions ()) && $ this ->getOptions ()['trace ' ]) {
207+ if (\ array_key_exists ('trace ' , $ this ->getOptions ()) && $ this ->getOptions ()['trace ' ]) {
281208 $ this ->getLogger ()->debug (
282- sprintf ("Trace of soap call '%s' on '%s' " , $ method , $ this ->getWsdl ()),
209+ \ sprintf ("Trace of soap call '%s' on '%s' " , $ method , $ this ->getWsdl ()),
283210 $ this ->getLastRequestTraceArray ()
284211 );
285212 }
@@ -288,33 +215,26 @@ protected function doSoapCall(string $method, array $input = [])
288215 }
289216
290217 /**
291- * Initialize \SoapClient object
292- *
293- * @return void
218+ * Initialize \SoapClient object.
294219 */
295220 protected function initializeSoapClient (): void
296221 {
297- if (!$ this ->getSoapClient ()) {
222+ if (!$ this ->getSoapClient () instanceof \SoapClient ) {
298223 $ options = array_merge ($ this ->getOptions (), ['trace ' => true ]);
299224 $ this ->setSoapClient (new \SoapClient ($ this ->getWsdl (), $ options ));
300225 }
301226 }
302227
303- /**
304- */
305228 protected function getLastRequestTrace (): void
306229 {
307- if ($ this ->getSoapClient ()) {
230+ if ($ this ->getSoapClient () instanceof \SoapClient ) {
308231 $ this ->setLastRequest ($ this ->getSoapClient ()->__getLastRequest ());
309232 $ this ->setLastRequestHeaders ($ this ->getSoapClient ()->__getLastRequestHeaders ());
310233 $ this ->setLastResponse ($ this ->getSoapClient ()->__getLastResponse ());
311234 $ this ->setLastResponseHeaders ($ this ->getSoapClient ()->__getLastResponseHeaders ());
312235 }
313236 }
314237
315- /**
316- * @return array
317- */
318238 protected function getLastRequestTraceArray (): array
319239 {
320240 return [
0 commit comments