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

CompanyBuilder::extractBusinessActivities()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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