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

SoundsSpec   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 69.88 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 4
dl 58
loc 83
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A let() 9 9 1
A it_should_list() 11 11 1
A it_should_upload_from_path() 18 18 2
A it_should_upload_from_file() 20 20 2
A it_should_delete() 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 Prophecy\Argument;
9
use Symfony\Component\Mime\Part\DataPart;
10
use Symfony\Contracts\HttpClient\ResponseInterface;
11
use Yproximite\WannaSpeakBundle\Api\Sounds;
12
use Yproximite\WannaSpeakBundle\Api\SoundsInterface;
13
use Yproximite\WannaSpeakBundle\HttpClientInterface;
14
15
class SoundsSpec extends ObjectBehavior
16
{
17
    public function it_is_initializable()
18
    {
19
        $this->shouldHaveType(Sounds::class);
20
    }
21
22 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...
23
    {
24
        $this->beConstructedWith($client);
25
26
        // Since we are in spec, the response content will always be the, see PHPUnit tests for real response asserting.
27
        $response
28
            ->toArray()
29
            ->willReturn(['error' => null, 'data' => [/* ... */]]);
30
    }
31
32 View Code Duplication
    public function it_should_list(HttpClientInterface $client, ResponseInterface $response)
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...
33
    {
34
        $client
35
            ->request(SoundsInterface::API, 'list', [])
36
            ->shouldBeCalled()
37
            ->willReturn($response);
38
39
        $this
40
            ->list()
41
            ->shouldBe(['error' => null, 'data' => [/* ... */]]);
42
    }
43
44 View Code Duplication
    public function it_should_upload_from_path(HttpClientInterface $client, ResponseInterface $response)
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...
45
    {
46
        $client
0 ignored issues
show
Bug introduced by
The method shouldBeCalled() does not seem to exist on object<Symfony\Contracts...ient\ResponseInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
            ->request(
48
                SoundsInterface::API,
49
                'upload',
50
                Argument::that(function ($args) {
51
                    return $args['sound'] instanceof DataPart
52
                        && 'the name' === $args['name'];
53
                })
54
            )
55
            ->shouldBeCalled()
56
            ->willReturn($response);
57
58
        $this
0 ignored issues
show
Bug introduced by
The method upload() does not exist on spec\Yproximite\WannaSpeakBundle\Api\SoundsSpec. Did you maybe mean it_should_upload_from_path()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
59
            ->upload(__DIR__.'/../../../../tests/fixtures/callee.mp3', 'the name')
60
            ->shouldBe(['error' => null, 'data' => [/* ... */]]);
61
    }
62
63 View Code Duplication
    public function it_should_upload_from_file(HttpClientInterface $client, ResponseInterface $response)
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...
64
    {
65
        $client
0 ignored issues
show
Bug introduced by
The method shouldBeCalled() does not seem to exist on object<Symfony\Contracts...ient\ResponseInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
            ->request(
67
                SoundsInterface::API,
68
                'upload',
69
                Argument::that(function ($args) {
70
                    return $args['sound'] instanceof DataPart
71
                        && 'the name' === $args['name'];
72
                })
73
            )
74
            ->shouldBeCalled()
75
            ->willReturn($response);
76
77
        $file = new \SplFileInfo(__DIR__.'/../../../../tests/fixtures/callee.mp3');
78
79
        $this
0 ignored issues
show
Bug introduced by
The method upload() does not exist on spec\Yproximite\WannaSpeakBundle\Api\SoundsSpec. Did you maybe mean it_should_upload_from_path()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
80
            ->upload($file, 'the name')
81
            ->shouldBe(['error' => null, 'data' => [/* ... */]]);
82
    }
83
84
    public function it_should_delete(HttpClientInterface $client, ResponseInterface $response)
85
    {
86
        $client
87
            ->request(SoundsInterface::API, 'delete', [
88
                'name' => 'the name',
89
            ])
90
            ->shouldBeCalled()
91
            ->willReturn($response);
92
93
        $this
94
            ->delete('the name')
95
            ->shouldBe(['error' => null, 'data' => [/* ... */]]);
96
    }
97
}
98