StampService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 32
ccs 13
cts 16
cp 0.8125
rs 10
c 3
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A settings() 0 3 1
A stamp() 0 17 4
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