Completed
Push — master ( 3b5f38...c5ceed )
by Tomáš
04:59
created

EolCharDetector::detectForContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 3
cts 4
cp 0.75
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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
use Symplify\PHP7_CodeSniffer\File\File;
12
13
final class EolCharDetector
14
{
15
    public function detectForFilePath(string $filePath) : string
16
    {
17
        $content = FileSystem::read($filePath);
18
        return $this->detectForContent($content);
19
    }
20
21 1
    public function detectForContent(string $content) : string
22
    {
23 1
        if (preg_match("/\r\n?|\n/", $content, $matches) !== 1) {
24
            // Assume there are no newlines.
25
            return "\n";
26
        }
27
28 1
        return $matches[0];
29
    }
30
}
31