StampService::stamp()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.25

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 3
b 0
f 0
nc 2
nop 1
dl 0
loc 17
ccs 9
cts 12
cp 0.75
crap 4.25
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Services\Stamping;
6
7
use PhpCfdi\Finkok\Definitions\Services;
8
use PhpCfdi\Finkok\FinkokSettings;
9
10
class StampService
11
{
12
    /** @var FinkokSettings */
13
    private $settings;
14
15 13
    public function __construct(FinkokSettings $settings)
16
    {
17 13
        $this->settings = $settings;
18
    }
19
20 11
    public function settings(): FinkokSettings
21
    {
22 11
        return $this->settings;
23
    }
24
25 11
    public function stamp(StampingCommand $command): StampingResult
26
    {
27 11
        $soapCaller = $this->settings()->createCallerForService(Services::stamping());
28
        // Finkok, repeat to fix bad webservice behavior of remote stamp method
29
        // This will not be fixed according to Finkok
30
        do {
31 11
            $rawResponse = $soapCaller->call('stamp', [
32 11
                'xml' => $command->xml(),
33 11
            ]);
34 11
            $result = new StampingResult('stampResult', $rawResponse);
35 11
            if (null !== $result->alerts()->findByErrorCode('307') && '' === $result->uuid()) {
36
                usleep(200000); // 0.2 seconds
37
                continue;
38
            }
39 11
            break;
40
        } while (true);
41 11
        return $result;
42
    }
43
}
44