EmptyLinesResizer::resizeLines()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 4
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of Zenify
7
 * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace ZenifyCodingStandard\Helper\Whitespace;
11
12
use PHP_CodeSniffer_File;
13
14
15
final class EmptyLinesResizer
16
{
17
18 3
	public static function resizeLines(
19
		PHP_CodeSniffer_File $file,
20
		int $position,
21
		int $currentLineCount,
22
		int $desiredLineCount
23
	) {
24 3
		if ($currentLineCount > $desiredLineCount) {
25 3
			self::reduceBlankLines($file, $position, $currentLineCount, $desiredLineCount);
26
27
		} else {
28 3
			self::increaseBlankLines($file, $position, $currentLineCount, $desiredLineCount);
29
		}
30 3
	}
31
32
33 3
	private static function reduceBlankLines(PHP_CodeSniffer_File $file, int $position, int $from, int $to)
34
	{
35 3
		for ($i = $from; $i > $to; $i--) {
36 3
			$file->fixer->replaceToken($position, '');
37 3
			$position++;
38
		}
39 3
	}
40
41
42 3
	private static function increaseBlankLines(PHP_CodeSniffer_File $file, int $position, int $from, int $to)
43
	{
44 3
		for ($i = $from; $i < $to; $i++) {
45 3
			$file->fixer->addContentBefore($position, PHP_EOL);
46
		}
47 3
	}
48
49
}
50