Completed
Push — master ( c28851...781c6a )
by Tobias
02:28
created

Import::import()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 4
crap 20
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\Resource\Api\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)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
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 ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) {
44
            $this->handleErrors($response);
45
        }
46
47
        return $this->hydrator->hydrate($response, Imported::class);
48
    }
49
}
50