PHP PSR1回声副作用

I was working on a command line application and I have this class that handles the business logic. This class has some method that loops all data from a \Generator and echo out some values.

I use \Generator because this command line application will loop a hundred of thousand of datum. and I need it to be print/echo in the command line the output on the fly

// SomeClass.php
class SomeClass {
    //... some code here
    public function someMethod($someArgs) { 
        foreach ($this->isFromAGenerator() as $data) {
            // the data above from `isFromAGenerator` 
            // is a data that is being yield
            echo $this->isAnotherMethod($data);
        }
    }
}

// index.php
$someClass = new SomeClass();
$someClass->someMethod(); 

This works fine and running smoothly but this is directly violates PSR1 2.3 Side Effects https://www.php-fig.org/psr/psr-1/#23-side-effects

如何在不违反PSR1副作用的情况下实现此解决方案?

评论