Skip to content

Commit f0988e5

Browse files
author
Administrator
committed
[docs] core/composer
1. Completed PHPDoc for the `toArrayOrValue()` core method. 2. Updated `composer.json` to include relevant keywords for better package discovery.
1 parent 2b0e8bd commit f0988e5

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ Here’s your English version of that changelog entry, keeping the same structur
44

55
---
66

7-
## [v3.1.0] - 2025-10-27
7+
## [v3.1.0-rc.2] - 2025-10-29
8+
9+
### Added
10+
- Completed PHPDoc for the `toArrayOrValue()` core method.
11+
12+
### Changed
13+
- Updated `composer.json` to include relevant keywords for better package discovery.
14+
15+
16+
## [v3.1.0-rc] - 2025-10-27
817

918
### ⚠️Note
1019
> Starting from this release, the CHANGELOG will be maintained in English only.<br>

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@
2424
}
2525
],
2626
"keywords": [
27+
"php",
2728
"dto",
28-
"data-transfer-object",
29+
"toArray",
30+
"utility",
31+
"immutable",
32+
"reflection",
33+
"type-safety",
2934
"value-object",
30-
"immutable"
35+
"serialization",
36+
"normalization",
37+
"array-conversion",
38+
"data-transfer-object"
3139
],
3240
"require-dev": {
3341
"phpunit/phpunit": "^10",

src/ImmutableBase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,20 @@ final public function toArray(): array
463463
});
464464
return $properties;
465465
}
466+
/**
467+
* Converts an object to an array if possible, otherwise returns the original value.
468+
*
469+
* This method checks whether the given value is an object implementing a `toArray()` method.
470+
* If so, it invokes that method and returns the resulting array. For all other values, the
471+
* original input is returned unchanged.
472+
*
473+
* This utility provides a lightweight normalization step for mixed-type data, ensuring that
474+
* objects capable of array conversion are consistently represented as arrays.
475+
*
476+
* @param mixed $value The value to be normalized or returned as-is.
477+
*
478+
* @return mixed The array representation of the object, or the original value if no conversion applies.
479+
*/
466480
private function toArrayOrValue(mixed $value)
467481
{
468482
if (is_object($value)) {

0 commit comments

Comments
 (0)