Passed
Push — master ( b3e686...761a52 )
by Daimona
01:54
created

Element   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 2

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
	 * @return string
13
	 */
14
	abstract public function getRegex() : string;
15
16
	/**
17
	 * Get a regex matching any element in the given array
18
	 *
19
	 * @param self[] $elements
20
	 * @return string
21
	 * @fixme Is this the right place?
22
	 */
23
	public static function regexFromArray( array $elements ) : string {
24
		$bits = [];
25
		foreach ( $elements as $el ) {
26
			$bits[] = $el->getRegex();
27
		}
28
		return '(?:' . implode( '|', $bits ) . ')';
29
	}
30
}
31