14
14
class Fixer
15
15
{
16
16
/**
17
- * The number of times we have looped over a file.
18
- *
19
17
* @var int
20
18
*/
21
19
protected $ loops = 0 ;
22
20
23
21
/**
24
- * The character used when we are adding new lines.
25
- *
26
22
* @var string
27
23
*/
28
24
protected $ eolChar = "\n" ;
@@ -40,19 +36,19 @@ class Fixer
40
36
/**
41
37
* The list of tokens that make up the file contents.
42
38
*
43
- * This is a simplified list which just contains the token content and nothing
44
- * else. This is the array that is updated as fixes are made, not the file's
45
- * token array. Imploding this array will give you the file content back.
39
+ * This is a simplified list which just contains the token content and nothing else.
40
+ * This is the array that is updated as fixes are made, not the file's token array.
41
+ * Imploding this array will give you the file content back.
46
42
*
47
- * @var array<int, string>
43
+ * @var array
48
44
*/
49
45
protected $ tokens = [];
50
46
51
47
/**
52
48
* A list of tokens that have already been fixed.
53
49
*
54
- * We don't allow the same token to be fixed more than once each time
55
- * through a file as this can easily cause conflicts between sniffs.
50
+ * We don't allow the same token to be fixed more than once each time through a file
51
+ * as this can easily cause conflicts between sniffs.
56
52
*
57
53
* @var int[]
58
54
*/
@@ -61,18 +57,16 @@ class Fixer
61
57
/**
62
58
* The last value of each fixed token.
63
59
*
64
- * If a token is being "fixed" back to its last value, the fix is
65
- * probably conflicting with another.
60
+ * If a token is being "fixed" back to its last value, the fix is probably conflicting with another.
66
61
*
67
- * @var array<int, string>
62
+ * @var array
68
63
*/
69
64
protected $ oldTokenValues = [];
70
65
71
66
/**
72
67
* A list of tokens that have been fixed during a changeset.
73
68
*
74
- * All changes in changeset must be able to be applied, or else
75
- * the entire changeset is rejected.
69
+ * All changes in changeset must be able to be applied, or else the entire changeset is rejected.
76
70
*
77
71
* @var array
78
72
*/
@@ -100,8 +94,6 @@ class Fixer
100
94
protected $ numFixes = 0 ;
101
95
102
96
/**
103
- * Starts fixing a new file.
104
- *
105
97
* @param Ruleset $ruleset
106
98
* @param Tokenizer $tokenizer
107
99
*
@@ -134,8 +126,6 @@ public function startFile(array $tokens): void
134
126
}
135
127
136
128
/**
137
- * Attempt to fix the file by processing it until no fixes are made.
138
- *
139
129
* @param string $file
140
130
*
141
131
* @return bool
@@ -181,8 +171,6 @@ public function fixFile(string $file): bool
181
171
}
182
172
183
173
/**
184
- * Generates a text diff of the original file and the new content.
185
- *
186
174
* @param string $filePath File path to diff the file against.
187
175
*
188
176
* @return string
@@ -242,8 +230,6 @@ public function generateDiff(string $filePath): string
242
230
}
243
231
244
232
/**
245
- * Get the current content of the file, as a string.
246
- *
247
233
* @return string
248
234
*/
249
235
public function getContents (): string
@@ -254,12 +240,10 @@ public function getContents(): string
254
240
}
255
241
256
242
/**
257
- * Get the current fixed content of a token.
258
- *
259
243
* This function takes changesets into account so should be used
260
244
* instead of directly accessing the token array.
261
245
*
262
- * @param int $tokenPosition The position of the token in the token stack.
246
+ * @param int $tokenPosition
263
247
*
264
248
* @return string
265
249
*/
@@ -331,12 +315,10 @@ public function rollbackChangeset(): void
331
315
}
332
316
333
317
/**
334
- * Replace the entire contents of a token.
318
+ * @param int $tokenPosition
319
+ * @param string $content
335
320
*
336
- * @param int $tokenPosition The position of the token in the token stack.
337
- * @param string $content The new content of the token.
338
- *
339
- * @return bool If the change was accepted.
321
+ * @return bool
340
322
*/
341
323
public function replaceToken (int $ tokenPosition , string $ content ): bool
342
324
{
@@ -384,11 +366,9 @@ public function replaceToken(int $tokenPosition, string $content): bool
384
366
}
385
367
386
368
/**
387
- * Reverts the previous fix made to a token.
369
+ * @param int $tokenPosition
388
370
*
389
- * @param int $tokenPosition The position of the token in the token stack.
390
- *
391
- * @return bool If a change was reverted.
371
+ * @return bool
392
372
*/
393
373
public function revertToken (int $ tokenPosition ): bool
394
374
{
@@ -404,11 +384,9 @@ public function revertToken(int $tokenPosition): bool
404
384
}
405
385
406
386
/**
407
- * Adds a newline to end of a token's content.
408
- *
409
- * @param int $tokenPosition The position of the token in the token stack.
387
+ * @param int $tokenPosition
410
388
*
411
- * @return bool If the change was accepted.
389
+ * @return bool
412
390
*/
413
391
public function addNewline (int $ tokenPosition ): bool
414
392
{
@@ -418,11 +396,9 @@ public function addNewline(int $tokenPosition): bool
418
396
}
419
397
420
398
/**
421
- * Adds a newline to the start of a token's content.
422
- *
423
- * @param int $tokenPosition The position of the token in the token stack.
399
+ * @param int $tokenPosition
424
400
*
425
- * @return bool If the change was accepted.
401
+ * @return bool
426
402
*/
427
403
public function addNewlineBefore (int $ tokenPosition ): bool
428
404
{
@@ -432,12 +408,10 @@ public function addNewlineBefore(int $tokenPosition): bool
432
408
}
433
409
434
410
/**
435
- * Adds content to the end of a token's current content.
436
- *
437
- * @param int $tokenPosition The position of the token in the token stack.
438
- * @param string $content The content to add.
411
+ * @param int $tokenPosition
412
+ * @param string $content
439
413
*
440
- * @return bool If the change was accepted.
414
+ * @return bool
441
415
*/
442
416
public function addContent (int $ tokenPosition , string $ content ): bool
443
417
{
@@ -447,12 +421,10 @@ public function addContent(int $tokenPosition, string $content): bool
447
421
}
448
422
449
423
/**
450
- * Adds content to the start of a token's current content.
424
+ * @param int $tokenPosition
425
+ * @param string $content
451
426
*
452
- * @param int $tokenPosition The position of the token in the token stack.
453
- * @param string $content The content to add.
454
- *
455
- * @return bool If the change was accepted.
427
+ * @return bool
456
428
*/
457
429
public function addContentBefore (int $ tokenPosition , string $ content ): bool
458
430
{
0 commit comments