EmptyLinesResizer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resizeLines() 0 13 2
A reduceBlankLines() 0 7 2
A increaseBlankLines() 0 6 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