DataObjectFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Copyright © Thomas Klein, All rights reserved.
4
 * See LICENSE bundled with this library for license details.
5
 */
6
declare(strict_types=1);
7
8
namespace Zoho\Desk\Model;
9
10
/**
11
 * @api
12
 */
13
final class DataObjectFactory
14
{
15
    /**
16
     * @var string[]
17
     */
18
    private array $dataObjectTypes;
19
20
    public function __construct(array $dataObjectTypes = [])
21
    {
22
        $this->dataObjectTypes = $dataObjectTypes;
23
    }
24
25
    public function create(string $entityType, array $data = []): DataObjectInterface
26
    {
27
        $dataObjectClass = $this->dataObjectTypes[$entityType] ?? DataObject::class;
28
29
        return new $dataObjectClass($data);
30
    }
31
}
32