Completed
Push — master ( f60c21...243075 )
by Alejandro
10:43
created

TestUtils::createReqHandlerMock()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Util;
5
6
use Prophecy\Argument;
7
use Prophecy\Prophet;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Zend\Diactoros\Response;
12
13
class TestUtils
14
{
15
    private static $prophet;
16
17
    public static function createReqHandlerMock(ResponseInterface $response = null, RequestInterface $request = null)
18
    {
19
        $argument = $request ?: Argument::any();
20
        $delegate = static::getProphet()->prophesize(RequestHandlerInterface::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...
21
        $delegate->handle($argument)->willReturn($response ?: new Response());
22
23
        return $delegate;
24
    }
25
26
    /**
27
     * @return Prophet
28
     */
29
    private static function getProphet()
30
    {
31
        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...
32
            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...
33
        }
34
35
        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...
36
    }
37
}
38