AbstractDataObject   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A getEntityId() 0 3 2
A toJson() 0 3 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
use function json_encode;
11
12
abstract class AbstractDataObject implements DataObjectInterface
13
{
14
    protected string $entityIdFieldName;
15
16
    protected array $data;
17
18
    public function __construct(array $data)
19
    {
20
        $this->data = $data;
21
    }
22
23
    final public function toArray(): array
24
    {
25
        return $this->data;
26
    }
27
28
    final public function toJson(): string
29
    {
30
        return json_encode($this->data);
31
    }
32
33
    final public function getEntityId(): ?int
34
    {
35
        return isset($this->data[$this->entityIdFieldName]) ? (int) $this->data[$this->entityIdFieldName] : null;
36
    }
37
}
38