Skip to content

Commit 12ff1bf

Browse files
committed
feature symfony#59075 [Uid] Add `@return non-empty-string annotations to AbstractUid` and relevant functions (niravpateljoin)
This PR was merged into the 7.3 branch. Discussion ---------- [Uid] Add ``@return` non-empty-string` annotations to `AbstractUid` and relevant functions | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issue | Fix symfony#59076 | License | MIT This Merge Request introduces ``@return` non-empty-string` annotations to the AbstractUid class and other relevant functions in the Symfony UID component. By explicitly defining the return type as non-empty-string, this change improves type safety and ensures stricter static analysis when working with UIDs. ### Rationale - Symfony 7.3 has adopted stricter type safety guidelines, including support for non-empty-string in interfaces like UserInterface::getUserIdentifier. Aligning the UID component with these standards improves consistency across the framework. - Adding these annotations benefits developers by providing enhanced autocompletion and error detection in IDEs and tools like Psalm and PHPStan. ### Changes Made - Updated PHPDoc comments in AbstractUid and related classes to specify ``@return` non-empty-string` for methods where applicable. - Verified all usages of these methods to ensure compatibility with the stricter return type. ### Backward Compatibility - This change does not affect backward compatibility, as it only updates PHPDoc annotations. The runtime behavior of the methods remains the same. Commits ------- 41dacf7 Add `@return` non-empty-string annotations to AbstractUid and relevant functions
2 parents b7ed0a4 + 41dacf7 commit 12ff1bf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Symfony/Component/Uid/AbstractUid.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,17 @@ public static function fromRfc4122(string $uid): static
8585

8686
/**
8787
* Returns the identifier as a raw binary string.
88+
*
89+
* @return non-empty-string
8890
*/
8991
abstract public function toBinary(): string;
9092

9193
/**
9294
* Returns the identifier as a base58 case-sensitive string.
9395
*
9496
* @example 2AifFTC3zXgZzK5fPrrprL (len=22)
97+
*
98+
* @return non-empty-string
9599
*/
96100
public function toBase58(): string
97101
{
@@ -104,6 +108,8 @@ public function toBase58(): string
104108
* @see https://tools.ietf.org/html/rfc4648#section-6
105109
*
106110
* @example 09EJ0S614A9FXVG9C5537Q9ZE1 (len=26)
111+
*
112+
* @return non-empty-string
107113
*/
108114
public function toBase32(): string
109115
{
@@ -127,6 +133,8 @@ public function toBase32(): string
127133
* @see https://datatracker.ietf.org/doc/html/rfc9562/#section-4
128134
*
129135
* @example 09748193-048a-4bfb-b825-8528cf74fdc1 (len=36)
136+
*
137+
* @return non-empty-string
130138
*/
131139
public function toRfc4122(): string
132140
{
@@ -143,6 +151,8 @@ public function toRfc4122(): string
143151
* Returns the identifier as a prefixed hexadecimal case insensitive string.
144152
*
145153
* @example 0x09748193048a4bfbb8258528cf74fdc1 (len=34)
154+
*
155+
* @return non-empty-string
146156
*/
147157
public function toHex(): string
148158
{
@@ -161,6 +171,9 @@ public function equals(mixed $other): bool
161171
return $this->uid === $other->uid;
162172
}
163173

174+
/**
175+
* @return non-empty-string
176+
*/
164177
public function hash(): string
165178
{
166179
return $this->uid;
@@ -171,16 +184,25 @@ public function compare(self $other): int
171184
return (\strlen($this->uid) - \strlen($other->uid)) ?: ($this->uid <=> $other->uid);
172185
}
173186

187+
/**
188+
* @return non-empty-string
189+
*/
174190
final public function toString(): string
175191
{
176192
return $this->__toString();
177193
}
178194

195+
/**
196+
* @return non-empty-string
197+
*/
179198
public function __toString(): string
180199
{
181200
return $this->uid;
182201
}
183202

203+
/**
204+
* @return non-empty-string
205+
*/
184206
public function jsonSerialize(): string
185207
{
186208
return $this->uid;

0 commit comments

Comments
 (0)