Passed
Push — master ( 6c9087...fb9083 )
by Josh
14:03
created

AbstractConfigurableHostHelper::getHostRegexp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
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\SiteHelpers;
9
10
use function array_keys, strtolower;
11
12
abstract class AbstractConfigurableHostHelper extends AbstractSiteHelper
13
{
14
	public function addHost(string $host): void
15
	{
16
		$this->addHosts([$host]);
17
	}
18
19
	public function addHosts(array $hosts): void
20
	{
21
		$siteId = $this->getSiteId();
22
		if (!isset($this->configurator->registeredVars['MediaEmbed.sites'][$siteId]))
23
		{
24
			$this->configurator->MediaEmbed->add($siteId);
25
		}
26
27
		foreach ($hosts as $host)
28
		{
29
			$host = strtolower($host);
30
			$this->configurator->registeredVars['MediaEmbed.hosts'][$host] = $siteId;
31
		}
32
	}
33
34
	/**
35
	* Generate a regexp that 
36
	*/
37
	public function getHostRegexp(): string
38
	{
39
	}
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
40
41
	abstract protected function getSiteId(): string;
42
43
	public function setHosts(array $hosts): void
44
	{
45
		$siteId = $this->getSiteId();
46
		if (!isset($this->configurator->registeredVars['MediaEmbed.sites'][$siteId]))
47
		{
48
			$this->configurator->MediaEmbed->add($siteId);
49
		}
50
51
		// Remove previously set hosts for this site
52
		$unsetHosts = array_keys(
53
			(array) $this->configurator->registeredVars['MediaEmbed.hosts'],
54
			$siteId,
55
			true
56
		);
57
		foreach ($unsetHosts as $host)
58
		{
59
			unset($this->configurator->registeredVars['MediaEmbed.hosts'][$host]);
60
		}
61
62
		$this->addHosts($hosts);
63
	}
64
}