Passed
Push — master ( 0931bd...ddadd0 )
by Josh
13:59
created

AbstractConfigurableHostHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 7
c 1
b 0
f 1
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addHost() 0 10 2
1
<?php declare(strict_types=1);
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) The s9e authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator;
9
10
use function strtolower;
11
use s9e\TextFormatter\Configurator;
12
13
abstract class AbstractConfigurableHostHelper
14
{
15
	/**
16
	* @var Configurator
17
	*/
18
	protected Configurator $configurator;
19
20
	public function __construct(Configurator $configurator)
21
	{
22
		$this->configurator = $configurator;
23
	}
24
25
	public function addHost(string $host): void
26
	{
27
		$siteId = $this->getSiteId();
28
		if (!isset($this->configurator->registeredVars['MediaEmbed.sites'][$siteId]))
29
		{
30
			$this->configurator->MediaEmbed->add($siteId);
31
		}
32
33
		$host = strtolower($host);
34
		$this->configurator->registeredVars['MediaEmbed.hosts'][$host] = $siteId;
35
	}
36
37
	abstract protected function getSiteId(): string;
38
}