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

CompanyFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 67
ccs 31
cts 31
cp 1
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\Factory\Profile;
6
7
use DateTime;
8
use Werkspot\KvkApi\Client\Factory\AbstractFactory;
9
use Werkspot\KvkApi\Client\Factory\Profile\Company\AddressFactoryInterface;
10
use Werkspot\KvkApi\Client\Factory\Profile\Company\BusinessActivityFactoryInterface;
11
use Werkspot\KvkApi\Client\Factory\Profile\Company\TradeNamesFactoryInterface;
12
use Werkspot\KvkApi\Client\Profile\Company;
13
14
final class CompanyFactory extends AbstractFactory implements CompanyFactoryInterface
15
{
16
    /**
17
     * @var AddressFactoryInterface
18
     */
19
    private $addressFactory;
20
21
    /**
22
     * @var BusinessActivityFactoryInterface
23
     */
24
    private $businessActivityFactory;
25
26
    /**
27
     * @var TradeNamesFactoryInterface
28
     */
29
    private $tradeNamesFactory;
30
31 19
    public function __construct(
32
        TradeNamesFactoryInterface $tradeNamesFactory,
33
        BusinessActivityFactoryInterface $businessActivityFactory,
34
        AddressFactoryInterface $addressFactory
35
    ) {
36 19
        $this->tradeNamesFactory = $tradeNamesFactory;
37 19
        $this->businessActivityFactory = $businessActivityFactory;
38 19
        $this->addressFactory = $addressFactory;
39 19
    }
40
41 17
    public function fromArray(array $data): Company
42
    {
43 17
        return new Company(
44 17
            $this->extractIntegerOrNull('kvkNumber', $data),
45 17
            $this->extractStringOrNull('branchNumber', $data),
46 17
            $this->extractIntegerOrNull('rsin', $data),
47 17
            $this->tradeNamesFactory->fromArray($data['tradeNames']),
48 17
            $this->extractStringOrNull('legalForm', $data),
49 17
            $this->extractBusinessActivities($data),
50 17
            $this->extractBoolean('hasEntryInBusinessRegister', $data),
51 17
            $this->extractBoolean('hasCommercialActivities', $data),
52 17
            $this->extractBoolean('hasNonMailingIndication', $data),
53 17
            $this->extractBoolean('isLegalPerson', $data),
54 17
            $this->extractBoolean('isBranch', $data),
55 17
            $this->extractBoolean('isMainBranch', $data),
56 17
            $this->extractIntegerOrNull('employees', $data),
57 17
            new DateTime($data['foundationDate']),
58 17
            new DateTime($data['registrationDate']),
59 17
            $this->extractAddresses($data)
60
        );
61
    }
62
63 17
    private function extractBusinessActivities($data): ?array
64
    {
65 17
        if (array_key_exists('businessActivities', $data)) {
66 15
            return $this->businessActivityFactory->fromArray($data['businessActivities']);
67
        }
68
69 2
        return null;
70
    }
71
72 17
    private function extractAddresses($data): ?array
73
    {
74 17
        if (array_key_exists('addresses', $data)) {
75 16
            return $this->addressFactory->fromArray($data['addresses']);
76
        }
77
78 1
        return null;
79
    }
80
}
81