Completed
Pull Request — master (#77)
by
unknown
04:47
created

BigFile::iterateText()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
// inspirated by:https://dzone.com/articles/processing-large-files-using-php
4
5
namespace Spatie\DbSnapshots;
6
7
class BigFile
8
{
9
    protected $file;
10
11
    public function __construct($filename, $mode = "r",$compressed=false)
12
    {
13
        if (!file_exists($filename)) {
14
15
            throw new \Exception("File not found");
16
        }
17
        if ($compressed){
18
            $this->file = new \SplFileObject("compress.zlib://".$filename, $mode);
19
        }else{
20
            $this->file = new \SplFileObject($filename, $mode);
21
        }
22
    }
23
24
    public function iterateText()
25
    {
26
        $count = 0;
27
28
        while (!$this->file->eof()) {
29
30
            yield $this->file->fgets();
31
32
            $count++;
33
        }
34
        return $count;
35
    }
36
37
}
38