1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
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\PhraseApp\Api; |
11
|
|
|
|
12
|
|
|
use FAPI\PhraseApp\Model\Key\KeyCreated; |
13
|
|
|
use FAPI\PhraseApp\Model\Key\KeySearchResults; |
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Sascha-Oliver Prolic <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Key extends HttpApi |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Create a new key. |
23
|
|
|
* |
24
|
|
|
* @param string $projectKey |
25
|
|
|
* @param string $localeId |
|
|
|
|
26
|
|
|
* @param array $params |
27
|
|
|
* |
28
|
|
|
* @return mixed|ResponseInterface |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public function create(string $projectKey, string $name, array $params = []) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$params['name'] = $name; |
33
|
|
|
|
34
|
|
|
$response = $this->httpPost(sprintf('/api/v2/projects/%s/keys', $projectKey), $params); |
35
|
|
|
|
36
|
|
|
if (!$this->hydrator) { |
37
|
|
|
return $response; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { |
41
|
|
|
$this->handleErrors($response); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->hydrator->hydrate($response, KeyCreated::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Search keys. |
49
|
|
|
* |
50
|
|
|
* @param string $projectKey |
51
|
|
|
* @param string $localeId |
52
|
|
|
* @param array $params |
53
|
|
|
* |
54
|
|
|
* @return mixed|ResponseInterface |
55
|
|
|
*/ |
56
|
|
|
public function search(string $projectKey, string $localeId, array $params = []) |
57
|
|
|
{ |
58
|
|
|
$q = ''; |
59
|
|
|
|
60
|
|
|
if (isset($params['tags'])) { |
61
|
|
|
$q .= 'tags:'.$params['tags'].' '; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (isset($params['name'])) { |
65
|
|
|
$q .= 'name:'.$params['name'].' '; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (isset($params['ids'])) { |
69
|
|
|
$q .= 'ids:'.$params['ids'].' '; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$params = [ |
73
|
|
|
'locale_id' => $localeId, |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
if (!empty($q)) { |
77
|
|
|
$params['q'] = $q; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$response = $this->httpPost(sprintf('/api/v2/projects/%s/keys/search', $projectKey), $params); |
81
|
|
|
|
82
|
|
|
if (!$this->hydrator) { |
83
|
|
|
return $response; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { |
87
|
|
|
$this->handleErrors($response); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $this->hydrator->hydrate($response, KeySearchResults::class); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Delete a key. |
95
|
|
|
* |
96
|
|
|
* @param string $projectKey |
97
|
|
|
* @param string $keyId |
98
|
|
|
* |
99
|
|
|
* @return bool|ResponseInterface |
100
|
|
|
*/ |
101
|
|
|
public function delete(string $projectKey, string $keyId) |
102
|
|
|
{ |
103
|
|
|
$response = $this->httpDelete(sprintf('/api/v2/projects/%s/keys/%s', $projectKey, $keyId)); |
104
|
|
|
|
105
|
|
|
if ($response->getStatusCode() !== 204) { |
106
|
|
|
$this->handleErrors($response); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return true; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.