Skip to content

Commit 3e2cdf5

Browse files
committed
Moving functions from Data to base data
1 parent dd309e5 commit 3e2cdf5

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/Concerns/BaseData.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,17 @@ final public function jsonSerialize(): array
156156
throw new SerializeException($e->getMessage(), $e->getCode(), $e);
157157
}
158158
}
159+
160+
/**
161+
* @throws SerializeException
162+
*/
163+
final public function toArray(): array
164+
{
165+
return $this->jsonSerialize();
166+
}
167+
168+
final public function toJson(): false|string
169+
{
170+
return json_encode($this);
171+
}
159172
}

src/Contracts/BaseData.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ public static function create(mixed ...$args): static;
2121
*/
2222
public function jsonSerialize(): array;
2323

24+
/**
25+
* @return array<string, mixed>
26+
*
27+
* @throws SerializeException
28+
*/
29+
public function toArray(): array;
30+
31+
/**
32+
* @return false|string
33+
*
34+
* @throws SerializeException
35+
*/
36+
public function toJson(): false|string;
37+
2438
/**
2539
* @throws DeserializeException
2640
*/

src/Data.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,11 @@
66
use Nuxtifyts\PhpDto\Contracts\EmptyData as EmptyDataContract;
77
use Nuxtifyts\PhpDto\Concerns\BaseData;
88
use Nuxtifyts\PhpDto\Concerns\EmptyData;
9-
use Nuxtifyts\PhpDto\Exceptions\SerializeException;
109

1110
abstract readonly class Data implements
1211
BaseDataContract,
1312
EmptyDataContract
1413
{
1514
use BaseData;
1615
use EmptyData;
17-
18-
/**
19-
* @return array<string, mixed>
20-
*
21-
* @throws SerializeException
22-
*/
23-
final public function toArray(): array
24-
{
25-
return $this->jsonSerialize();
26-
}
27-
28-
final public function toJson(): false|string
29-
{
30-
return json_encode($this);
31-
}
3216
}

0 commit comments

Comments
 (0)