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

AddDirectory::execute()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.5806
cc 4
eloc 15
nc 5
nop 0
1
<?php
2
3
namespace Akeneo\Crowdin\Api;
4
5
/**
6
 * Add a directory to the Crowdin project.
7
 *
8
 * @author Julien Janvier <[email protected]>
9
 * @see http://crowdin.net/page/api/add-directory
10
 */
11
class AddDirectory extends AbstractApi
12
{
13
    private $directory;
14
15
    private $isBranch = false;
16
17
    private $branch;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function execute()
23
    {
24
        if (null == $this->getDirectory()) {
25
            throw new \InvalidArgumentException('There is no directory to create.');
26
        }
27
28
        $path = sprintf(
29
            "project/%s/add-directory?key=%s",
30
            $this->client->getProjectIdentifier(),
31
            $this->client->getProjectApiKey()
32
        );
33
34
        $parameters = array_merge($this->parameters, array('name' => $this->getDirectory()));
35
        if ($this->getIsBranch()) {
36
            $parameters['is_branch'] = '1';
37
        }
38
        if (null !== $this->getBranch()) {
39
            $parameters['branch'] = $this->getBranch();
40
        }
41
42
        $request  = $this->client->getHttpClient()->post($path, array(), $parameters);
43
44
        $response = $request->send();
45
46
        return $response->getBody(true);
47
    }
48
49
    /**
50
     * @param mixed $directory
51
     */
52
    public function setDirectory($directory)
53
    {
54
        $this->directory = $directory;
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60
    public function getDirectory()
61
    {
62
        return $this->directory;
63
    }
64
65
    /**
66
     * @param bool $isBranch
67
     */
68
    public function setIsBranch($isBranch)
69
    {
70
        $this->isBranch = $isBranch;
71
    }
72
73
    /**
74
     * @return bool
75
     */
76
    public function getIsBranch()
77
    {
78
        return $this->isBranch;
79
    }
80
81
    /**
82
     * @param string $branch
83
     */
84
    public function setBranch($branch)
85
    {
86
        $this->branch = $branch;
87
    }
88
89
    /**
90
     * @return string|null
91
     */
92
    public function getBranch()
93
    {
94
        return $this->branch;
95
    }
96
}
97