ConcatenateConstantStrings::optimizeStream()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 28
ccs 19
cts 19
cp 1
rs 8.439
cc 6
eloc 18
nc 5
nop 0
crap 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
	protected 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
}