Completed
Push — master ( c50b30...914d8d )
by Park Jong-Hun
02:21
created

FileUtils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getLines() 0 24 4
1
<?php
2
3
namespace Core\ErrorReporter;
4
5
use SplFileObject;
6
7
class FileUtils
8
{
9
    /**
10
     * @param string $filePath
11
     * @param int $line
12
     * @param int $fetchLineCount
13
     * @return array
14
     */
15
    public static function getLines($filePath, $line, $fetchLineCount)
16
    {
17
        $lines = [];
18
19
        $startLine = $line > 0 ? $line : 0;
20
        $endLine = $startLine + $fetchLineCount;
21
22
        $file = new SplFileObject($filePath);
23
        $file->setFlags(SplFileObject::DROP_NEW_LINE);
24
        $file->seek($startLine);
25
26
        for ($i = $startLine; $i < $endLine; $i++) {
27
            $line = $file->current();
28
29
            if ($line === false) {
30
                break;
31
            }
32
33
            $lines[$i] = $line;
34
            $file->next();
35
        }
36
37
        return $lines;
38
    }
39
}