Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeniorCollaboratorsImport
0.00% covered (danger)
0.00%
0 / 20
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 / 20
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace Domain\Shared\Integrations\Senior;
4
5use Domain\Request\DTOs\CollaboratorsDTO;
6use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException;
7
8use SoapFault;
9use function __;
10use function is_null;
11
12class SeniorCollaboratorsImport extends SeniorImportBase
13{
14    /**
15     * @param CollaboratorsDTO $collaboratorsDTO
16     * @return array
17     * @throws IntegrationSoapSeniorException
18     */
19    public function execute(CollaboratorsDTO $collaboratorsDTO): array
20    {
21        $wsdlURI = config('integration.url') . '/sapiens_Synccom_br_Soelx_colaboradores?wsdl';
22
23        try {
24            $params = $collaboratorsDTO->toArray();
25
26            $client = new SeniorSoapClient($wsdlURI, $this->options);
27            $response = $client->Listar(config('integration.user'), config('integration.user_password'), 0, $params);
28
29            $this->verifyErroFromSenior($response, $wsdlURI);
30
31            if (!isset($response->colaboradores)) {
32                throw new IntegrationSoapSeniorException(__(
33                    'Collaborator not found.',
34                ));
35            }
36
37            return is_array($response->colaboradores)
38                ? $response->colaboradores
39                : [$response->colaboradores];
40
41        } catch (SoapFault $soapFault) {
42            throw new IntegrationSoapSeniorException(
43                __("Failure to consume Senior's soap: :message (:wsdl)", [
44                    'message' => $soapFault->getMessage(),
45                    'wsdl' => $wsdlURI,
46                ]),
47                previous: $soapFault
48            );
49        }
50    }
51}