Completed
Push — master ( eb5568...bc1b58 )
by Nicolas
9s
created

Download   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 89
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 2
A setPackage() 0 6 1
A getPackage() 0 4 1
A setCopyDestination() 0 6 1
A getCopyDestination() 0 4 1
A getBranch() 0 4 1
A setBranch() 0 4 1
1
<?php
2
3
namespace Akeneo\Crowdin\Api;
4
5
/**
6
 * Download ZIP file with translations (all or chosen language)
7
 *
8
 * @author Nicolas Dupont <[email protected]>
9
 * @see http://crowdin.net/page/api/download
10
 */
11
class Download extends AbstractApi
12
{
13
    /** @var string $package */
14
    protected $package = 'all.zip';
15
16
    /** @var string $copyDestination */
17
    protected $copyDestination = '/tmp';
18
19
    /** @var string */
20
    protected $branch;
21
22
    /**
23
     * @return mixed
24
     */
25
    public function execute()
26
    {
27
        $path = sprintf(
28
            "project/%s/download/%s?key=%s",
29
            $this->client->getProjectIdentifier(),
30
            $this->getPackage(),
31
            $this->client->getProjectApiKey()
32
        );
33
        if (null !== $this->branch) {
34
            $path = sprintf('%s&branch=%s', $path, $this->branch);
35
        }
36
        $request = $this->client->getHttpClient()->get($path);
37
        $response = $request
38
            ->setResponseBody($this->copyDestination.DIRECTORY_SEPARATOR.$this->getPackage())
39
            ->send();
40
41
        return $response->getBody(true);
42
    }
43
44
    /**
45
     * @param string $package
46
     *
47
     * @return Download
48
     */
49
    public function setPackage($package)
50
    {
51
        $this->package = $package;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getPackage()
60
    {
61
        return $this->package;
62
    }
63
64
    /**
65
     * @param string $dest
66
     *
67
     * @return Download
68
     */
69
    public function setCopyDestination($dest)
70
    {
71
        $this->copyDestination = $dest;
72
73
        return $this;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getCopyDestination()
80
    {
81
        return $this->copyDestination;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getBranch()
88
    {
89
        return $this->branch;
90
    }
91
92
    /**
93
     * @param string $branch
94
     */
95
    public function setBranch($branch)
96
    {
97
        $this->branch = $branch;
98
    }
99
}
100