Completed
Pull Request — master (#19)
by
unknown
08:16
created

FixerHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A removeLine() 0 10 3
A removeLines() 0 6 2
1
<?php
2
3
namespace BestIt\Helper;
4
5
use PHP_CodeSniffer_File;
6
7
/**
8
 * Class FixerHelper
9
 *
10
 * @package BestIt\Helper
11
 * @author Nick Lubisch <[email protected]>
12
 */
13
class FixerHelper
14
{
15
    /**
16
     * Removes the given line.
17
     *
18
     * @param PHP_CodeSniffer_File $file The php cs file.
19
     * @param int $line The line which is to be removed
20
     *
21
     * @return void
22
     */
23 12
    public static function removeLine(PHP_CodeSniffer_File $file, $line)
24
    {
25 12
        foreach ($file->getTokens() as $tagPtr => $tagToken) {
26 12
            if ($tagToken['line'] !== $line) {
27 12
                continue;
28
            }
29
30 12
            $file->fixer->replaceToken($tagPtr, '');
31
        }
32 12
    }
33
34
    /**
35
     * Removes lines by given start and end.
36
     *
37
     * @param PHP_CodeSniffer_File $file The php cs file
38
     * @param int $startLine The first line which is to be removed
39
     * @param int $endLine The last line which is to be removed
40
     *
41
     * @return void
42
     */
43 12
    public static function removeLines(PHP_CodeSniffer_File $file, $startLine, $endLine)
44
    {
45 12
        for ($line = $startLine; $line <= $endLine; $line++) {
46 12
            self::removeLine($file, $line);
47
        }
48 12
    }
49
}
50