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
            throw new \Exception('File not found');
15
        }
16
        if ($compressed) {
17
            $this->file = new \SplFileObject('compress.zlib://'.$filename, $mode);
18
        } else {
19
            $this->file = new \SplFileObject($filename, $mode);
20
        }
21
    }
22
23
    public function iterateText()
24
    {
25
        $count = 0;
26
27
        while (! $this->file->eof()) {
28
            yield $this->file->fgets();
29
            $count++;
30
        }
31
32
        return $count;
33
    }
34
}
35