Completed
Pull Request — master (#11)
by Carlos C
03:41
created

StampService::stamp()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.3244

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
nc 2
nop 1
dl 0
loc 17
ccs 8
cts 11
cp 0.7272
crap 4.3244
rs 9.9
c 3
b 0
f 0
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 3
    public function __construct(FinkokSettings $settings)
16
    {
17 3
        $this->settings = $settings;
18 3
    }
19
20 1
    public function settings(): FinkokSettings
21
    {
22 1
        return $this->settings;
23
    }
24
25 1
    public function stamp(StampingCommand $command): StampingResult
26
    {
27 1
        $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 1
            $rawResponse = $soapCaller->call('stamp', [
32 1
                'xml' => $command->xml(),
33
            ]);
34 1
            $result = new StampingResult('stampResult', $rawResponse);
35 1
            if (null !== $result->alerts()->findByErrorCode('307') && '' === $result->uuid()) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $result->alerts()->findByErrorCode('307') targeting PhpCfdi\Finkok\Services\...erts::findByErrorCode() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
                usleep(200000); // 0.2 seconds
37
                continue;
38
            }
39 1
            break;
40
        } while (true);
41 1
        return $result;
42
    }
43
}
44