Passed
Push — main ( b480f2...a8d709 )
by Carlos C
02:53 queued 12s
created

ObtainCustomersService::settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Services\Registration;
6
7
use PhpCfdi\Finkok\Definitions\Services;
8
use PhpCfdi\Finkok\FinkokSettings;
9
10
class ObtainCustomersService
11
{
12
    /** @var FinkokSettings */
13
    private $settings;
14
15 4
    public function __construct(FinkokSettings $settings)
16
    {
17 4
        $this->settings = $settings;
18
    }
19
20 3
    public function settings(): FinkokSettings
21
    {
22 3
        return $this->settings;
23
    }
24
25 1
    public function obtainAll(): Customers
26
    {
27 1
        $page = 0;
28 1
        $result = new Customers([]);
29
30
        do {
31 1
            $page = $page + 1;
32 1
            $command = new ObtainCustomersCommand($page);
33 1
            $current = $this->obtainPage($command);
34 1
            $result = $result->merge($current->customers());
35 1
        } while ($current->pagesInformation()->hasMorePages());
36
37 1
        return $result;
38
    }
39
40 3
    public function obtainPage(ObtainCustomersCommand $command): ObtainCustomersResult
41
    {
42 3
        $soapCaller = $this->settings()->createCallerForService(
43 3
            Services::registration(),
44 3
            'username',
45 3
            'password'
46 3
        );
47 3
        $rawResponse = $soapCaller->call('customers', [
48 3
            'page' => $command->page(),
49 3
        ]);
50 3
        return new ObtainCustomersResult($rawResponse);
51
    }
52
}
53