Directory::add()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 8
nc 4
nop 3
crap 3
1
<?php
2
/**
3
 * Crowdin API implementation in PHP.
4
 *
5
 * @copyright  Copyright (C) 2016 Nikolai Plath (elkuku)
6
 * @license    WTFPL - See license.txt
7
 */
8
9
namespace ElKuKu\Crowdin\Package;
10
11
use ElKuKu\Crowdin\Package;
12
13
use Psr\Http\Message\ResponseInterface;
14
15
/**
16
 * Class Directory
17
 *
18
 * @since  1.0.3
19
 */
20
Class Directory extends Package
21
{
22
	/**
23
	 * Add directory to Crowdin project.
24
	 *
25
	 * @param   string   $name      The name of the directory to add.
26
	 * @param   boolean  $isBranch  If set to 1 the directory will be marked as a version branch.
27
	 *                              Acceptable values are: 1 or 0.
28
	 * @param   string   $branch    The name of related version branch.
29
	 *
30
	 * @see https://crowdin.com/page/api/add-directory
31
	 * @since  1.0.3
32
	 *
33
	 * @return ResponseInterface
34
	 */
35 1 View Code Duplication
	public function add(string $name, bool $isBranch = false, string $branch = '') : ResponseInterface
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...
36
	{
37 1
		$parameters = ['name' => $name];
38
39 1
		if ($isBranch)
40
		{
41 1
			$parameters['is_branch'] = '1';
42
		}
43
44 1
		if ($branch)
45
		{
46 1
			$parameters['branch'] = $branch;
47
		}
48
49 1
		return $this->getHttpClient()
50 1
			->post($this->getBasePath('add-directory'), ['form_params' => $parameters]);
51
	}
52
53
	/**
54
	 * Rename directory or modify its attributes.
55
	 * When renaming directory the path can not be changed
56
	 * (it means new_name parameter can not contain path, name only).
57
	 *
58
	 * @param   string  $name           Full directory path that should be modified (e.g. /MainPage/AboutUs).
59
	 * @param   string  $newName        New directory name.
60
	 * @param   string  $title          New directory title to be displayed in Crowdin UI.
61
	 * @param   string  $exportPattern  New directory export pattern.
62
	 *                                  Is used to create directory name and path in resulted translations bundle.
63
	 * @param   string  $branch         The name of related version branch.
64
	 *
65
	 * @see   https://crowdin.com/page/api/change-directory
66
	 * @since 1.0.3
67
	 *
68
	 * @return ResponseInterface
69
	 */
70 1
	public function update(string $name, string $newName = '', string $title = '', string $exportPattern = '', string $branch = '') : ResponseInterface
71
	{
72 1
		$data = ['name' => $name];
73
74 1
		if ($newName)
75
		{
76 1
			$data['new_name'] = $newName;
77
		}
78
79 1
		if ($title)
80
		{
81 1
			$data['title'] = $title;
82
		}
83
84 1
		if ($exportPattern)
85
		{
86 1
			$data['export_pattern'] = $exportPattern;
87
		}
88
89 1
		if ($branch)
90
		{
91 1
			$data['branch'] = $branch;
92
		}
93
94 1
		return $this->getHttpClient()
95 1
			->post($this->getBasePath('change-directory'), ['form_params' => $data]);
96
	}
97
98
	/**
99
	 * Delete Crowdin project directory.
100
	 * All nested files and directories will be deleted too.
101
	 *
102
	 * @param   string  $name  The name of the directory to delete.
103
	 *
104
	 * @see   https://crowdin.com/page/api/delete-directory
105
	 * @since 1.0.3
106
	 *
107
	 * @return ResponseInterface
108
	 */
109 1
	public function delete(string $name) : ResponseInterface
110
	{
111 1
		return $this->getHttpClient()
112 1
			->post($this->getBasePath('delete-directory'), ['form_params' => ['name' => $name]]);
113
	}
114
}
115