Passed
Pull Request — master (#19)
by
unknown
02:19
created

Fixer   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 120
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A beginChangeset() 0 4 1
A replaceToken() 0 4 1
A addContentBefore() 0 4 1
A addContent() 0 4 1
A endChangeset() 0 4 1
A removeLine() 0 10 3
A removeLines() 0 6 2
1
<?php
2
3
namespace BestIt\CodeSniffer;
4
5
use PHP_CodeSniffer_Fixer;
6
7
/**
8
 * Class Fixer
9
 *
10
 * @package BestIt\CodeSniffer
11
 * @author Nick Lubisch <[email protected]>
12
 */
13
class Fixer
14
{
15
    /**
16
     * The PHP_CodeSniffer_Fixer
17
     *
18
     * @var PHP_CodeSniffer_Fixer
19
     */
20
    private $baseFixer;
21
22
    /**
23
     * The wrapped PHP_CodeSniffer_File
24
     *
25
     * @var File
26
     */
27
    private $file;
28
29
    /**
30
     * Fixer constructor.
31
     *
32
     * @param File $file The wrapped PHP_CodeSniffer_File
33
     * @param PHP_CodeSniffer_Fixer $baseFixer The PHP_CodeSniffer_Fixer
34
     */
35 109
    public function __construct(File $file, PHP_CodeSniffer_Fixer $baseFixer)
36
    {
37 109
        $this->file = $file;
38 109
        $this->baseFixer = $baseFixer;
39 109
    }
40
41
    /**
42
     * Start recording actions for a changeset.
43
     *
44
     * @return void
45
     */
46 33
    public function beginChangeset()
47
    {
48 33
        $this->baseFixer->beginChangeset();
49 33
    }
50
51
    /**
52
     * Replace the entire contents of a token.
53
     *
54
     * @param int $stackPtr The position of the token in the token stack.
55
     * @param string $content The new content of the token.
56
     *
57
     * @return bool If the change was accepted.
58
     */
59 8
    public function replaceToken($stackPtr, $content)
60
    {
61 8
        return $this->baseFixer->replaceToken($stackPtr, $content);
62
    }
63
64
    /**
65
     * Adds content to the start of a token's current content.
66
     *
67
     * @param int $stackPtr The position of the token in the token stack.
68
     * @param string $content The content to add.
69
     *
70
     * @return bool If the change was accepted.
71
     */
72 2
    public function addContentBefore($stackPtr, $content)
73
    {
74 2
        return $this->baseFixer->addContentBefore($stackPtr, $content);
75
    }
76
77
    /**
78
     * Adds content to the end of a token's current content.
79
     *
80
     * @param int $stackPtr The position of the token in the token stack.
81
     * @param string $content The content to add.
82
     *
83
     * @return bool If the change was accepted.
84
     */
85 12
    public function addContent($stackPtr, $content)
86
    {
87 12
        return $this->baseFixer->addContent($stackPtr, $content);
88
    }
89
90
    /**
91
     * Stop recording actions for a changeset, and apply logged changes.
92
     *
93
     * @return bool Returns false if the changeset is in conflict
94
     */
95 33
    public function endChangeset()
96
    {
97 33
        return $this->baseFixer->endChangeset();
98
    }
99
100
    /**
101
     * Removes the given line.
102
     *
103
     * @param int $line The line which is to be removed
104
     *
105
     * @return void
106
     */
107 16
    public function removeLine($line)
108
    {
109 16
        foreach ($this->file->getTokens() as $tagPtr => $tagToken) {
110 16
            if ($tagToken['line'] !== $line) {
111 16
                continue;
112
            }
113
114 16
            $this->baseFixer->replaceToken($tagPtr, '');
115
        }
116 16
    }
117
118
    /**
119
     * Removes lines by given start and end.
120
     *
121
     * @param int $startLine The first line which is to be removed
122
     * @param int $endLine The last line which is to be removed
123
     *
124
     * @return void
125
     */
126 16
    public function removeLines($startLine, $endLine)
127
    {
128 16
        for ($line = $startLine; $line <= $endLine; $line++) {
129 16
            $this->removeLine($line);
130
        }
131 16
    }
132
}
133