Completed
Push — master ( fa92b2...371532 )
by Thijs
01:32
created

TransformsCompanies::toCustifyCompany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace TestMonitor\Custify\Transforms;
4
5
use TestMonitor\Custify\Validator;
6
use TestMonitor\Custify\Resources\Company;
7
8
trait TransformsCompanies
9
{
10
    /**
11
     * @param array $companies
12
     *
13
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
14
     * @return \TestMonitor\Custify\Resources\Company[]
15
     */
16
    protected function fromCustifyCompanies($companies): array
17
    {
18
        Validator::isArray($companies);
19
20
        return array_map(function ($company) {
21
            return $this->fromCustifyCompany($company);
22
        }, $companies);
23
    }
24
25
    /**
26
     * @param array $company
27
     *
28
     * @throws \TestMonitor\Custify\Exceptions\InvalidDataException
29
     * @return \TestMonitor\Custify\Resources\Company
30
     */
31
    protected function fromCustifyCompany($company): Company
32
    {
33
        Validator::keysExists($company, ['id', 'company_id']);
34
35
        return new Company([
36
            'id' => $company['id'],
37
            'company_id' => $company['company_id'],
38
            'name' => $company['name'],
39
        ]);
40
    }
41
42
    /**
43
     * @param Company $company
44
     *
45
     * @return array
46
     */
47
    protected function toCustifyCompany(Company $company): array
48
    {
49
        return [
50
            'company_id' => $company->company_id,
51
            'name' => $company->name,
52
        ];
53
    }
54
}
55