Skip to content

Commit d4acad7

Browse files
committed
Formattnig cleanup
1 parent 346272a commit d4acad7

File tree

17 files changed

+120
-90
lines changed

17 files changed

+120
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
composer.phar
23
composer.lock
34
vendor/

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ SendCloud PHP API Client
33

44
An unofficial client for the SendCloud API. More info about SendCloud on http://sendcloud.nl. Below are some examples on the usage of this client.
55

6+
Full docs of the SendCloud API can be found on https://docs.sendcloud.sc/api/v2/index.html
7+
68
## Installation
79
This project can easily be installed through Composer.
810

@@ -40,7 +42,7 @@ $parcel->city = 'Wellington';
4042
$parcel->postal_code = '3423 DD';
4143
$parcel->country = 'NL';
4244
$parcel->requestShipment = true;
43-
$parcel->shipment = 10; // Shipping method ($sendCloud->shippingMethods()->all())
45+
$parcel->shipment = 10; // Shipping method, get possibilities from $sendCloud->shippingMethods()->all()
4446
$parcel->order_number = 'ORDER2014-52321';
4547

4648
$parcel->save();
@@ -49,11 +51,9 @@ $parcel->save();
4951
## Exceptions
5052
Actions to the API may cause an Exception to be thrown in case something went wrong
5153
```php
52-
try
53-
{
54+
try {
5455
$parcel->save();
55-
} catch (SendCloudApiException $e)
56-
{
56+
} catch (SendCloudApiException $e) {
5757
throw new Exception($e->getMessage());
5858
}
5959
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.5.0",
19+
"php": ">=5.6.0",
2020
"guzzlehttp/guzzle": "~6.0"
2121
},
2222
"autoload": {

example.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111

1212
// Do stuff
1313
$parcels = $sendCloud->parcels()->all();
14+
1415
var_dump($parcels);

src/Picqer/Carriers/SendCloud/Connection.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
<?php namespace Picqer\Carriers\SendCloud;
1+
<?php
2+
3+
namespace Picqer\Carriers\SendCloud;
24

35
use GuzzleHttp\Client;
46
use GuzzleHttp\Exception\RequestException;
57
use GuzzleHttp\HandlerStack;
68
use Psr\Http\Message\ResponseInterface;
79

8-
class Connection {
10+
class Connection
11+
{
912

1013
/**
1114
* Holds the API url for test requests
@@ -38,7 +41,7 @@ class Connection {
3841
* Array of inserted middleWares
3942
* @var array
4043
*/
41-
protected $middleWares = [];
44+
protected $middleWares = [];
4245

4346

4447
/**
@@ -103,14 +106,14 @@ public function get($url)
103106
{
104107
try {
105108
$result = $this->client()->get($url);
109+
return $this->parseResponse($result);
106110
} catch (RequestException $e) {
107-
if ($e->hasResponse())
111+
if ($e->hasResponse()) {
108112
$this->parseResponse($e->getResponse());
113+
}
109114

110115
throw new SendCloudApiException('SendCloud error: (no error message provided)' . $e->getResponse(), $e->getResponse()->getStatusCode());
111116
}
112-
113-
return $this->parseResponse($result);
114117
}
115118

116119
/**
@@ -124,14 +127,14 @@ public function post($url, $body)
124127
{
125128
try {
126129
$result = $this->client()->post($url, ['body' => $body]);
130+
return $this->parseResponse($result);
127131
} catch (RequestException $e) {
128-
if ($e->hasResponse())
132+
if ($e->hasResponse()) {
129133
$this->parseResponse($e->getResponse());
134+
}
130135

131136
throw new SendCloudApiException('SendCloud error: (no error message provided)' . $e->getResponse(), $e->getResponse()->getStatusCode());
132137
}
133-
134-
return $this->parseResponse($result);
135138
}
136139

137140
/**
@@ -145,14 +148,14 @@ public function put($url, $body)
145148
{
146149
try {
147150
$result = $this->client()->put($url, ['body' => $body]);
151+
return $this->parseResponse($result);
148152
} catch (RequestException $e) {
149-
if ($e->hasResponse())
153+
if ($e->hasResponse()) {
150154
$this->parseResponse($e->getResponse());
155+
}
151156

152157
throw new SendCloudApiException('SendCloud error: (no error message provided)' . $e->getResponse(), $e->getResponse()->getStatusCode());
153158
}
154-
155-
return $this->parseResponse($result);
156159
}
157160

158161
/**
@@ -165,14 +168,14 @@ public function delete($url)
165168
{
166169
try {
167170
$result = $this->client()->delete($url);
171+
return $this->parseResponse($result);
168172
} catch (RequestException $e) {
169-
if ($e->hasResponse())
173+
if ($e->hasResponse()) {
170174
$this->parseResponse($e->getResponse());
175+
}
171176

172177
throw new SendCloudApiException('SendCloud error: (no error message provided)' . $e->getResponse(), $e->getResponse()->getStatusCode());
173178
}
174-
175-
return $this->parseResponse($result);
176179
}
177180

178181
/**
@@ -189,15 +192,14 @@ public function parseResponse(ResponseInterface $response)
189192
$responseBody = $response->getBody()->getContents();
190193
$resultArray = json_decode($responseBody, true);
191194

192-
if (! is_array($resultArray)) {
195+
if ( ! is_array($resultArray)) {
193196
throw new SendCloudApiException(sprintf('SendCloud error %s: %s', $response->getStatusCode(), $responseBody), $response->getStatusCode());
194197
}
195198

196199
if (array_key_exists('error', $resultArray)
197200
&& is_array($resultArray['error'])
198201
&& array_key_exists('message', $resultArray['error'])
199-
)
200-
{
202+
) {
201203
throw new SendCloudApiException('SendCloud error: ' . $resultArray['error']['message'], $resultArray['error']['code']);
202204
}
203205

@@ -227,7 +229,7 @@ public function getEnvironment()
227229
*/
228230
public function setEnvironment($environment)
229231
{
230-
if ( $environment === 'test' ) {
232+
if ($environment === 'test') {
231233
throw new SendCloudApiException('SendCloud test environment is no longer available');
232234
}
233235
}

src/Picqer/Carriers/SendCloud/Invoice.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
<?php namespace Picqer\Carriers\SendCloud;
1+
<?php
2+
3+
namespace Picqer\Carriers\SendCloud;
24

35
/**
46
* Class Invoice
57
*
68
* @property integer id
7-
* @property string description
8-
* @property float price_excl
9-
* @property float price_incl
10-
* @property string date
9+
* @property string description
10+
* @property float price_excl
11+
* @property float price_incl
12+
* @property string date
1113
* @property boolean isPayed
12-
* @property string items
14+
* @property string items
1315
*
1416
* @package Picqer\Carriers\SendCloud
1517
*/
16-
class Invoice extends Model {
18+
class Invoice extends Model
19+
{
1720

1821
use Query\FindAll;
1922

src/Picqer/Carriers/SendCloud/Label.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace Picqer\Carriers\SendCloud;
1+
<?php
2+
3+
namespace Picqer\Carriers\SendCloud;
24

35
/**
46
* Class Label
@@ -8,7 +10,8 @@
810
*
911
* @package Picqer\Carriers\SendCloud
1012
*/
11-
class Label extends Model {
13+
class Label extends Model
14+
{
1215

1316
use Query\FindOne;
1417

src/Picqer/Carriers/SendCloud/Model.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
<?php namespace Picqer\Carriers\SendCloud;
1+
<?php
22

3-
abstract class Model {
3+
namespace Picqer\Carriers\SendCloud;
4+
5+
abstract class Model
6+
{
47

58
/**
69
* @var Connection
@@ -71,10 +74,8 @@ protected function fill(array $attributes)
7174
if (array_key_exists($this->namespaces['singular'], $attributes))
7275
$attributes = $attributes[$this->namespaces['singular']];
7376

74-
foreach ($this->fillableFromArray($attributes) as $key => $value)
75-
{
76-
if ($this->isFillable($key))
77-
{
77+
foreach ($this->fillableFromArray($attributes) as $key => $value) {
78+
if ($this->isFillable($key)) {
7879
$this->setAttribute($key, $value);
7980
}
8081
}
@@ -88,8 +89,7 @@ protected function fill(array $attributes)
8889
*/
8990
protected function fillableFromArray(array $attributes)
9091
{
91-
if (count($this->fillable) > 0)
92-
{
92+
if (count($this->fillable) > 0) {
9393
return array_intersect_key($attributes, array_flip($this->fillable));
9494
}
9595

@@ -108,8 +108,7 @@ protected function setAttribute($key, $value)
108108

109109
public function __get($key)
110110
{
111-
if (isset($this->attributes[$key]))
112-
{
111+
if (isset($this->attributes[$key])) {
113112
return $this->attributes[$key];
114113
}
115114

@@ -118,15 +117,14 @@ public function __get($key)
118117

119118
public function __set($key, $value)
120119
{
121-
if ($this->isFillable($key))
122-
{
120+
if ($this->isFillable($key)) {
123121
$this->setAttribute($key, $value);
124122
}
125123
}
126124

127125
public function exists()
128126
{
129-
if (! in_array($this->primaryKey, $this->attributes)) return false;
127+
if ( ! in_array($this->primaryKey, $this->attributes)) return false;
130128

131129
return ! empty($this->attributes[$this->primaryKey]);
132130
}
@@ -146,8 +144,7 @@ public function json()
146144
public function __debugInfo()
147145
{
148146
$result = [];
149-
foreach ($this->fillable as $attribute)
150-
{
147+
foreach ($this->fillable as $attribute) {
151148
$result[$attribute] = $this->$attribute;
152149
}
153150
return $result;

src/Picqer/Carriers/SendCloud/Parcel.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
<?php namespace Picqer\Carriers\SendCloud;
1+
<?php
2+
3+
namespace Picqer\Carriers\SendCloud;
24

35
/**
46
* Class Parcel
57
*
68
* @property integer id
7-
* @property string name
8-
* @property string company_name
9-
* @property string address
10-
* @property array address_divided
11-
* @property string city
12-
* @property string postal_code
13-
* @property string telephone
14-
* @property string email
15-
* @property array status
16-
* @property array data
17-
* @property array country
18-
* @property array shipment
19-
* @property bool requestShipment
20-
* @property string order_number
21-
* @property string tracking_number
22-
* @property string weight
9+
* @property string name
10+
* @property string company_name
11+
* @property string address
12+
* @property array address_divided
13+
* @property string city
14+
* @property string postal_code
15+
* @property string telephone
16+
* @property string email
17+
* @property array status
18+
* @property array data
19+
* @property array country
20+
* @property array shipment
21+
* @property bool requestShipment
22+
* @property string order_number
23+
* @property string tracking_number
24+
* @property string weight
2325
*
2426
* @package Picqer\Carriers\SendCloud
2527
*/

src/Picqer/Carriers/SendCloud/Persistance/Storable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace Picqer\Carriers\SendCloud\Persistance;
1+
<?php
2+
3+
namespace Picqer\Carriers\SendCloud\Persistance;
24

35
use Picqer\Carriers\SendCloud\Connection;
46

0 commit comments

Comments
 (0)