Completed
Branch MediaEmbedSiteConfig (7a33c9)
by Josh
03:32
created

SiteDefinitionCollection::getNotExistException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2016 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator\Collections;
9
10
use InvalidArgumentException;
11
use RuntimeException;
12
use s9e\TextFormatter\Configurator\Collections\NormalizedCollection;
13
14
class SiteDefinitionCollection extends NormalizedCollection
15
{
16
	/**
17
	* {@inheritdoc}
18
	*/
19
	protected $onDuplicateAction = 'replace';
20
21
	/**
22
	* {@inheritdoc}
23
	*/
24
	protected function getAlreadyExistsException($key)
25
	{
26
		return new RuntimeException("Media site '" . $key . "' already exists");
27
	}
28
29
	/**
30
	* {@inheritdoc}
31
	*/
32 2
	protected function getNotExistException($key)
33
	{
34 2
		return new RuntimeException("Media site '" . $key . "' does not exist");
35
	}
36
37
	/**
38
	* Validate and normalize a site ID
39
	*
40
	* @param  string $siteId
41
	* @return string
42
	*/
43 16
	public function normalizeKey($siteId)
44
	{
45 16
		$siteId = strtolower($siteId);
46 16
		if (!preg_match('(^[a-z0-9]+$)', $siteId))
47 16
		{
48 5
			throw new InvalidArgumentException('Invalid site ID');
49
		}
50
51 11
		return $siteId;
52
	}
53
54
	/**
55
	* {@inheritdoc}
56
	*/
57 2
	public function normalizeValue($siteConfig)
58
	{
59 2
		if (!is_array($siteConfig))
60 2
		{
61 1
			throw new InvalidArgumentException('Invalid site definition type');
62
		}
63
64 1
		return $siteConfig;
65
	}
66
}