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

Htmlspecialchars   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 37
ccs 20
cts 22
cp 0.9091
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B transform() 0 34 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 Htmlspecialchars extends AbstractRule
25
{
26 5
    public function transform($input, $arguments)
27
    {
28
        // I should have two arguments: old format / new format
29 5
        if (count($arguments) > 3) {
30 1
            throw new TransformationException(
31
                'Rule Htmlspecialchars expects at most 3 arguments'
32 1
            );
33
        }
34
        $defaults = array(
35 4
            ENT_COMPAT | ENT_HTML401,
36 4
            ini_get('default_charset'),
37
            true
38 4
        );
39 4
        if (isset($arguments[0])) {
40 2
            $flags_array = $arguments[0];
41 2
            $arguments[0] = 0;
42 2
            if (!is_array($flags_array)) {
43 1
                throw new TransformationException(
44
                    'First argument of Htmlspecialchars should be an array'
45 1
                );
46
            }
47 1
            foreach ($flags_array as $constant) {
48 1
                if (!defined($constant)) {
49
                    throw new TransformationException(
50
                        'Flags should be valid PHP constants'
51
                    );
52
                }
53 1
                $arguments[0] |= constant($constant);
54 1
            }
55 1
        }
56
57 3
        $options = $arguments + $defaults;
58 3
        return htmlspecialchars($input, $options[0], $options[1], $options[2]);
59
    }
60
}
61