Completed
Push — master ( e70246...95e794 )
by Josh
03:30
created

PromoteSingleStrings::promoteSingleStrings()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 1
crap 4
1
<?php
2
3
/**
4
* @package   s9e\RegexpBuilder
5
* @copyright Copyright (c) 2016 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\RegexpBuilder\Passes;
9
10
class PromoteSingleStrings extends AbstractPass
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 4
	protected function processStrings(array $strings)
16
	{
17 4
		return array_map([$this, 'promoteSingleStrings'], $strings);
18
	}
19
20
	/**
21
	* Promote single strings found inside given string
22
	*
23
	* @param  array $string Original string
24
	* @return array         Modified string
25
	*/
26 3
	protected function promoteSingleStrings(array $string)
27
	{
28 3
		$newString = [];
29 3
		foreach ($string as $element)
30
		{
31 3
			if (is_array($element) && count($element) === 1)
32
			{
33 2
				$newString = array_merge($newString, $element[0]);
34
			}
35
			else
36
			{
37 3
				$newString[] = $element;
38
			}
39
		}
40
41 3
		return $newString;
42
	}
43
}