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