1 | <?php |
||
15 | class UploadTranslation extends AbstractApi |
||
16 | { |
||
17 | /** @var FileReader */ |
||
18 | protected $fileReader; |
||
19 | |||
20 | /** @var array */ |
||
21 | protected $translations; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $locale; |
||
25 | |||
26 | /** @var bool */ |
||
27 | protected $areDuplicatesImported = false; |
||
28 | |||
29 | /** @var bool */ |
||
30 | protected $areEqualSuggestionsImported = false; |
||
31 | |||
32 | /** @var bool */ |
||
33 | protected $areImportsAutoApproved = false; |
||
34 | |||
35 | /** |
||
36 | * @param Client $client |
||
37 | * @param FileReader $fileReader |
||
38 | */ |
||
39 | public function __construct(Client $client, FileReader $fileReader) |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function execute() |
||
93 | |||
94 | /** |
||
95 | * @param string $crowdinPath the Crowdin file path |
||
96 | * @param string $localPath the local file path |
||
97 | * |
||
98 | * @throws InvalidArgumentException |
||
99 | * |
||
100 | * @return UploadTranslation |
||
101 | */ |
||
102 | public function addTranslation($crowdinPath, $localPath) |
||
111 | |||
112 | /** |
||
113 | * @return array |
||
114 | */ |
||
115 | public function getTranslations() |
||
119 | |||
120 | /** |
||
121 | * @param bool $importsAutoApproved |
||
122 | * |
||
123 | * @throws InvalidArgumentException |
||
124 | * |
||
125 | * @return UploadTranslation |
||
126 | */ |
||
127 | public function setImportsAutoApproved($importsAutoApproved) |
||
137 | |||
138 | /** |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function areImportsAutoApproved() |
||
145 | |||
146 | /** |
||
147 | * @param bool $duplicatesImported |
||
148 | * |
||
149 | * @throws InvalidArgumentException |
||
150 | * |
||
151 | * @return UploadTranslation |
||
152 | */ |
||
153 | public function setDuplicatesImported($duplicatesImported) |
||
163 | |||
164 | /** |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function areDuplicatesImported() |
||
171 | |||
172 | /** |
||
173 | * @param bool $equalSuggestionsImported |
||
174 | * |
||
175 | * @throws InvalidArgumentException |
||
176 | * |
||
177 | * @return UploadTranslation |
||
178 | */ |
||
179 | public function setEqualSuggestionsImported($equalSuggestionsImported) |
||
189 | |||
190 | /** |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function areEqualSuggestionsImported() |
||
197 | |||
198 | /** |
||
199 | * @param string $locale |
||
200 | * |
||
201 | * @return UploadTranslation |
||
202 | */ |
||
203 | public function setLocale($locale) |
||
209 | |||
210 | /** |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getLocale() |
||
217 | } |
||
218 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.