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

Bigfile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 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
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