Completed
Push — master ( 9ef838...0845f2 )
by Rob
01:58
created

integration::inte()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
namespace devtoolboxuk\soteria;
4
5
use PHPUnit\Framework\TestCase;
6
7
class integration extends TestCase
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
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...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

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...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testEmailForUrl.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

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...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for inte.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

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