CurlFactoryTest::testCreateClient()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Tests\Unit\ClientFactory;
6
7
use Http\Client\Curl\Client;
8
use Http\HttplugBundle\ClientFactory\CurlFactory;
9
use PHPUnit\Framework\TestCase;
10
use Psr\Http\Message\ResponseFactoryInterface;
11
use Psr\Http\Message\StreamFactoryInterface;
12
13
/**
14
 * @author Tobias Nyholm <[email protected]>
15
 */
16 View Code Duplication
class CurlFactoryTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    public function testCreateClient(): void
19
    {
20
        if (!class_exists(Client::class)) {
21
            $this->markTestSkipped('Curl client is not installed');
22
        }
23
24
        $factory = new CurlFactory(
25
            $this->getMockBuilder(ResponseFactoryInterface::class)->getMock(),
0 ignored issues
show
Documentation introduced by
$this->getMockBuilder(\P...face::class)->getMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ResponseFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
            $this->getMockBuilder(StreamFactoryInterface::class)->getMock()
0 ignored issues
show
Documentation introduced by
$this->getMockBuilder(\P...face::class)->getMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\StreamFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
        );
28
        $client = $factory->createClient();
29
30
        $this->assertInstanceOf(Client::class, $client);
31
    }
32
}
33