Test Failed
Pull Request — develop (#18)
by Kevin
02:51
created

AbstractContextConfigurationFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 45 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 9
loc 20
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSchema() 0 7 1
A getContexts() 9 9 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\Config;
6
use Magium\Configuration\File\AbstractAdapter;
7
8
abstract class AbstractContextConfigurationFile extends AbstractAdapter
9
{
10
    protected function configureSchema(\DOMElement $element)
11
    {
12
        $schema = realpath(__DIR__ . '/../../../assets/context.xsd');
13
        $element->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.magiumlib.com/ConfigurationContext');
14
        $element->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', 'http://www.magiumlib.com/ConfigurationContext ' . $schema);
15
        return $schema;
16
    }
17
18 View Code Duplication
    public function getContexts()
19
    {
20
        $contexts = [Config::CONTEXT_DEFAULT];
21
        $configuredContexts = $this->toXml()->xpath('//s:context');
22
        foreach ($configuredContexts as $context) {
23
            $contexts[] = (string)$context['id'];
24
        }
25
        return $contexts;
26
    }
27
}
28