GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FileParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getParsed() 0 25 3
A __construct() 0 7 2
1
<?php
2
3
namespace Spatie\CodeOutline\Parser;
4
5
use Spatie\CodeOutline\Elements\EmptyLine;
6
use Spatie\CodeOutline\Elements\Line;
7
use Spatie\CodeOutline\Elements\Page;
8
use Spatie\CodeOutline\Exceptions\FileNotFound;
9
10
class FileParser implements Parser
11
{
12
    /** @var string */
13
    protected $path;
14
15
    public function __construct(string $path)
16
    {
17
        if (!file_exists($path)) {
18
            throw FileNotFound::path($path);
19
        }
20
21
        $this->path = $path;
22
    }
23
24
    public function getParsed(): Page
25
    {
26
        $contents = file_get_contents($this->path);
27
28
        $lines = explode(PHP_EOL, $contents);
29
30
        $page = new Page();
31
32
        foreach ($lines as $line) {
33
            if (strlen($line) === 0) {
34
                $page[] = new EmptyLine();
35
36
                continue;
37
            }
38
39
            $totalLineCount = strlen($line);
40
41
            $characterCount = strlen(ltrim($line));
42
43
            $indentationCount = $totalLineCount - $characterCount;
44
45
            $page[] = Line::make($indentationCount, $characterCount);
46
        }
47
48
        return $page;
49
    }
50
}
51