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

EolCharDetector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 18
ccs 3
cts 7
cp 0.4286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A detectForFilePath() 0 5 1
A detectForContent() 0 9 2
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