AbstractDataObject::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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