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

Element::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
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