Completed
Push — master ( e04a88...42a5e8 )
by Craig
07:17
created

XsltBlock   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 21.28 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormClassName() 0 4 1
A getFormTemplate() 0 4 1
B display() 10 27 6
A getFormOptions() 0 6 1

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
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\BlocksModule\Block;
13
14
use DOMDocument;
15
use XSLTProcessor;
16
use Zikula\BlocksModule\AbstractBlockHandler;
17
18
/**
19
 * Block to display a parsed xml document
20
 */
21
class XsltBlock extends AbstractBlockHandler
22
{
23
    public function display(array $properties)
24
    {
25
        if (!$this->hasPermission('xsltblock::', "$properties[title]::", ACCESS_OVERVIEW)) {
26
            return '';
27
        }
28
29
        $doc = new DOMDocument();
30
        $xsl = new XSLTProcessor();
31
32
        // load stylesheet
33 View Code Duplication
        if (isset($properties['styleurl']) && !empty($properties['styleurl'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            $doc->load($properties['styleurl']);
35
        } else {
36
            $doc->loadXML($properties['stylecontents']);
37
        }
38
        $xsl->importStyleSheet($doc);
39
40
        // load xml source
41 View Code Duplication
        if (isset($properties['docurl']) && !empty($properties['docurl'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
            $doc->load($properties['docurl']);
43
        } else {
44
            $doc->loadXML($properties['doccontents']);
45
        }
46
47
        // apply stylesheet and return output
48
        return $xsl->transformToXML($doc);
49
    }
50
51
    public function getFormClassName()
52
    {
53
        return 'Zikula\BlocksModule\Block\Form\Type\XsltBlockType';
54
    }
55
56
    public function getFormTemplate()
57
    {
58
        return '@ZikulaBlocksModule/Block/xslt_modify.html.twig';
59
    }
60
61
    public function getFormOptions()
62
    {
63
        return [
64
            'translator' => $this->getTranslator()
65
        ];
66
    }
67
}
68