Skip to content

Commit d0c4ede

Browse files
committed
Rename data classes for consistency and clarity
Updated class names across documentation to append "Data" for better alignment with naming conventions. This ensures uniformity and improves readability throughout the examples.
1 parent eefb049 commit d0c4ede

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

docs/CloneableData.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum Status: string
3636
Using `with` function, we can easily create new instances of the `TodoData` class with the new data:
3737

3838
```php
39-
$emptyTodo = Todo::empty();
39+
$emptyTodo = TodoData::empty();
4040

4141
// ...
4242

@@ -76,7 +76,9 @@ final readonly class PersonData extends Data
7676
public function __construct(
7777
public string $firstName,
7878
public string $lastName
79-
) {}
79+
) {
80+
$this->fullName = $this->firstName . ' ' . $this->lastName;
81+
}
8082
}
8183
```
8284

docs/DefaultValues.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ we can achieve that using plain PHP for some property types but not all of them.
77
```php
88
use Nuxtifyts\PhpDto\Data;
99

10-
final readonly class User extends Data
10+
final readonly class UserData extends Data
1111
{
1212
public function __construct(
1313
public string $firstName,
@@ -28,7 +28,7 @@ that's where `DefaultsTo` attribute comes in.
2828
use Nuxtifyts\PhpDto\Data;
2929
use Nuxtifyts\PhpDto\Attributes\Property\DefaultsTo;
3030

31-
final readonly class User extends Data
31+
final readonly class UserData extends Data
3232
{
3333
public function __construct(
3434
public string $firstName,
@@ -79,7 +79,7 @@ using the constructor is no longer possible, instead, you can make use of the
7979
Using the same example above, we can create a new instance of `User` with the default value for `config`:
8080

8181
```php
82-
$user = User::create(
82+
$user = UserData::create(
8383
firstName: 'John',
8484
lastName: 'Doe',
8585
email: 'johndoe@example.com'

docs/EmptyData.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and by default `Data` classes have the ability to create an `"empty"` instance:
88
use Nuxtifyts\PhpDto\Data;
99
use DateTimeImmutable;
1010

11-
final readonly class Todo extends Data
11+
final readonly class TodoData extends Data
1212
{
1313
public function __construct(
1414
public string $title,
@@ -30,10 +30,10 @@ enum Status: string
3030
}
3131
```
3232

33-
By calling the `empty()` method, we can create a new instance of the `Todo` class with all properties set to `null`:
33+
By calling the `empty()` method, we can create a new instance of the `TodoData` class with all properties set to `null`:
3434

3535
```php
36-
$emptyTodo = Todo::empty();
36+
$emptyTodo = TodoData::empty();
3737
```
3838

3939
> This is really useful with [Cloneable Data](https://github.com/nuxtifyts/php-dto/blob/main/docs/CloneableData.md)

docs/Normalizers.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class Goal
3131
}
3232
```
3333

34-
And we have our `Todo` data class:
34+
And we have our `TodoData` data class:
3535

3636
```php
3737
use Nuxtifyts\PhpDto\Data;
3838

39-
final readonly class Todo extends Data
39+
final readonly class TodoData extends Data
4040
{
4141
public function __construct(
4242
public string $title,
@@ -56,7 +56,8 @@ use Nuxtifyts\PhpDto\Normalizers\Normalizer;
5656

5757
final readonly class GoalTodoNormalizer extends Normalizer
5858
{
59-
public function normalize() : array|false{
59+
public function normalize(): array|false
60+
{
6061
if (!$this->value instanceof Goal) {
6162
return false;
6263
}
@@ -76,7 +77,7 @@ Next step is to add this new normalizer to the todo class:
7677
```php
7778
use Nuxtifyts\PhpDto\Data;
7879

79-
final readonly class Todo extends Data
80+
final readonly class TodoData extends Data
8081
{
8182
// ...
8283

@@ -87,7 +88,7 @@ final readonly class Todo extends Data
8788
```
8889

8990
This will add the `GoalTodoNormalizer` on top of the default normalizers. Now it'll be possible to hydrate
90-
a `Todo` instance from a `Goal` instance.
91+
a `TodoData` instance from a `Goal` instance.
9192

9293
```php
9394
$goal = new Goal(
@@ -96,5 +97,5 @@ $goal = new Goal(
9697
dueDate: new DateTimeImmutable()
9798
);
9899

99-
$todo = Todo::from($goal);
100+
$todo = TodoData::from($goal);
100101
```

docs/PropertyAttributes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This can be done using the `Computed` attribute.
1717
use Nuxtifyts\PhpDto\Data;
1818
use Nuxtifyts\PhpDto\Attributes\Property\Computed;
1919

20-
final readonly class Person extends Data
20+
final readonly class PersonData extends Data
2121
{
2222
#[Computed]
2323
public string $fullName;
@@ -43,7 +43,7 @@ This can be done using the `Aliases` attribute.
4343
use Nuxtifyts\PhpDto\Data;
4444
use Nuxtifyts\PhpDto\Attributes\Property\Aliases;
4545

46-
final readonly class Person extends Data
46+
final readonly class PersonData extends Data
4747
{
4848
public function __construct(
4949
#[Aliases('first_name')]
@@ -69,7 +69,7 @@ use Nuxtifyts\PhpDto\Data;
6969
use Nuxtifyts\PhpDto\Attributes\Property\Types\ArrayOfData;
7070
use Nuxtifyts\PhpDto\Attributes\Property\CipherTarget;
7171

72-
final readonly class User extends Data
72+
final readonly class UserData extends Data
7373
{
7474
/**
7575
* @param list<UserConfigData> $userConfigs
@@ -119,7 +119,7 @@ we can achieve that using plain PHP for some property types but not all of them.
119119
```php
120120
use Nuxtifyts\PhpDto\Data;
121121

122-
final readonly class User extends Data
122+
final readonly class UserData extends Data
123123
{
124124
public function __construct(
125125
public string $firstName,
@@ -140,7 +140,7 @@ that's where `DefaultsTo` attribute comes in.
140140
use Nuxtifyts\PhpDto\Data;
141141
use Nuxtifyts\PhpDto\Attributes\Property\DefaultsTo;
142142

143-
final readonly class User extends Data
143+
final readonly class UserData extends Data
144144
{
145145
public function __construct(
146146
public string $firstName,

docs/Quickstart.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ In this quickstart guide, you will learn the most basic usage of this package.
66
First, you should [install](https://github.com/nuxtifyts/php-dto?tab=readme-ov-file#installation) the package using composer:
77

88
We will create a Todo application, where we need to manage a list of TODOs. so we can start
9-
with creating a `Todo` data class.
9+
with creating a `TodoData` data class.
1010

1111
```php
1212
use Nuxtifyts\PhpDto\Data;
1313

14-
final readonly class Todo extends Data
14+
final readonly class TodoData extends Data
1515
{
1616
public function __construct(
1717
public string $title,
@@ -37,10 +37,10 @@ enum Status: string
3737
}
3838
```
3939

40-
We can now create a new instance of the `Todo`:
40+
We can now create a new instance of the `TodoData`:
4141

4242
```php
43-
$todo = new Todo(
43+
$todo = new TodoData(
4444
title: 'Learn PHP DTO',
4545
content: 'Learn how to use PHP DTO',
4646
status: Status::READY,
@@ -51,11 +51,11 @@ $todo = new Todo(
5151
The package allows you to hydrate these data objects from other types, for example an array:
5252

5353
```php
54-
$todo = Todo::from([
54+
$todo = TodoData::from([
5555
'title' => 'Learn PHP DTO',
5656
'content' => 'Learn how to use PHP DTO',
5757
'status' => 'ready', // Or Status::READY
58-
'dueDate' => '2025-01-01T00:00:00+00:00'
58+
'dueDate' => '2025-01-01'
5959
]);
6060
```
6161

@@ -66,7 +66,6 @@ You can also serialize the data object to an array, or a json string:
6666
$todo->toArray();
6767

6868
// Serialize to a json string
69-
json_encode($todo); // or
7069
$todo->toJson();
7170
```
7271

0 commit comments

Comments
 (0)