Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Yielding is not flagged as a valid return statement. See https://github.com/squizlabs/PHP_CodeSniffer/issues/479
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
30 | ERROR | @return doc comment specified, but function has no
| | return statement
/**
* Prepare one row per image file in the source column.
*
* @param \SplFileObject $file
* The source CSV file object.
*
* @return \Generator
* A new row, one for each filename in the source image column.
*/
public function getYield(\SplFileObject $file) {
foreach ($file as $row_num => $row) {
$new_row = [];
for ($i = 1; $i < 5; $i++) {
$new_row['attribute_name'] = trim($row["attribute_name$i"]);
$new_row['attribute_value'] = trim($row["attribute_value$i"]);
if ((!empty($new_row['attribute_name'])) && (!empty($new_row['attribute_value']))) {
yield($new_row);
}
}
}
}
Proposed resolution
Treat it as a return.
Remaining tasks
Code up the rule. It should be a modification of Drupal_Sniffs_Commenting_FunctionCommentSniff
Comments
Comment #2
heddnComment #3
klausiThis is fixed in Coder 8.x-3.x and does not trigger an error with the above test code. Please upgrade and test again!