Completed
Push — master ( f7424d...b53e51 )
by Alejandro
07:43
created

TestUtils   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createDelegateMock() 0 8 3
A getProphet() 0 8 2
1
<?php
2
namespace ShlinkioTest\Shlink\Common\Util;
3
4
use Interop\Http\ServerMiddleware\DelegateInterface;
5
use Prophecy\Argument;
6
use Prophecy\Prophet;
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Zend\Diactoros\Response;
10
11
class TestUtils
12
{
13
    private static $prophet;
14
15
    public static function createDelegateMock(ResponseInterface $response = null, RequestInterface $request = null)
16
    {
17
        $argument = $request ?: Argument::any();
18
        $delegate = static::getProphet()->prophesize(DelegateInterface::class);
0 ignored issues
show
Bug introduced by
Since getProphet() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getProphet() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
19
        $delegate->process($argument)->willReturn($response ?: new Response());
20
21
        return $delegate;
22
    }
23
24
    /**
25
     * @return Prophet
26
     */
27
    private static function getProphet()
28
    {
29
        if (static::$prophet === null) {
0 ignored issues
show
Bug introduced by
Since $prophet is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $prophet to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
30
            static::$prophet = new Prophet();
0 ignored issues
show
Bug introduced by
Since $prophet is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $prophet to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
31
        }
32
33
        return static::$prophet;
0 ignored issues
show
Bug introduced by
Since $prophet is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $prophet to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
34
    }
35
}
36