HTMLPurifier_IDAccumulator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 4 2
A build() 0 5 1
A add() 0 6 2
1
<?php
2
3
/**
4
 * Component of HTMLPurifier_AttrContext that accumulates IDs to prevent dupes
5
 * @note In Slashdot-speak, dupe means duplicate.
6
 * @note The default constructor does not accept $config or $context objects:
7
 *       use must use the static build() factory method to perform initialization.
8
 */
9
class HTMLPurifier_IDAccumulator
10
{
11
12
    /**
13
     * Lookup table of IDs we've accumulated.
14
     * @public
15
     */
16
    public $ids = array();
17
18
    /**
19
     * Builds an IDAccumulator, also initializing the default blacklist
20
     * @param HTMLPurifier_Config $config Instance of HTMLPurifier_Config
21
     * @param HTMLPurifier_Context $context Instance of HTMLPurifier_Context
22
     * @return HTMLPurifier_IDAccumulator Fully initialized HTMLPurifier_IDAccumulator
23
     */
24
    public static function build($config, $context)
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    public static function build($config, /** @scrutinizer ignore-unused */ $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        $id_accumulator = new HTMLPurifier_IDAccumulator();
27
        $id_accumulator->load($config->get('Attr.IDBlacklist'));
28
        return $id_accumulator;
29
    }
30
31
    /**
32
     * Add an ID to the lookup table.
33
     * @param string $id ID to be added.
34
     * @return bool status, true if success, false if there's a dupe
35
     */
36
    public function add($id)
37
    {
38
        if (isset($this->ids[$id])) {
39
            return false;
40
        }
41
        return $this->ids[$id] = true;
42
    }
43
44
    /**
45
     * Load a list of IDs into the lookup table
46
     * @param $array_of_ids Array of IDs to load
47
     * @note This function doesn't care about duplicates
48
     */
49
    public function load($array_of_ids)
50
    {
51
        foreach ($array_of_ids as $id) {
52
            $this->ids[$id] = true;
53
        }
54
    }
55
}
56
57
// vim: et sw=4 sts=4
58