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

BigFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

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