Completed
Push — master ( 8ee262...f95707 )
by Rémi
04:14
created

HtmlspecialcharsDecode   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 89.47%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 32
ccs 17
cts 19
cp 0.8947
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B transform() 0 29 6
1
<?php
2
/**
3
 * inetprocess/transformation
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @author Rémi Sauvat
8
 * @copyright 2005-2015 iNet Process
9
 *
10
 * @package inetprocess/transformation
11
 *
12
 * @license GNU General Public License v2.0
13
 *
14
 * @link http://www.inetprocess.com
15
 */
16
17
namespace Inet\Transformation\Rule;
18
19
use Inet\Transformation\Exception\TransformationException;
20
21
/**
22
 * Call a function and send back the result
23
 */
24
class HtmlspecialcharsDecode extends AbstractRule
25
{
26 4
    public function transform($input, $arguments)
27
    {
28
        // I should have two arguments: old format / new format
29 4
        if (count($arguments) > 1) {
30 1
            throw new TransformationException(
31
                'Rule HtmlspecialcharsDecode expects at most 1 argument'
32 1
            );
33
        }
34 3
        $flags = ENT_COMPAT | ENT_HTML401;
35 3
        if (isset($arguments[0])) {
36 2
            $flags_array = $arguments[0];
37 2
            $flags = 0;
38 2
            if (!is_array($flags_array)) {
39 1
                throw new TransformationException(
40
                    'First argument of HtmlspecialcharsDecode should be an array'
41 1
                );
42
            }
43 1
            foreach ($flags_array as $constant) {
44 1
                if (!defined($constant)) {
45
                    throw new TransformationException(
46
                        'Flags should be valid PHP constants'
47
                    );
48
                }
49 1
                $flags |= constant($constant);
50 1
            }
51 1
        }
52
53 2
        return htmlspecialchars_decode($input, $flags);
54
    }
55
}
56