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

FileUtils::getLines()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 24
rs 8.6845
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
}