Completed
Pull Request — master (#29)
by Hugo
01:27
created

StatisticsSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 29.03 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 9
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A let() 9 9 1
A it_should_get_stats() 0 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Yproximite\WannaSpeakBundle\Api;
6
7
use PhpSpec\ObjectBehavior;
8
use Symfony\Contracts\HttpClient\ResponseInterface;
9
use Yproximite\WannaSpeakBundle\Api\Statistics;
10
use Yproximite\WannaSpeakBundle\Api\StatisticsInterface;
11
use Yproximite\WannaSpeakBundle\HttpClientInterface;
12
13
class StatisticsSpec extends ObjectBehavior
14
{
15
    public function it_is_initializable()
16
    {
17
        $this->shouldHaveType(Statistics::class);
18
    }
19
20 View Code Duplication
    public function let(HttpClientInterface $client, ResponseInterface $response): void
0 ignored issues
show
Duplication introduced by
This method 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...
21
    {
22
        $this->beConstructedWith($client);
23
24
        // Since we are in spec, the response content will always be the, see PHPUnit tests for real response asserting.
25
        $response
26
            ->toArray()
27
            ->willReturn(['error' => null, 'data' => [/* ... */]]);
28
    }
29
30
    public function it_should_get_stats(HttpClientInterface $client, ResponseInterface $response)
31
    {
32
        $client
33
            ->request(StatisticsInterface::API, 'did', [
34
                'tag1' => '12345',
35
            ])
36
            ->shouldBeCalled()
37
            ->willReturn($response);
38
39
        $this
40
            ->did(['tag1' => '12345'])
41
            ->shouldBe(['error' => null, 'data' => [/* ... */]]);
42
    }
43
}
44