TidyTrait::tidy()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
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