Passed
Push — master ( 54b834...db39b8 )
by Daimona
01:31
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
	/** @var Controller */
10
	protected $controller;
11
12
	/**
13
	 * @param Controller $controller
14
	 */
15
	public function __construct( Controller $controller ) {
16
		$this->controller = $controller;
17
	}
18
19
	/**
20
	 * Return a regex for matching the name of the element
21
	 *
22
	 * @return string
23
	 */
24
	abstract public function getRegex() : string;
25
26
	/**
27
	 * Get a regex matching any element in the given array
28
	 *
29
	 * @param self[] $elements
30
	 * @return string
31
	 * @todo Is this the right place?
32
	 */
33
	public static function regexFromArray( array $elements ) : string {
34
		$bits = [];
35
		foreach ( $elements as $el ) {
36
			$bits[] = $el->getRegex();
37
		}
38
		return '(?:' . implode( '|', $bits ) . ')';
39
	}
40
}
41