1 | <?php |
||
2 | /* |
||
3 | * The MIT License |
||
4 | * |
||
5 | * Copyright 2016 BCL Technologies. |
||
6 | * |
||
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
8 | * of this software and associated documentation files (the "Software"), to deal |
||
9 | * in the Software without restriction, including without limitation the rights |
||
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
11 | * copies of the Software, and to permit persons to whom the Software is |
||
12 | * furnished to do so, subject to the following conditions: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice shall be included in |
||
15 | * all copies or substantial portions of the Software. |
||
16 | * |
||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
23 | * THE SOFTWARE. |
||
24 | */ |
||
25 | |||
26 | namespace Bcl\EasyPdfCloud; |
||
27 | |||
28 | use InvalidArgumentException; |
||
29 | use function is_file; |
||
30 | use function basename; |
||
31 | use function file_get_contents; |
||
32 | |||
33 | class RestApi |
||
34 | { |
||
35 | /** |
||
36 | * @var RestApiImpl |
||
37 | */ |
||
38 | private $impl; |
||
39 | |||
40 | public function __construct($clientId, $clientSecret, IOAuth2TokenManager $tokenManager = null, UrlInfo $urlInfo = null) |
||
41 | { |
||
42 | $this->impl = new RestApiImpl($clientId, $clientSecret, $tokenManager, $urlInfo); |
||
43 | } |
||
44 | |||
45 | // GET: /workflows |
||
46 | public function getWorkflowInfoList() |
||
47 | { |
||
48 | return $this->impl->getWorkflowInfoList(true); |
||
49 | } |
||
50 | |||
51 | // GET: /workflows/{id} |
||
52 | public function getWorkflowInfo($workflowId) |
||
53 | { |
||
54 | $this->impl->validateWorkflowId($workflowId); |
||
55 | |||
56 | return $this->impl->getWorkflowInfo($workflowId, true); |
||
57 | } |
||
58 | |||
59 | // PUT: /workflows/{id}/job |
||
60 | public function createNewJobWithFilePath($workflowId, $filePath, $start, $test) |
||
61 | { |
||
62 | $this->impl->validateWorkflowId($workflowId); |
||
63 | |||
64 | $this->validateFilePath($filePath); |
||
65 | |||
66 | $fileName = basename($filePath); |
||
67 | |||
68 | $fileContents = $this->getFileContents($filePath); |
||
69 | |||
70 | return $this->impl->createNewJobWithFileContents($workflowId, $fileContents, $fileName, $start, $test, true); |
||
71 | } |
||
72 | |||
73 | // PUT: /workflows/{id}/job |
||
74 | public function createNewJobWithFilePathAndName($workflowId, $filePath, $fileName, $start, $test) |
||
75 | { |
||
76 | $this->impl->validateWorkflowId($workflowId); |
||
77 | |||
78 | $this->validateFilePath($filePath); |
||
79 | $this->validateFileName($fileName); |
||
80 | |||
81 | $fileContents = $this->getFileContents($filePath); |
||
82 | |||
83 | return $this->impl->createNewJobWithFileContents($workflowId, $fileContents, $fileName, $start, $test, true); |
||
84 | } |
||
85 | |||
86 | // PUT: /workflows/{id}/job |
||
87 | public function createNewJobWithFileContents($workflowId, $fileContents, $fileName, $start, $test) |
||
88 | { |
||
89 | $this->impl->validateWorkflowId($workflowId); |
||
90 | |||
91 | $this->validateInputFile($fileContents); |
||
92 | $this->validateFileName($fileName); |
||
93 | |||
94 | return $this->impl->createNewJobWithFileContents($workflowId, $fileContents, $fileName, $start, $test, true); |
||
95 | } |
||
96 | |||
97 | // PUT: /jobs/{id} |
||
98 | public function uploadInputWithFilePath($jobId, $filePath) |
||
99 | { |
||
100 | $this->impl->validateJobId($jobId); |
||
101 | |||
102 | $this->validateFilePath($filePath); |
||
103 | |||
104 | $fileName = basename($filePath); |
||
105 | |||
106 | $fileContents = $this->getFileContents($filePath); |
||
107 | |||
108 | return $this->impl->uploadInputWithFileContents($jobId, $fileContents, $fileName, true); |
||
0 ignored issues
–
show
|
|||
109 | } |
||
110 | |||
111 | // PUT: /jobs/{id} |
||
112 | public function uploadInputWithFilePathAndName($jobId, $filePath, $fileName) |
||
113 | { |
||
114 | $this->impl->validateJobId($jobId); |
||
115 | |||
116 | $this->validateFilePath($filePath); |
||
117 | $this->validateFileName($fileName); |
||
118 | |||
119 | $fileContents = $this->getFileContents($filePath); |
||
120 | |||
121 | return $this->impl->uploadInputWithFileContents($jobId, $fileContents, $fileName, true); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->impl->uploadInput...tents, $fileName, true) targeting Bcl\EasyPdfCloud\RestApi...InputWithFileContents() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
122 | } |
||
123 | |||
124 | // PUT: /jobs/{id}/<filename> |
||
125 | public function uploadInputWithFileContents($jobId, $fileContents, $fileName) |
||
126 | { |
||
127 | $this->impl->validateJobId($jobId); |
||
128 | |||
129 | $this->validateInputFile($fileContents); |
||
130 | $this->validateFileName($fileName); |
||
131 | |||
132 | return $this->impl->uploadInputWithFileContents($jobId, $fileContents, $fileName, true); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->impl->uploadInput...tents, $fileName, true) targeting Bcl\EasyPdfCloud\RestApi...InputWithFileContents() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
133 | } |
||
134 | |||
135 | // GET: /jobs/{id}/output?type=metadata |
||
136 | public function getOutputInfo($jobId) |
||
137 | { |
||
138 | $this->impl->validateJobId($jobId); |
||
139 | |||
140 | return $this->impl->getOutputInfoForFileName($jobId, null, true); |
||
141 | } |
||
142 | |||
143 | // GET: /jobs/{id}/output/<filename>?type=metadata |
||
144 | public function getOutputInfoForFileName($jobId, $fileName) |
||
145 | { |
||
146 | $this->impl->validateJobId($jobId); |
||
147 | |||
148 | $this->validateFileName($fileName); |
||
149 | |||
150 | return $this->impl->getOutputInfoForFileName($jobId, $fileName, true); |
||
151 | } |
||
152 | |||
153 | // GET: /jobs/{id}/output?type=file |
||
154 | public function downloadOutput($jobId) |
||
155 | { |
||
156 | $this->impl->validateJobId($jobId); |
||
157 | |||
158 | return $this->impl->downloadOutputForFileName($jobId, null, true); |
||
159 | } |
||
160 | |||
161 | // GET: /jobs/{id}/output/<filename>?type=file |
||
162 | public function downloadOutputForFileName($jobId, $fileName) |
||
163 | { |
||
164 | $this->impl->validateJobId($jobId); |
||
165 | |||
166 | $this->validateFileName($fileName); |
||
167 | |||
168 | return $this->impl->downloadOutputForFileName($jobId, $fileName, true); |
||
169 | } |
||
170 | |||
171 | // GET: /jobs/{id} |
||
172 | public function getJobInfo($jobId) |
||
173 | { |
||
174 | $this->impl->validateJobId($jobId); |
||
175 | |||
176 | return $this->impl->getJobInfo($jobId, true); |
||
177 | } |
||
178 | |||
179 | // POST: /jobs/{id}?operation=start |
||
180 | public function startJob($jobId) |
||
181 | { |
||
182 | $this->impl->validateJobId($jobId); |
||
183 | |||
184 | $this->impl->startOrStopJob($jobId, true, true); |
||
185 | } |
||
186 | |||
187 | // POST: /jobs/{id}?operation=stop |
||
188 | public function stopJob($jobId) |
||
189 | { |
||
190 | $this->impl->validateJobId($jobId); |
||
191 | |||
192 | $this->impl->startOrStopJob($jobId, false, true); |
||
193 | } |
||
194 | |||
195 | // POST: /jobs/{id}?operation=stop |
||
196 | public function deleteJob($jobId) |
||
197 | { |
||
198 | $this->impl->validateJobId($jobId); |
||
199 | |||
200 | $this->impl->deleteJob($jobId, true); |
||
201 | } |
||
202 | |||
203 | // POST: /jobs/{id}/event |
||
204 | public function waitForJobEvent($jobId) |
||
205 | { |
||
206 | $this->impl->validateJobId($jobId); |
||
207 | |||
208 | return $this->impl->waitForJobEvent($jobId, true); |
||
209 | } |
||
210 | |||
211 | protected function validateFilePath($filePath) |
||
212 | { |
||
213 | if (StringUtils::isEmpty($filePath)) { |
||
214 | throw new InvalidArgumentException('Input file is not specified'); |
||
215 | } |
||
216 | |||
217 | if (false === is_file($filePath)) { |
||
218 | throw new InvalidArgumentException('Input file does not exist'); |
||
219 | } |
||
220 | } |
||
221 | |||
222 | protected function validateFileName($fileName) |
||
223 | { |
||
224 | if (StringUtils::isEmpty($fileName)) { |
||
225 | throw new InvalidArgumentException('File name is not specified'); |
||
226 | } |
||
227 | } |
||
228 | |||
229 | protected function getFileContents($filePath) |
||
230 | { |
||
231 | $fileContents = file_get_contents($filePath); |
||
232 | if (false === $fileContents) { |
||
233 | throw new InvalidArgumentException('Unable to open input file'); |
||
234 | } |
||
235 | |||
236 | return $fileContents; |
||
237 | } |
||
238 | |||
239 | protected function validateInputFile($fileContents) |
||
240 | { |
||
241 | if (null === $fileContents || false === $fileContents) { |
||
242 | throw new InvalidArgumentException('Input file is not specified'); |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.