Test Failed
Branch feature/2512 (a8f148)
by Michael
09:52 queued 13s
created

HTMLPurifier_AttrDef_CSS_Ratio   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 25 6
1
<?php
2
3
/**
4
 * Validates a ratio as defined by the CSS spec.
5
 */
6
class HTMLPurifier_AttrDef_CSS_Ratio extends HTMLPurifier_AttrDef
7
{
8
    /**
9
     * @param   string               $ratio   Ratio to validate
10
     * @param   HTMLPurifier_Config  $config  Configuration options
11
     * @param   HTMLPurifier_Context $context Context
12
     *
13
     * @return  string|boolean
14
     *
15
     * @warning Some contexts do not pass $config, $context. These
16
     *          variables should not be used without checking HTMLPurifier_Length
17
     */
18
    public function validate($ratio, $config, $context)
19
    {
20
        $ratio = $this->parseCDATA($ratio);
21
22
        $parts = explode('/', $ratio, 2);
23
        $length = count($parts);
24
25
        if ($length < 1 || $length > 2) {
26
            return false;
27
        }
28
29
        $num = new \HTMLPurifier_AttrDef_CSS_Number();
30
31
        if ($length === 1) {
32
            return $num->validate($parts[0], $config, $context);
33
        }
34
35
        $num1 = $num->validate($parts[0], $config, $context);
36
        $num2 = $num->validate($parts[1], $config, $context);
37
38
        if ($num1 === false || $num2 === false) {
39
            return false;
40
        }
41
42
        return $num1 . '/' . $num2;
43
    }
44
}
45
46
// vim: et sw=4 sts=4
47