AbstractContextConfigurationFile   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 31.82 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 7
loc 22
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSchema() 7 7 1
A getContexts() 0 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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