ImageClassificationItem returns string from getConfidenceScorePercentage and uses uppercase NULL in hints
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3584863. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) >>> <p>[Tracker]<br> <strong>Update Summary: </strong>[One-line status update for stakeholders]<br> <strong>Short Description: </strong>ImageClassificationItem::getConfidenceScorePercentage() is typed as string and returns mixed float/string; type hints also use uppercase NULL instead of lowercase null.<br> <strong>Check-in Date: </strong>MM/DD/YYYY<br> [/Tracker]</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>In <code>src/OperationType/ImageClassification/ImageClassificationItem.php</code>, <code>getConfidenceScorePercentage()</code> is declared with return type <code>string</code> but the docblock says <code>float|null</code>, and the body returns either a float (<code>round($this-&gt;confidenceScore * 100, 2)</code>) or the string <code>'0'</code>. The return value is inconsistent and does not match the declared type, which is confusing for callers doing numeric comparisons or formatting, and can cause subtle bugs when the score is zero.</p> <p>In the same file, the nullable type hints use uppercase <code>NULL</code> (for example <code>float|NULL</code>) in both property declarations, constructor arguments, setters, and docblocks. Drupal coding standards and PHP convention is lowercase <code>null</code> for type expressions.</p> <p>Technically this is breaking since the class is not final, but its minor enough to be added to minor updates.</p> <h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4> <ol> <li>Open <code>src/OperationType/ImageClassification/ImageClassificationItem.php</code>.</li> <li>Look at <code>getConfidenceScorePercentage()</code>: declared <code>: string</code>, returns <code>round(...)</code> (float) or <code>'0'</code> (string).</li> <li>Look at the property/constructor/setter signatures for <code>$confidenceScore</code>: they use <code>float|NULL</code> with uppercase <code>NULL</code>.</li> </ol> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <ul> <li>Change <code>getConfidenceScorePercentage()</code> to return <code>float</code> consistently. Return <code>0.0</code> instead of <code>'0'</code> when the confidence score is null or zero, and update the return type declaration and docblock to <code>float</code>.</li> <li>Replace all uppercase <code>NULL</code> in type expressions with lowercase <code>null</code> in this file (property declaration, constructor, setter, and docblocks).</li> <li>Check other <code>ImageClassification*</code> files for the same uppercase-NULL pattern and fix them in the same change.</li> <li>Update or add tests in <code>tests/src/Unit/OperationType/ImageClassification/</code> to cover the float return type of <code>getConfidenceScorePercentage()</code>, including the null/zero case.</li> </ul> <h3 id="summary-ai-usage">AI usage (if applicable)</h3> <p>[x] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p> <p>[ ] AI Assisted Code<br> [ ] AI Generated Code<br> [ ] Vibe Coded</p> <p>- <strong>This issue was created with the help of AI</strong></p>
issue