This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\ |
||
12 | { |
||
13 | Package, Languagefile |
||
14 | }; |
||
15 | |||
16 | use Psr\Http\Message\ResponseInterface; |
||
17 | |||
18 | /** |
||
19 | * Class File |
||
20 | * |
||
21 | * @since 1.0 |
||
22 | */ |
||
23 | Class File extends Package |
||
24 | { |
||
25 | /** |
||
26 | * Add new file to Crowdin project. |
||
27 | * |
||
28 | * @param Languagefile $languagefile The translation file object |
||
29 | * @param string $type The type. |
||
30 | * @param string $branch The branch. |
||
31 | * |
||
32 | * @see https://crowdin.com/page/api/add-file |
||
33 | * @since 1.0 |
||
34 | * |
||
35 | * @return ResponseInterface |
||
36 | */ |
||
37 | 1 | public function add(Languagefile $languagefile, string $type = '', string $branch = '') : ResponseInterface |
|
38 | { |
||
39 | 1 | $data = []; |
|
40 | |||
41 | 1 | if ($type) |
|
42 | { |
||
43 | 1 | $data[] = [ |
|
44 | 1 | 'name' => 'type', |
|
45 | 1 | 'contents' => $type |
|
46 | ]; |
||
47 | } |
||
48 | |||
49 | 1 | if ($branch) |
|
50 | { |
||
51 | 1 | $data[] = [ |
|
52 | 1 | 'name' => 'branch', |
|
53 | 1 | 'contents' => $branch |
|
54 | ]; |
||
55 | } |
||
56 | |||
57 | 1 | $data = $this->processLanguageFile($data, $languagefile); |
|
58 | |||
59 | 1 | return $this->getHttpClient() |
|
60 | 1 | ->post($this->getBasePath('add-file'), ['multipart' => $data]); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Upload latest version of your localization file to Crowdin. |
||
65 | * |
||
66 | * @param Languagefile $languagefile The translation file object |
||
67 | * @param string $branch The branch. |
||
68 | * |
||
69 | * @see https://crowdin.com/page/api/update-file |
||
70 | * @since 1.0 |
||
71 | * |
||
72 | * @return ResponseInterface |
||
73 | */ |
||
74 | 1 | View Code Duplication | public function update(Languagefile $languagefile, $branch = '') : ResponseInterface |
0 ignored issues
–
show
|
|||
75 | { |
||
76 | 1 | $data = []; |
|
77 | |||
78 | 1 | if ($branch) |
|
79 | { |
||
80 | 1 | $data[] = [ |
|
81 | 1 | 'name' => 'branch', |
|
82 | 1 | 'contents' => $branch |
|
83 | ]; |
||
84 | } |
||
85 | |||
86 | 1 | $data = $this->processLanguageFile($data, $languagefile); |
|
87 | |||
88 | 1 | return $this->getHttpClient() |
|
89 | 1 | ->post($this->getBasePath('update-file'), ['multipart' => $data]); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Delete file from Crowdin project. All the translations will be lost without ability to restore them. |
||
94 | * |
||
95 | * @param Languagefile $file The file to delete. |
||
96 | * |
||
97 | * @see https://crowdin.com/page/api/delete-file |
||
98 | * @since 1.0 |
||
99 | * |
||
100 | * @return ResponseInterface |
||
101 | */ |
||
102 | 1 | public function delete(Languagefile $file) : ResponseInterface |
|
103 | { |
||
104 | 1 | return $this->getHttpClient() |
|
105 | 1 | ->post($this->getBasePath('delete-file'), ['form_params' => ['file' => $file->getCrowdinPath()]]); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * This method exports single translated files from Crowdin. |
||
110 | * Additionally, it can be applied to export XLIFF files for offline localization. (@todo) |
||
111 | * |
||
112 | * @param string $file The file name. |
||
113 | * @param string $language The language tag. |
||
114 | * @param string $toPath Export to path. |
||
115 | * |
||
116 | * @see https://crowdin.com/page/api/export-file |
||
117 | * @since 1.0 |
||
118 | * |
||
119 | * @return ResponseInterface |
||
120 | */ |
||
121 | 1 | public function export(string $file, string $language, string $toPath) : ResponseInterface |
|
122 | { |
||
123 | 1 | $path = sprintf( |
|
124 | 1 | '%s&file=%s&language=%s', |
|
125 | 1 | $this->getBasePath('export-file'), |
|
126 | 1 | $file, |
|
127 | 1 | $language |
|
128 | ); |
||
129 | |||
130 | 1 | return $this->getHttpClient() |
|
131 | 1 | ->get($path, ['sink' => $toPath]); |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Process a language file. |
||
136 | * |
||
137 | * @param array $data Data array. |
||
138 | * @param Languagefile $languagefile The language file object. |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | 1 | private function processLanguageFile(array $data, Languagefile $languagefile) : array |
|
143 | { |
||
144 | 1 | $data[] = [ |
|
145 | 1 | 'name' => 'files[' . $languagefile->getCrowdinPath() . ']', |
|
146 | 1 | 'contents' => fopen($languagefile->getLocalPath(), 'r') |
|
147 | ]; |
||
148 | |||
149 | 1 | if ($languagefile->getTitle()) |
|
150 | { |
||
151 | 1 | $data[] = [ |
|
152 | 1 | 'name' => 'titles[' . $languagefile->getCrowdinPath() . ']', |
|
153 | 1 | 'contents' => $languagefile->getTitle() |
|
154 | ]; |
||
155 | } |
||
156 | |||
157 | 1 | if ($languagefile->getExportPattern()) |
|
158 | { |
||
159 | 1 | $data[] = [ |
|
160 | 1 | 'name' => 'export_patterns[' . $languagefile->getCrowdinPath() . ']', |
|
161 | 1 | 'contents' => $languagefile->getExportPattern() |
|
162 | ]; |
||
163 | } |
||
164 | |||
165 | 1 | return $data; |
|
166 | } |
||
167 | } |
||
168 |
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.