Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
8 / 8
CsvLineGenerator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
8 / 8
 eachLine
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
8 / 8
<?php
namespace Puyo\File\Generator;
class CsvLineGenerator
{
    /**
     * CSVを1行ずつ返すgenerator
     * @param string $fullpath
     * @return \Generator
     */
    public static function eachLine($fullpath) {
        $fp = @fopen($fullpath, 'rb');
        if($fp === false) {
            throw new \RuntimeException("cannot open stream: $fullpath");
        }
        try {
            while (false !== $line = fgetcsv($fp)) {
                yield $line;
            }
        } finally {
            fclose($fp);
        }
    }
}