Skip to content

Commit aa58840

Browse files
committed
Fix lint errors
Add composer license Add Errors response class
1 parent 6350981 commit aa58840

File tree

8 files changed

+68
-29
lines changed

8 files changed

+68
-29
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "phramework/jsonapi-client",
33
"homepage": "https://phramework.github.io/",
4+
"license": "Apache-2.0",
45
"authors": [
56
{
67
"name": "Xenofon Spafaridis",
@@ -39,6 +40,6 @@
3940
"find tests/ -name '*.php' -print0 | xargs -0 -L 1 php -l",
4041
"phpunit"
4142
],
42-
"lint": "php ./vendor/bin/phpcs -p -s --standard=RSR2 ./src ./public ./queued"
43+
"lint": "php ./vendor/bin/phpcs -p -s --standard=PSR2 ./src ./tests/src"
4344
}
4445
}

src/Client.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ public static function post(
310310
public static function patch(
311311
string $id,
312312
\stdClass $attributes = null,
313-
\stdClass $relationships = null)
314-
{
313+
\stdClass $relationships = null
314+
) {
315315

316316
}
317317

@@ -328,11 +328,10 @@ public static function request(
328328
string $url,
329329
string $method = self::METHOD_GET,
330330
\stdClass $headers = null,
331-
$data = NULL,
331+
$data = null,
332332
$flags = self::REQUEST_EMPTY_FLAG,
333333
//$accept = 'application/json',
334-
$encoding = NULL
335-
334+
$encoding = null
336335
) {
337336
//Extract flags
338337
//Is the request binary
@@ -366,7 +365,7 @@ public static function request(
366365

367366
curl_setopt($handle, CURLOPT_URL, $url);
368367
curl_setopt($handle, CURLOPT_HTTPHEADER, $headersArray);
369-
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
368+
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
370369
curl_setopt($handle, CURLOPT_HEADER, true);
371370

372371
//Set timeout values ( in seconds )
@@ -375,11 +374,11 @@ public static function request(
375374
curl_setopt($handle, CURLOPT_NOSIGNAL, 1);
376375
//Security options
377376
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
378-
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
377+
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
379378

380379
/*//On binary transfers
381380
if ($binary) {
382-
curl_setopt($handle, CURLOPT_BINARYTRANSFER, TRUE);
381+
curl_setopt($handle, CURLOPT_BINARYTRANSFER, true);
383382
}*/
384383

385384
//Switch on HTTP Request method
@@ -391,15 +390,27 @@ public static function request(
391390
curl_setopt($handle, CURLOPT_POST, true);
392391
if ($data && $form_encoded) { //Encode fields if required ( URL ENCODED )
393392
curl_setopt(
394-
$handle, CURLOPT_POSTFIELDS, http_build_query($data));
395-
} else if ($data) {
396-
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
393+
$handle,
394+
CURLOPT_POSTFIELDS,
395+
http_build_query($data)
396+
);
397+
} elseif ($data) {
398+
curl_setopt(
399+
$handle,
400+
CURLOPT_POSTFIELDS,
401+
$data
402+
);
397403
}
398404
break;
399405
case self::METHOD_PUT: //On METHOD_PUT
400406
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, self::METHOD_PUT);
407+
//todo only if json
401408
if ($data) {
402-
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($data));
409+
curl_setopt(
410+
$handle,
411+
CURLOPT_POSTFIELDS,
412+
json_encode($data)
413+
);
403414
}
404415
break;
405416
case self::METHOD_DELETE: //On METHOD_DELETE
@@ -432,10 +443,10 @@ public static function request(
432443
curl_close($handle);
433444

434445
return [
435-
$responseStatusCode,
436-
$responseHeaders,
437-
json_decode($responseBody)
438-
];
446+
$responseStatusCode,
447+
$responseHeaders,
448+
json_decode($responseBody)
449+
];
439450

440451
/* if (!$response) {
441452
throw new Exception('Error: ' . curl_error($handle));

src/Filter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717
namespace Phramework\JSONAPI\Client;
18+
1819
use Phramework\JSONAPI\FilterAttribute;
1920
use Phramework\JSONAPI\FilterJSONAttribute;
2021

src/ResourceObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ class ResourceObject
4141
* @var \stdClass
4242
*/
4343
public $relationships;
44-
}
44+
}

src/Response/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ class Collection extends Response
3333
* @var ResourceObject[]
3434
*/
3535
public $included;
36-
}
36+
}

src/Response/Errors.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright 2016 Xenofon Spafaridis
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
namespace Phramework\JSONAPI\Client\Response;
18+
19+
/**
20+
* @author Xenofon Spafaridis <[email protected]>
21+
* @since 0.0.0
22+
*/
23+
class Errors extends Response
24+
{
25+
/**
26+
* @var \stdClass[]
27+
* @todo add errors object
28+
*/
29+
public $errors;
30+
}

src/Response/Resource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ class Resource extends Response
3434
* @var ResourceObject[]
3535
*/
3636
public $included;
37-
}
37+
}

src/Response/Response.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @author Xenofon Spafaridis <[email protected]>
2121
* @since 0.0.0
2222
*/
23-
class Response
23+
abstract class Response
2424
{
2525
/**
2626
* @var \stdClass
@@ -43,17 +43,13 @@ class Response
4343
protected $headers;
4444

4545
/**
46-
* Response constructor.
47-
*/
48-
public function __construct(
49-
) {
50-
}
51-
52-
/**
46+
* Parse response object, will copy any top members available at this
47+
* Response instance
5348
* @param \stdClass $response
5449
* @return $this
5550
*/
56-
public function parse(\stdClass $response) {
51+
public function parse(\stdClass $response)
52+
{
5753
$members = array_keys(get_object_vars($this));
5854

5955
foreach ($members as $member) {

0 commit comments

Comments
 (0)