1.2.258. Could Be Generator

This rule reports methods, functions… where the return value may be typed Generator. This is the case when the body of the function uses the yield and yield from keyword.

<?php

// Yield makes foo() a generator
function foo() {
    yield 1;
    // Returns an int
    return $b + 8;
}

?>

See also class.

1.2.258.1. Suggestions

  • Add Generator typehint to the method.

1.2.258.2. Specs

Short name

Typehints/CouldBeGenerator

Rulesets

All, Typechecks

Exakat since

2.2.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

class, yield, yield-from

Available in

Entreprise Edition, Exakat Cloud