*/ final class DisallowForeachByReferenceRule implements Rule{ public function getNodeType() : string{ return Foreach_::class; } public function processNode(Node $node, Scope $scope) : array{ /** @var Foreach_ $node */ if($node->byRef){ return [ RuleErrorBuilder::message("Foreach by-reference is not allowed, because it has surprising behaviour.") ->tip("If the value variable is used outside of the foreach construct (e.g. in a second foreach), the iterable's contents will be unexpectedly altered.") ->build() ]; } return []; } }