From 32dba8b727cdcf0bbccc07fdbf51861c4445c44b Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:50:16 +0200 Subject: [PATCH] Use conditional return type for words() --- CHANGELOG.md | 1 + src/Faker/Generator.php | 2 +- src/Faker/Provider/Lorem.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eba2c05d41..6705173b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Refreshed ISO currencies (#919) - Improved italian phone number formats - Replaced `via.placeholder.com` with `placehold.co` in Image provider (#1013) +- Added a conditional return type to `words()` so static analysis knows `$asText` decides between `string` and `list` ## [2024-11-09, v1.24.0](https://github.com/FakerPHP/Faker/compare/v1.23.1..v1.24.0) diff --git a/src/Faker/Generator.php b/src/Faker/Generator.php index a2357d6723..20fac72de4 100644 --- a/src/Faker/Generator.php +++ b/src/Faker/Generator.php @@ -355,7 +355,7 @@ * * @property array|string $words * - * @method array|string words($nb = 3, $asText = false) + * @method ($asText is true ? string : list) words($nb = 3, $asText = false) * * @property string $sentence * diff --git a/src/Faker/Provider/Lorem.php b/src/Faker/Provider/Lorem.php index 2cfb70ea7c..95272a1109 100644 --- a/src/Faker/Provider/Lorem.php +++ b/src/Faker/Provider/Lorem.php @@ -62,7 +62,7 @@ public static function word() * @param int $nb how many words to return * @param bool $asText if true the sentences are returned as one string * - * @return array|string + * @return ($asText is true ? string : list) */ public static function words($nb = 3, $asText = false) {