Passed
Push — master ( 7f7d2c...7dbe13 )
by Daimona
02:03
created

RegexUtils::regexFromArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Utils;
4
5
class RegexUtils {
6
	/**
7
	 * Get a regex matching any element in the given array
8
	 *
9
	 * @param string $delimiter
10
	 * @param IRegexAble ...$elements
11
	 * @return string
12
	 */
13
	public static function regexFromArray( string $delimiter = '/', IRegexAble ...$elements ) : string {
14
		$bits = [];
15
		foreach ( $elements as $el ) {
16
			$bits[] = $el->getRegex( $delimiter );
17
		}
18
		return '(?:' . implode( '|', $bits ) . ')';
19
	}
20
}
21