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

EolCharDetector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 18
ccs 7
cts 7
cp 1
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
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