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

Bigfile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
A iterateText() 0 11 2
1
<?php
2
3
// inspirated by:https://dzone.com/articles/processing-large-files-using-php
4
5
namespace Spatie\DbSnapshots;
6
7
use \Exception;
8
use \SplFileObject;
9
10
class Bigfile
11
{
12
    protected $file;
13
14
    public function __construct($filename, $mode = 'r', $compressed = false)
15
    {
16
        if (! file_exists($filename)) {
17
            throw new Exception('File not found');
18
        }
19
        $this->file = new SplFileObject(($compressed ? 'compress.zlib://'.$filename : $filename), $mode);
20
    }
21
22
    public function iterateText()
23
    {
24
        $count = 0;
25
26
        while (! $this->file->eof()) {
27
            yield $this->file->fgets();
28
            $count++;
29
        }
30
31
        return $count;
32
    }
33
}
34