Import   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 11
cp 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A import() 0 14 4
1
<?php
2
3
/*
4
 *
5
 *
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license.  See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Localise\Api;
11
12
use FAPI\Localise\Model\Import\Imported;
13
use Psr\Http\Message\ResponseInterface;
14
use FAPI\Localise\Exception;
15
16
/**
17
 * @author Tobias Nyholm <[email protected]>
18
 */
19
class Import extends HttpApi
20
{
21
    /**
22
     * Export a locale.
23
     * {@link https://localise.biz/api/docs/export/exportlocale}.
24
     *
25
     * @param string $projectKey
26
     * @param string $ext
27
     * @param string $body
28
     * @param array  $params
29
     *
30
     * @return string|ResponseInterface
31
     *
32
     * @throws Exception
33
     */
34
    public function import(string $projectKey, string $ext, string $body, array $params)
35
    {
36
        $params['key'] = $projectKey;
37
        $response = $this->httpPostRaw(sprintf('/api/import/%s?%s', $ext, http_build_query($params)), $body);
38
39
        if (!$this->hydrator) {
40
            return $response;
41
        }
42
43
        if (200 !== $response->getStatusCode() && 201 !== $response->getStatusCode()) {
44
            $this->handleErrors($response);
45
        }
46
47
        return $this->hydrator->hydrate($response, Imported::class);
48
    }
49
}
50