No_Iframes   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A about() 0 4 1
A init() 0 4 1
A api_version() 0 2 1
A hook_sanitize() 0 12 3
1
<?php
2
class No_Iframes extends Plugin {
3
    private $host;
4
5
    public function about() {
6
        return array(1.0,
7
            "Remove embedded iframes (unless whitelisted)",
8
            "fox");
9
    }
10
11
    public function init($host) {
12
        $this->host = $host;
13
14
        $host->add_hook($host::HOOK_SANITIZE, $this);
15
    }
16
17
    /**
18
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
19
     */
20
    public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes) {
0 ignored issues
show
Unused Code introduced by
The parameter $site_url 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

20
    public function hook_sanitize($doc, /** @scrutinizer ignore-unused */ $site_url, $allowed_elements, $disallowed_attributes) {

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...
21
22
        $xpath = new DOMXpath($doc);
23
        $entries = $xpath->query('//iframe');
24
25
        foreach ($entries as $entry) {
26
            if (!iframe_whitelisted($entry)) {
27
                            $entry->parentNode->removeChild($entry);
28
            }
29
        }
30
31
        return array($doc, $allowed_elements, $disallowed_attributes);
32
    }
33
34
    public function api_version() {
35
        return 2;
36
    }
37
38
}
39