Skip to content

Commit 0cb7d1a

Browse files
Merge pull request #1000 from cyppe/fix-return-types
Add return type annotations to TransformableData trait
2 parents 528c54c + 4a2fdbe commit 0cb7d1a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Concerns/TransformableData.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
trait TransformableData
1616
{
17+
/**
18+
* Transform the data object into an array.
19+
*
20+
* @param null|TransformationContextFactory|TransformationContext $transformationContext
21+
* @return array<string, mixed>
22+
*/
1723
public function transform(
1824
null|TransformationContextFactory|TransformationContext $transformationContext = null,
1925
): array {
@@ -39,11 +45,21 @@ public function transform(
3945
return $resolver->execute($this, $transformationContext);
4046
}
4147

48+
/**
49+
* Get all data as an array without transforming values.
50+
*
51+
* @return array<string, mixed>
52+
*/
4253
public function all(): array
4354
{
4455
return $this->transform(TransformationContextFactory::create()->withValueTransformation(false));
4556
}
4657

58+
/**
59+
* Get the data object as an array.
60+
*
61+
* @return array<string, mixed>
62+
*/
4763
public function toArray(): array
4864
{
4965
return $this->transform();
@@ -54,6 +70,11 @@ public function toJson($options = 0): string
5470
return json_encode($this->transform(), $options);
5571
}
5672

73+
/**
74+
* Get the data object as an array for JSON serialization.
75+
*
76+
* @return array<string, mixed>
77+
*/
5778
public function jsonSerialize(): array
5879
{
5980
return $this->transform();

0 commit comments

Comments
 (0)