Completed
Push — fix-checkstyle ( 525678...700890 )
by
unknown
03:06
created

AddDirectory::execute()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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