BaseModel   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 29
rs 10
wmc 3
ccs 6
cts 6
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 3 1
A toArray() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Arrayable;
6
7
use function json_encode;
8
use const JSON_THROW_ON_ERROR;
9
10
/**
11
 * @template TKey of array-key
12
 * @template TValue
13
 * @implements \Inspirum\Arrayable\Model<TKey,TValue>
14
 */
15
abstract class BaseModel implements Model
16
{
17
    /**
18
     * @return array<TKey,TValue>
19
     */
20
    abstract public function __toArray(): array;
21
22
    /**
23
     * @return array<TKey,TValue>
24
     */
25 2
    public function toArray(): array
26
    {
27 2
        return $this->__toArray();
28
    }
29
30
    /**
31
     * @return array<TKey,TValue>
32
     */
33 2
    public function jsonSerialize(): array
34
    {
35 2
        return $this->__toArray();
36
    }
37
38
    /**
39
     * @throws \JsonException
40
     */
41 2
    public function __toString(): string
42
    {
43 2
        return json_encode($this->jsonSerialize(), JSON_THROW_ON_ERROR);
44
    }
45
}
46