Completed
Push — master ( 43bea0...004255 )
by Laurens
02:04
created

CompanyBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 93.55%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 67
ccs 29
cts 31
cp 0.9355
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A fromArray() 0 21 1
A extractBusinessActivities() 0 8 2
A extractAddresses() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Werkspot\KvkApi\Client\Builder\Profile;
6
7
use DateTime;
8
use Werkspot\KvkApi\Api\Profile\Company;
9
use Werkspot\KvkApi\Client\Builder\AbstractBuilder;
10
use Werkspot\KvkApi\Client\Builder\Profile\Company\AddressBuilderInterface;
11
use Werkspot\KvkApi\Client\Builder\Profile\Company\BusinessActivityBuilderInterface;
12
use Werkspot\KvkApi\Client\Builder\Profile\Company\TradeNamesBuilderInterface;
13
14
final class CompanyBuilder extends AbstractBuilder implements CompanyBuilderInterface
15
{
16
    /**
17
     * @var AddressBuilderInterface
18
     */
19
    private $addressBuilder;
20
21
    /**
22
     * @var BusinessActivityBuilderInterface
23
     */
24
    private $businessActivityBuilder;
25
26
    /**
27
     * @var TradeNamesBuilderInterface
28
     */
29
    private $tradeNamesBuilder;
30
31 5
    public function __construct(
32
        TradeNamesBuilderInterface $tradeNamesBuilder,
33
        BusinessActivityBuilderInterface $businessActivityBuilder,
34
        AddressBuilderInterface $addressBuilder
35
    ) {
36 5
        $this->tradeNamesBuilder = $tradeNamesBuilder;
37 5
        $this->businessActivityBuilder = $businessActivityBuilder;
38 5
        $this->addressBuilder = $addressBuilder;
39 5
    }
40
41 5
    public function fromArray(array $data): Company
42
    {
43 5
        return new Company(
44 5
            $this->extractIntegerOrNull('kvkNumber', $data),
45 5
            $this->extractStringOrNull('branchNumber', $data),
46 5
            $this->extractIntegerOrNull('rsin', $data),
47 5
            $this->tradeNamesBuilder->fromArray($data['tradeNames']),
48 5
            $this->extractStringOrNull('legalForm', $data),
49 5
            $this->extractBusinessActivities($data),
50 5
            $this->extractBoolean('hasEntryInBusinessRegister', $data),
51 5
            $this->extractBoolean('hasCommercialActivities', $data),
52 5
            $this->extractBoolean('hasNonMailingIndication', $data),
53 5
            $this->extractBoolean('isLegalPerson', $data),
54 5
            $this->extractBoolean('isBranch', $data),
55 5
            $this->extractBoolean('isMainBranch', $data),
56 5
            $this->extractIntegerOrNull('employees', $data),
57 5
            new DateTime($data['foundationDate']),
58 5
            new DateTime($data['registrationDate']),
59 5
            $this->extractAddresses($data)
60
        );
61
    }
62
63 5
    private function extractBusinessActivities($data): ?array
64
    {
65 5
        if (array_key_exists('businessActivities', $data)) {
66 5
            return $this->businessActivityBuilder->fromArray($data['businessActivities']);
67
        }
68
69
        return null;
70
    }
71
72 5
    private function extractAddresses($data): ?array
73
    {
74 5
        if (array_key_exists('addresses', $data)) {
75 5
            return $this->addressBuilder->fromArray($data['addresses']);
76
        }
77
78
        return null;
79
    }
80
}
81