Completed
Branch master (06cb84)
by Tomáš
06:00
created

EolCharDetector::detectForFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\PHP7_CodeSniffer\Parser;
9
10
use Nette\Utils\FileSystem;
11
12
final class EolCharDetector
13
{
14 1
    public function detectForFilePath(string $filePath) : string
15
    {
16 1
        $content = FileSystem::read($filePath);
17 1
        return $this->detectForContent($content);
18
    }
19
20 2
    public function detectForContent(string $content) : string
21
    {
22 2
        if (preg_match("/\r\n?|\n/", $content, $matches) !== 1) {
23
            // Assume there are no newlines.
24 1
            return "\n";
25
        }
26
27 2
        return $matches[0];
28
    }
29
}
30