TidyTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 70 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 21
loc 30
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A tidy() 21 21 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
namespace Fwlib\Web\Helper;
3
4
use Fwlib\Base\Exception\ExtensionNotLoadedException;
5
use tidy;
6
7
/**
8
 * @copyright   Copyright 2015 Fwolf
9
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
10
 */
11
trait TidyTrait
12
{
13
    /**
14
     * Format html with tidy extension
15
     *
16
     * @param   string  $html
17
     * @return  string
18
     */
19 View Code Duplication
    protected function tidy($html)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
20
    {
21
        if (!extension_loaded('tidy')) {
22
            throw (new ExtensionNotLoadedException)->setExtension('tidy');
23
24
        } else {
25
            $config = [
26
                'doctype'       => 'strict',
27
                'indent'        => true,
28
                'indent-spaces' => 2,
29
                'output-xhtml'  => true,
30
                'wrap'          => 200
31
            ];
32
33
            $tidy = new tidy;
34
            $tidy->parseString($html, $config, 'utf8');
35
            $tidy->cleanRepair();
36
37
            return tidy_get_output($tidy);
38
        }
39
    }
40
}
41