DataObjectFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 17
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 5 1
A __construct() 0 3 1
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