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

FixerHelper::removeLines()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 3
crap 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