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

ConcatOperatorSniff   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 0
cbo 1
dl 4
loc 30
ccs 9
cts 10
cp 0.9
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A process() 4 13 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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