Passed
Push — master ( 7cd6c5...dd963e )
by Laurens
04:05
created

KvkPaginatorFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 38
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromProfileData() 0 11 1
A extractCompanies() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Werkspot\KvkApi\Client\Factory;
6
7
use Werkspot\KvkApi\Client\Factory\Profile\CompanyFactoryInterface;
8
use Werkspot\KvkApi\Client\KvkPaginator;
9
use Werkspot\KvkApi\Client\KvkPaginatorInterface;
10
use Werkspot\KvkApi\Client\Profile\Company;
11
12
final class KvkPaginatorFactory extends AbstractFactory implements KvkPaginatorFactoryInterface
13
{
14
    /**
15
     * @var CompanyFactoryInterface
16
     */
17
    private $companyFactory;
18
19 19
    public function __construct(CompanyFactoryInterface $companyFactory)
20
    {
21 19
        $this->companyFactory = $companyFactory;
22 19
    }
23
24 17
    public function fromProfileData(array $data): KvkPaginatorInterface
25
    {
26 17
        return new KvkPaginator(
27 17
            $this->extractIntegerOrNull('itemsPerPage', $data),
28 17
            $this->extractIntegerOrNull('startPage', $data),
29 17
            $this->extractIntegerOrNull('totalItems', $data),
30 17
            $this->extractCompanies($data['items']),
31 17
            $this->extractStringOrNull('nextLink', $data),
32 17
            $this->extractStringOrNull('previousLink', $data)
33
        );
34
    }
35
36
    /**
37
     * @return Company[]
38
     */
39 17
    private function extractCompanies(array $data): array
40
    {
41 17
        $companies = [];
42
43 17
        foreach ($data  as $company) {
44 17
            $companies[] = $this->companyFactory->fromArray($company);
45
        }
46
47 17
        return $companies;
48
    }
49
}
50