Completed
Push — refresh ( 3dadd3 )
by Tomáš
03:56
created

ConcatOperatorSniff::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 4
Ratio 30.77 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 4
loc 13
ccs 7
cts 8
cp 0.875
rs 9.2
cc 4
eloc 7
nc 3
nop 2
crap 4.0312
1
<?php
2
3
/**
4
 * This file is part of Zenify
5
 * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
6
 */
7
8
namespace ZenifyCodingStandard\Sniffs\WhiteSpace;
9
10
use PHP_CodeSniffer_File;
11
12
13
/**
14
 * Rules:
15
 * - ConcatOperator (.) should be surrounded by spaces.
16
 */
17
final class ConcatOperatorSniff implements \PHP_CodeSniffer_Sniff
18
{
19
20
	/**
21
	 * {@inheritdoc}
22
	 */
23 1
	public function register()
24
	{
25 1
		return [T_STRING_CONCAT];
26
	}
27
28
29
	/**
30
	 * {@inheritdoc}
31
	 */
32 1
	public function process(PHP_CodeSniffer_File $file, $position)
33
	{
34 1
		$tokens = $file->getTokens();
35
36 1
		if ($tokens[$position + 1]['content'] === '=') {
37
			return;
38
		}
39
40 1 View Code Duplication
		if ($tokens[$position - 1]['code'] !== T_WHITESPACE || $tokens[$position + 1]['code'] !== T_WHITESPACE) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41 1
			$error = 'Concat operator (.) should be surrounded by spaces.';
42 1
			$file->addError($error, $position);
43
		};
44 1
	}
45
46
}
47