Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (success)
80.00%
4 / 5
CRAP
91.67% covered (success)
91.67%
11 / 12
FileIterator53
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (success)
80.00%
4 / 5
7.03
91.67% covered (success)
91.67%
11 / 12
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 createByPath
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 __destruct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 current
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 key
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
<?php
namespace Puyo\File\Iterator;
/**
 * ファイルを読み込んで1行単位で返すIterator
 *
 * php-5.5以降であればGeneratorを使った方がパフォーマンスがよい。
 * 5.5.11以降であればSplFileObjectもバイナリファイルに対応されている。
 *
 * @uses >= php-5.3
 * @version 0.1.0
 */
abstract class FileIterator53 implements \Iterator
{
    /** @var resource */
    protected $fp;
    /** @var mixed scalar */
    protected $_key;
    /** @var mixed */
    protected $buf;
    /**
     * @param resource $fp
     */
    public function __construct($fp) {
        if(!is_resource($fp)) {
            throw new \InvalidArgumentException();
        }
        $this->fp = $fp;
    }
    /**
     * @param string $fullpath
     * @param string $mode
     * @return static
     */
    public static function createByPath($fullpath, $mode='rb') {
        $fp = @fopen($fullpath, $mode);
        if(!is_resource($fp)) {
            throw new \RuntimeException("cannot open stream: $fullpath");
        }
        return new static($fp);
    }
    public function __destruct() {
        @fclose($this->fp);
    }
    public function current() {
        return $this->buf;
    }
    public function key() {
        return $this->_key;
    }
}