Passed
Pull Request — develop (#18)
by Kevin
03:03 queued 22s
created

AbstractContextConfigurationFile::getContexts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Magium\Configuration\File\Context;
4
5
use Magium\Configuration\Config\Config;
6
use Magium\Configuration\File\AbstractAdapter;
7
8
abstract class AbstractContextConfigurationFile extends AbstractAdapter
9
{
10 6
    protected function configureSchema(\DOMElement $element)
11
    {
12 6
        $schema = realpath(__DIR__ . '/../../../assets/context.xsd');
13 6
        $element->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.magiumlib.com/ConfigurationContext');
14 6
        $element->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', 'http://www.magiumlib.com/ConfigurationContext ' . $schema);
15 6
        return $schema;
16
    }
17
18
    public function getContexts()
19
    {
20
        $contexts = [Config::CONTEXT_DEFAULT];
21
        $xml = $this->toXml();
22
        $xml->registerXPathNamespace('s', 'http://www.magiumlib.com/ConfigurationContext');
23
        $configuredContexts = $xml->xpath('//s:context');
24
        foreach ($configuredContexts as $context) {
25
            $contexts[] = (string)$context['id'];
26
        }
27
        return $contexts;
28
    }
29
}
30