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

ObtainCustomersService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 41
ccs 23
cts 23
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A obtainPage() 0 11 1
A obtainAll() 0 13 2
A __construct() 0 3 1
A settings() 0 3 1
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