Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeniorQueryExecute
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace Domain\Shared\Integrations\Senior;
4
5use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException;
6use SoapFault;
7use function __;
8use function is_null;
9
10class SeniorQueryExecute extends SeniorImportBase
11{
12    /**
13     * @param string $query
14     * @param int $offset
15     * @param int $limit
16     * @return array
17     * @throws IntegrationSoapSeniorException
18     */
19    public function execute(string $query, int $offset = 0, int $limit = 1000): array
20    {
21        $wsdlURI = config('integration.url') . '/sapiens_Synccom_br_Soelx_Util?wsdl';
22        try {
23            $client = new SeniorSoapClient($wsdlURI, $this->options);
24            $queryArray = [
25                "ReturnType" => 0,
26                "columns" => [],
27                "table" => [],
28                "join" => [],
29                "where" => [],
30                "order" => [],
31                "limit" => $limit,
32                "offSet" => $offset,
33                "queryCompleted" => $query
34            ];
35            $response = $client->genericConsult(config('integration.user'), config('integration.user_password'), 0, $queryArray);
36
37            if (isset($response->erroExecucao)) {
38                throw new IntegrationSoapSeniorException(
39                    __("Senior's SOAP request returned with an error: :message (:wsdl)", [
40                        'message' => $response->erroExecucao,
41                        'wsdl' => $wsdlURI,
42                    ]),
43
44                );
45            }
46
47            if (is_null($response->pmJsonResponse)) {
48                return [];
49            }
50
51            return $this->convertBase64InArray($response->pmJsonResponse);
52
53        } catch (SoapFault $soapFault) {
54            throw new IntegrationSoapSeniorException(
55                __("Failure to consume Senior's soap: :message (:wsdl)", [
56                    'message' => $soapFault->getMessage(),
57                    'wsdl' => $wsdlURI,
58                ]),
59                previous: $soapFault
60            );
61        }
62    }
63}