Completed
Push — master ( 2d3e3c...0995af )
by Rob
09:50 queued 08:39
created

XssWrapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 12 2
A setLocalName() 0 5 1
1
<?php
2
3
namespace devtoolboxuk\cerberus\Wrappers;
4
5
/**
6
 *
7
 * Detect if XSS has been passed through
8
 *
9
 * Class XssWrapper
10
 * @package devtoolboxuk\cerberus\Wrappers
11
 */
12
class XssWrapper extends Wrapper
13
{
14
15 2
    public function process()
16
    {
17 2
        $this->initWrapper($this->setLocalName());
18
19 2
        $xss = $this->soteria->xss(true);
20 2
        $xss->clean($this->getReference());
0 ignored issues
show
Bug introduced by
The method clean does only exist in devtoolboxuk\soteria\handlers\Xss, but not in devtoolboxuk\soteria\handlers\Sanitise.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
21 2
        if (!$xss->result()->isValid()) {
22 1
            $this->setScore($this->getRealScore());
23 1
            $this->setResult();
24
        }
25
26 2
    }
27
28 2
    private function setLocalName()
29
    {
30 2
        $name = str_replace(__NAMESPACE__ . '\\', '', __CLASS__);
31 2
        return str_replace('Wrapper', '', $name);
32
    }
33
}