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

SiteCollection::asConfig()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 7
nop 0
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
ccs 17
cts 17
cp 1
crap 6
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 ArrayObject;
11
use s9e\TextFormatter\Configurator\ConfigProvider;
12
use s9e\TextFormatter\Configurator\JavaScript\Dictionary;
13
14
class SiteCollection extends ArrayObject implements ConfigProvider
15
{
16
	/**
17
	* {@inheritdoc}
18
	*/
19 4
	public function asConfig()
20
	{
21 4
		$map = [];
22 4
		foreach ($this as $siteId => $siteConfig)
23
		{
24 3
			if (isset($siteConfig['host']))
25 3
			{
26 2
				foreach ((array) $siteConfig['host'] as $host)
27
				{
28 2
					$map[$host] = $siteId;
29 2
				}
30 2
			}
31
32 3
			if (isset($siteConfig['scheme']))
33 3
			{
34 1
				foreach ((array) $siteConfig['scheme'] as $scheme)
35
				{
36 1
					$map[$scheme . ':'] = $siteId;
37 1
				}
38 1
			}
39 4
		}
40
41 4
		return new Dictionary($map);
42
	}
43
}