Passed
Push — master ( 4b4859...1d252d )
by Daimona
02:04
created

Element   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A regexFromArray() 0 6 2
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Wiki;
4
5
/**
6
 * Base class for wiki elements
7
 */
8
abstract class Element {
9
	/**
10
	 * Return a regex for matching the name of the element
11
	 *
12
	 * @param string $delimiter
13
	 * @return string
14
	 */
15
	abstract public function getRegex( string $delimiter = '/' ) : string;
16
17
	/**
18
	 * Get a regex matching any element in the given array
19
	 *
20
	 * @param self[] $elements
21
	 * @param string $delimiter
22
	 * @return string
23
	 * @todo Is this the right place?
24
	 */
25
	public static function regexFromArray( array $elements, string $delimiter = '/' ) : string {
26
		$bits = [];
27
		foreach ( $elements as $el ) {
28
			$bits[] = $el->getRegex( $delimiter );
29
		}
30
		return '(?:' . implode( '|', $bits ) . ')';
31
	}
32
}
33