Completed
Push — master ( 84da34...cb7888 )
by Josh
16:13
created

RegexpBuilder::assemble()   C

Complexity

Conditions 11
Paths 84

Size

Total Lines 66

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 27
cts 27
cp 1
rs 6.5951
c 0
b 0
f 0
cc 11
nc 84
nop 1
crap 11

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2019 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Configurator\Helpers;
9
10
use s9e\RegexpBuilder\Builder;
11
12
abstract class RegexpBuilder
13
{
14
	/**
15
	* Create a regexp pattern that matches a list of words
16
	*
17
	* @param  array  $words   Words to sort (must be UTF-8)
18
	* @param  array  $options
19
	* @return string
20
	*/
21 73
	public static function fromList(array $words, array $options = [])
22
	{
23
		$options += [
24 73
			'delimiter'       => '/',
25
			'caseInsensitive' => false,
26
			'specialChars'    => [],
27
			'unicode'         => true
28
		];
29
30
		// Normalize ASCII if the regexp is meant to be case-insensitive
31 73
		if ($options['caseInsensitive'])
32
		{
33 2
			foreach ($words as &$word)
34
			{
35 2
				$word = strtr($word, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
36
			}
37 2
			unset($word);
38
		}
39
40 73
		$builder = new Builder([
41 73
			'delimiter' => $options['delimiter'],
42 73
			'meta'      => $options['specialChars'],
43 73
			'input'     => $options['unicode'] ? 'Utf8' : 'Bytes',
44 73
			'output'    => $options['unicode'] ? 'Utf8' : 'Bytes'
45
		]);
46
47 73
		return $builder->build($words);
48
	}
49
}