Completed
Push — master ( e86a78...1a9ef7 )
by Josh
02:17
created

ConcatenateConstantStrings   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B optimizeStream() 0 28 6
1
<?php
2
3
/**
4
* @package   s9e\SourceOptimizer
5
* @copyright Copyright (c) 2014-2018 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\SourceOptimizer\Passes;
9
10
class ConcatenateConstantStrings extends AbstractPass
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 3
	public function optimizeStream()
16
	{
17 3
		while ($this->stream->skipTo(T_CONSTANT_ENCAPSED_STRING))
18
		{
19 3
			$offset = $this->stream->key();
20 3
			$left   = $this->stream->currentText();
21 3
			$this->stream->next();
22 3
			$this->stream->skipNoise();
23 3
			if (!$this->stream->is('.'))
24
			{
25 3
				continue;
26
			}
27 3
			$this->stream->next();
28 3
			$this->stream->skipNoise();
29 3
			$right = $this->stream->currentText();
30 3
			if (!$this->stream->is(T_CONSTANT_ENCAPSED_STRING) || $left[0] !== $right[0])
31
			{
32 1
				continue;
33
			}
34 2
			$this->stream->replace([T_CONSTANT_ENCAPSED_STRING, substr($left, 0, -1) . substr($right, 1)]);
35 2
			$i = $this->stream->key();
36 2
			$this->stream->seek($i - 1);
37 2
			while (--$i >= $offset)
38
			{
39 2
				unset($this->stream[$i]);
40
			}
41
		}
42
	}
43
}