Skip to content

Commit df5ede4

Browse files
[Documentation] Stub phpDoc added
1 parent fc1cac7 commit df5ede4

File tree

3 files changed

+137
-3
lines changed

3 files changed

+137
-3
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# php-api-client-forge
2-
Create restful API client in PHP
2+
Create restful API client in PHP with least code
3+
4+
5+

src/support/forge/api/Client.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class Client
3636
protected $options;
3737
protected $rootPath;
3838

39+
/**
40+
* Client constructor.
41+
*
42+
* @param array $config
43+
*/
3944
public function __construct($config = [])
4045
{
4146
$this->setOptions($config);
@@ -50,6 +55,11 @@ public function __construct($config = [])
5055

5156
}
5257

58+
/**
59+
* @param array $options
60+
*
61+
* @return $this
62+
*/
5363
public function setOptions($options = [])
5464
{
5565
$myProperties = get_class_vars(__CLASS__);
@@ -68,6 +78,12 @@ public function setOptions($options = [])
6878
return $this;
6979
}
7080

81+
/**
82+
* @param $options
83+
* @param array $rootOption
84+
*
85+
* @return array|mixed
86+
*/
7187
protected function parseOptions($options, $rootOption = [])
7288
{
7389

@@ -91,6 +107,11 @@ protected function parseOptions($options, $rootOption = [])
91107

92108
}
93109

110+
/**
111+
* @param array $descriptionOptions
112+
*
113+
* @return $this
114+
*/
94115
public function setDescription($descriptionOptions = [])
95116
{
96117

@@ -129,12 +150,22 @@ public function setDescription($descriptionOptions = [])
129150
return $this;
130151
}
131152

153+
/**
154+
* @param array $clientOptions
155+
*
156+
* @return $this
157+
*/
132158
public function createClient($clientOptions = [])
133159
{
134160
$this->client = new GHClient($clientOptions);
135161
return $this;
136162
}
137163

164+
/**
165+
* @param array $clientOptions
166+
*
167+
* @return $this
168+
*/
138169
protected function setClient($clientOptions = [])
139170
{
140171

@@ -144,6 +175,12 @@ protected function setClient($clientOptions = [])
144175
return $this;
145176
}
146177

178+
/**
179+
* @param $name
180+
* @param $arguments
181+
*
182+
* @return mixed
183+
*/
147184
public function __call($name, $arguments)
148185
{
149186
$api = $this->consumer;
@@ -154,6 +191,13 @@ public function __call($name, $arguments)
154191
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s().', get_called_class(), $name));
155192
}
156193

194+
/**
195+
* @param string $source
196+
* @param string $destination
197+
* @param array $options
198+
*
199+
* @return bool|int
200+
*/
157201
public function importApi($source = '', $destination = '', $options = [])
158202
{
159203
if (empty($source)) {
@@ -177,9 +221,17 @@ protected function getAllOptions() {
177221
];
178222
}
179223

224+
/**
225+
* @return string
226+
* @throws \ReflectionException
227+
*/
180228
private function getChildDir() {
181229
return dirname((new \ReflectionClass(static::class))->getFileName());
182230
}
231+
232+
/**
233+
* @return string
234+
*/
183235
private function getDir() {
184236
return __DIR__;
185237
}

src/support/forge/api/Import.php

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class Import
2222
protected $DEFAULT_API_JSON_PATH = './config/api.json';
2323
protected $DEFAULT_SOURCE_JSON_PATH = './config/postman.json';
2424

25+
/**
26+
* Import constructor.
27+
*
28+
* @param string $filePath Path containing source (Postman generated) json file
29+
* @param array $options
30+
*
31+
* @throws \ReflectionException
32+
*/
2533
public function __construct($filePath = '', $options = [])
2634
{
2735

@@ -50,6 +58,11 @@ public function __construct($filePath = '', $options = [])
5058
$this->options = $options;
5159
}
5260

61+
/**
62+
* @param $filePath Path containing source (Postman generated) json file
63+
*
64+
* @return array
65+
*/
5366
protected function importFromJson($filePath)
5467
{
5568

@@ -111,6 +124,11 @@ protected function importFromJson($filePath)
111124
return $data;
112125
}
113126

127+
/**
128+
* @param array $request
129+
*
130+
* @return array
131+
*/
114132
protected function parseOperation($request = [])
115133
{
116134
$meta = [$request];
@@ -128,6 +146,13 @@ protected function parseOperation($request = [])
128146

129147
}
130148

149+
/**
150+
* @param array $paths
151+
* @param string $bodyRaw
152+
* @param array $meta
153+
*
154+
* @return array
155+
*/
131156
protected function parseParams($paths = [], $bodyRaw = '', $meta = [])
132157
{
133158
$params = [];
@@ -164,11 +189,22 @@ protected function parseParams($paths = [], $bodyRaw = '', $meta = [])
164189

165190
}
166191

192+
/**
193+
* @param $url
194+
* @param array $meta
195+
*
196+
* @return string
197+
*/
167198
protected function parseUri($url, $meta = [])
168199
{
169200
return implode('/', array_slice($url['path'], 2));
170201
}
171202

203+
/**
204+
* @param $api
205+
*
206+
* @return string
207+
*/
172208
protected function parseApiName($api)
173209
{
174210

@@ -207,6 +243,13 @@ protected function parseApiName($api)
207243

208244
}
209245

246+
/**
247+
* @param $operation
248+
* @param array $api
249+
* @param string $method
250+
*
251+
* @return array
252+
*/
210253
protected function generateDocs($operation, $api = [], $method = '') {
211254

212255
// $baseUri = $this->clientOptions['base_url'] ?: '';
@@ -251,6 +294,11 @@ protected function generateMethod($apiName, $operation = [], $api = []) {
251294

252295
}
253296

297+
/**
298+
* @param string $string
299+
*
300+
* @return string
301+
*/
254302
protected function sluggify($string = '')
255303
{
256304
if (!empty($string)) {
@@ -261,22 +309,36 @@ protected function sluggify($string = '')
261309
return $string;
262310
}
263311

264-
312+
/**
313+
* @return array
314+
*/
265315
public function getData()
266316
{
267317
return $this->data;
268318
}
269319

320+
/**
321+
* @return array
322+
*/
270323
public function getDocs()
271324
{
272325
return $this->docsData;
273326
}
274327

328+
/**
329+
* @return array
330+
*/
275331
public function getMethods()
276332
{
277333
return $this->methodData;
278334
}
279335

336+
/**
337+
* @param string $path
338+
* @param array $options
339+
*
340+
* @return bool|int
341+
*/
280342
public function writeData($path = '', $options = [])
281343
{
282344
if (empty($path)) {
@@ -300,7 +362,11 @@ public function writeData($path = '', $options = [])
300362
return file_put_contents($path, $json);
301363
}
302364

303-
365+
/**
366+
* @param string $path
367+
*
368+
* @return bool|int
369+
*/
304370
protected function writeMDDocs($path = '') {
305371

306372
if (empty($path)) {
@@ -347,6 +413,11 @@ protected function writeMDDocs($path = '') {
347413
return file_put_contents($path, $mdText);
348414
}
349415

416+
/**
417+
* @param string $path
418+
*
419+
* @return bool|int
420+
*/
350421
protected function writeMethods($path = '') {
351422

352423
if (empty($path)) {
@@ -367,9 +438,17 @@ protected function writeMethods($path = '') {
367438
return file_put_contents($path, $methodText);
368439
}
369440

441+
/**
442+
* @return string
443+
* @throws \ReflectionException
444+
*/
370445
private function getChildDir() {
371446
return dirname((new \ReflectionClass(static::class))->getFileName());
372447
}
448+
449+
/**
450+
* @return string
451+
*/
373452
private function getDir() {
374453
return __DIR__;
375454
}

0 commit comments

Comments
 (0)