Total Complexity | 13 |
Total Lines | 80 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class FormattedItem implements Arrayable, Jsonable |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * The original item |
||
13 | * |
||
14 | * @var mixed |
||
15 | */ |
||
16 | private $original; |
||
17 | |||
18 | /** |
||
19 | * Formatted items to prepare |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $prepared = []; |
||
24 | |||
25 | 35 | public function __construct($original) |
|
26 | { |
||
27 | 35 | $this->original = $original; |
|
28 | 35 | } |
|
29 | |||
30 | 25 | public static function create($original) |
|
31 | { |
||
32 | 25 | return new static($original); |
|
33 | } |
||
34 | |||
35 | 16 | public function original() |
|
36 | { |
||
37 | 16 | return $this->original; |
|
38 | } |
||
39 | |||
40 | 10 | public function isType(string $type) |
|
41 | { |
||
42 | 10 | return $this->original() instanceof $type; |
|
43 | } |
||
44 | |||
45 | |||
46 | 25 | public function addRow($key, $value) |
|
47 | { |
||
48 | 25 | $this->prepared[$key] = $value; |
|
49 | 25 | } |
|
50 | |||
51 | 9 | public function getColumnNames() |
|
52 | { |
||
53 | 9 | return array_keys($this->prepared); |
|
54 | } |
||
55 | |||
56 | 12 | public function getItem($column, $default = null) |
|
57 | { |
||
58 | 12 | if(array_key_exists($column, $this->prepared) && $this->prepared[$column] !== null) { |
|
59 | 11 | return $this->prepared[$column]; |
|
60 | } |
||
61 | 9 | return $default; |
|
62 | } |
||
63 | |||
64 | 10 | public function preparedItems(): array |
|
65 | { |
||
66 | 10 | return $this->prepared; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @inheritDoc |
||
71 | */ |
||
72 | 3 | public function toArray() |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * @inheritDoc |
||
79 | */ |
||
80 | 2 | public function toJson($options = 0) |
|
81 | { |
||
82 | 2 | return json_encode($this->toArray(), 0); |
|
83 | } |
||
84 | |||
85 | 1 | public function __toString() |
|
88 | } |
||
89 | } |