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

Import   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 31
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A import() 0 15 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\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