Completed
Pull Request — master (#29)
by Nicolas
03:33 queued 01:42
created

DownloadSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 5
dl 20
loc 55
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_should_be_an_api() 0 4 1
A it_has_a_package_with_all_languages() 0 5 1
A it_has_a_package_with_one_language() 0 5 1
A it_has_a_copy_destination() 0 5 1
A it_downloads_all_translations() 10 10 1
A it_downloads_french_translations() 10 10 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
namespace spec\Akeneo\Crowdin\Api;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Akeneo\Crowdin\Client;
8
use Guzzle\Http\Client as HttpClient;
9
use Guzzle\Http\Message\Response;
10
use Guzzle\Http\Message\Request;
11
12
class DownloadSpec extends ObjectBehavior
13
{
14
    function let(Client $client, HttpClient $http)
15
    {
16
        $client->getHttpClient()->willReturn($http);
17
        $client->getProjectIdentifier()->willReturn('akeneo');
18
        $client->getProjectApiKey()->willReturn('1234');
19
        $this->beConstructedWith($client);
20
    }
21
22
    function it_should_be_an_api()
23
    {
24
        $this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi');
25
    }
26
27
    function it_has_a_package_with_all_languages()
28
    {
29
        $this->setPackage('all.zip');
30
        $this->getPackage()->shouldReturn('all.zip');
31
    }
32
33
    function it_has_a_package_with_one_language()
34
    {
35
        $this->setPackage('fr.zip');
36
        $this->getPackage()->shouldReturn('fr.zip');
37
    }
38
39
    function it_has_a_copy_destination()
40
    {
41
        $this->setCopyDestination('/tmp/');
42
        $this->getCopyDestination()->shouldReturn('/tmp/');
43
    }
44
45 View Code Duplication
    function it_downloads_all_translations(HttpClient $http, Request $request, Response $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...
46
    {
47
        $this->setCopyDestination('/tmp');
48
        $this->setPackage('all.zip');
49
        $http->get('project/akeneo/download/all.zip?key=1234')->willReturn($request);
50
        $request->setResponseBody('/tmp/all.zip')->willReturn($request);
51
        $request->send()->willReturn($response);
52
        $response->getBody(true)->willReturn('bin');
53
        $this->execute()->shouldBe('bin');
54
    }
55
56 View Code Duplication
    function it_downloads_french_translations(HttpClient $http, Request $request, Response $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...
57
    {
58
        $this->setCopyDestination('/tmp');
59
        $this->setPackage('fr.zip');
60
        $http->get('project/akeneo/download/fr.zip?key=1234')->willReturn($request);
61
        $request->setResponseBody('/tmp/fr.zip')->willReturn($request);
62
        $request->send()->willReturn($response);
63
        $response->getBody(true)->willReturn('bin');
64
        $this->execute()->shouldBe('bin');
65
    }
66
}
67