Completed
Pull Request — master (#77)
by
unknown
01:25
created

Bigfile::iterateText()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
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
            yield $this->file->fgets();
30
            $count++;
31
        }
32
33
        return $count;
34
    }
35
36
}
37