Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
8 / 8 |
LineGenerator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
eachLine | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
<?php | |
namespace Puyo\File\Generator; | |
class LineGenerator | |
{ | |
/** | |
* ファイルを1行ずつ返すgenerator | |
* @param $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 = fgets($fp)) { | |
yield $line; | |
} | |
} finally { | |
@fclose($fp); | |
} | |
} | |
} |