integration::testEmailForUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace devtoolboxuk\soteria;
4
5
use PHPUnit\Framework\TestCase;
6
7
class integration extends TestCase
8
{
9
    private $security;
10
11
    function __construct($name = null, array $data = [], $dataName = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
    {
13
        parent::__construct($name, $data, $dataName);
14
        $this->security = new SoteriaService();
15
    }
16
17
    function testEmailForUrl()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18
    {
19
        $sanitise = $this->security->sanitise();
20
        $email = '[email protected]';
21
        echo "\nUnclean String: " . $email;
22
        echo "\n";
23
        echo "\nSanitised Url: " . $sanitise->removeUrl($email);
24
        if ($sanitise->isSanitised()) {
25
            echo "\n1";
26
        }
27
    }
28
29
    function inte()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30
    {
31
        $xss = $this->security->xss();
32
        $sanitise = $this->security->sanitise();
33
34
35
        echo "\nXSS";
36
        $unCleanString = 'Visit my website http://www.doajob.org?redirect=https://www.google.com';
37
38
39
        echo "\nUnclean String: " . $unCleanString;
40
        $cleanString = $xss->clean($unCleanString);
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...
41
        echo "\nXSS Cleaned String: " . $cleanString;
42
        $cleanString = $xss->cleanUrl($unCleanString);
0 ignored issues
show
Bug introduced by
The method cleanUrl 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...
43
        echo "\nXSS Cleaned Url: " . $cleanString;
44
        echo "\n";
45
46
        echo "\nSanitised Url: " . $sanitise->removeUrl($unCleanString);
47
        if ($sanitise->isSanitised()) {
48
            echo "\n1";
49
        }
50
51
        echo "\nString without a Url: " . $sanitise->removeUrl("Rob WIlson");
52
        if ($sanitise->isSanitised()) {
53
            echo "\n1";
54
        }
55
56
57
    }
58
59
}
60