AddDirectory::setBranch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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 https://crowdin.com/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
        $this->addUrlParameter('key', $this->client->getProjectApiKey());
34
35
        $path = sprintf(
36
            "project/%s/add-directory?%s",
37
            $this->client->getProjectIdentifier(),
38
            $this->getUrlQueryString()
39
        );
40
41
        $parameters = ['name' => $this->directory];
42
        if ($this->isBranch) {
43
            $parameters['is_branch'] = '1';
44
        }
45
        if (null !== $this->branch) {
46
            $parameters['branch'] = $this->branch;
47
        }
48
49
        $data = ['form_params' => $parameters];
50
        $response = $this->client->getHttpClient()->post($path, $data);
51
52
        return $response->getBody();
53
    }
54
55
    /**
56
     * @param mixed $directory
57
     */
58
    public function setDirectory($directory)
59
    {
60
        $this->directory = $directory;
61
    }
62
63
    /**
64
     * @return mixed
65
     */
66
    public function getDirectory()
67
    {
68
        return $this->directory;
69
    }
70
71
    /**
72
     * @param bool $isBranch
73
     */
74
    public function setIsBranch($isBranch)
75
    {
76
        $this->isBranch = $isBranch;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    public function getIsBranch()
83
    {
84
        return $this->isBranch;
85
    }
86
87
    /**
88
     * @param string $branch
89
     */
90
    public function setBranch($branch)
91
    {
92
        $this->branch = $branch;
93
    }
94
95
    /**
96
     * @return string|null
97
     */
98
    public function getBranch()
99
    {
100
        return $this->branch;
101
    }
102
}
103