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

PromoteSingleStrings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processStrings() 0 4 1
A promoteSingleStrings() 0 17 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
}