Skip to content

Commit 92eab36

Browse files
authored
Merge pull request #16 from ShipEngine/coverage
Coverage
2 parents ae0409c + 21d4238 commit 92eab36

15 files changed

Lines changed: 36 additions & 53 deletions

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,30 @@ Install ShipEngine via [Composer](https://getcomposer.org/):
3535
```bash
3636
composer require shipengine/shipengine
3737
```
38-
- The only configuration requirement is an [API key](https://www.shipengine.com/docs/auth/#api-keys).
38+
- The only configuration requirement is an [API Key](https://www.shipengine.com/docs/auth/#api-keys).
3939

40-
> The following example assumes that you have already set the `SHIPENGIEN_API_KEY` using `putenv()`.
40+
> The following example assumes that you have already set the `SHIPENGIEN_API_KEY` environment variable with your Api Key using `putenv()`.
4141
4242
Examples
4343
========
4444

4545
Methods
4646
-------
47-
- [validateAddress](./docs/addressValidateExample.md) - Indicates whether the provided address is valid. If the
47+
- [validateAddress](./docs/addressValidateExample.md "Validate Address method documentation") - Indicates whether the provided address is valid. If the
4848
address is valid, the method returns a normalized version of the address based on the standards of the country in
4949
which the address resides.
50-
- [normalizeAddress](./docs/normalizeAddressExample.md) - Returns a normalized, or standardized, version of the
50+
- [normalizeAddress](./docs/normalizeAddressExample.md "Normalize Address method documentation") - Returns a normalized, or standardized, version of the
5151
address. If the address cannot be normalized, an error is returned.
52-
- [trackPackage](./docs/trackPackageExample.md) - Track a package by `packageId` or by `carrierCode` and `trackingNumber`. This method returns
52+
- [trackPackage](./docs/trackPackageExample.md "Track Package method documentation") - Track a package by `packageId` or by `carrierCode` and `trackingNumber`. This method returns
5353
the all tracking events for a given shipment.
5454

5555
Class Objects
56-
--------------
56+
-------------
5757
- [ShipEngine]() - A configurable entry point to the ShipEngine API SDK, this class provides convenience methods
5858
for various ShipEngine API Services.
5959

6060
Instantiate ShipEngine Class
61-
------------------------------
61+
----------------------------
6262
```php
6363
<?php declare(strict_types=1);
6464

docs/addressValidateExample.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Address Validation Documentation
22
================================
3-
ShipEngine allows you to validate an address before using it to create a shipment to ensure accurate delivery
3+
[ShipEngine](www.shipengine.com) allows you to validate an address before using it to create a shipment to ensure accurate delivery
44
of your packages.
55

66
Address validation can lead to reduced shipping costs by preventing address correction surcharges. ShipEngine
@@ -24,8 +24,9 @@ There are two ways to validate an address using this SDK.
2424
requires a `countryCode` which should be the 2 character capitalized abbreviation for a given countryCode.
2525

2626
- **Behavior**: The `validateAddress` method will always return
27-
an [AddressValidateResult](../src/Model/Address/AddressValidateResult.php) object, even in the even that the
28-
address passed in was not *valid*.
27+
an [AddressValidateResult](../src/Model/Address/AddressValidateResult.php) object, and it allows you to determine
28+
whether an address is valid before using it for your shipments. It accepts an address object containing typical
29+
address properties, described below, and will return a normalized address object if the address is valid.
2930

3031
- **Method level configuration** - You can optionally pass in an array that contains `configuration` values to be used
3132
for the current method call. The options are `apiKey`, `baseUrl`, `pageSize`,
@@ -88,7 +89,7 @@ $validated_address = $shipengine->validateAddress($address, ['retries' => 2]);
8889
print_r($validated_address);
8990
```
9091

91-
**Successful Address Validation Output:**: As a raw `AddressValidateResult` object.
92+
**Successful Address Validation Output:** As a raw `AddressValidateResult` object.
9293

9394
```php
9495
ShipEngine\Model\Address\AddressValidateResult Object
@@ -138,7 +139,7 @@ $validated_address = $shipengine->validateAddress($address, ['retries' => 2]);
138139
print_r(json_encode($validated_address, JSON_PRETTY_PRINT)); // Return the AddressValidateResult Type as a JSON string.
139140
```
140141

141-
**Successful Address Validation Output:**: This is the `AddressValidateResult` Type serialized as JSON.
142+
**Successful Address Validation Output:** This is the `AddressValidateResult` Type serialized as JSON.
142143
```json5
143144
{
144145
"valid": true,

src/Message/Events/ShipEngineEvent.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use DateTime;
66
use ShipEngine\Message\InvalidFieldValueException;
7-
use ShipEngine\Message\ShipEngineException;
87
use ShipEngine\ShipEngineConfig;
98
use Symfony\Component\EventDispatcher\EventDispatcher;
109
use Symfony\Contracts\EventDispatcher\Event;

src/Message/TimeoutException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
final class TimeoutException extends ShipEngineException
1414
{
1515
/**
16-
* TimeoutException constructor - Instantiates a server-side error.
16+
* TimeoutException constructor - Instantiates a timeout exception.
1717
*
1818
* @param int $retryAfter The amount of time (in SECONDS) to wait before retrying the request.
1919
* @param string|null $source

src/Model/Carriers/CarrierAccount.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function __construct(array $accountInformation)
5151
$this->setCarrierAccount($accountInformation);
5252
$this->accountId = $accountInformation['accountID'];
5353
$this->accountNumber = $accountInformation['accountNumber'];
54-
$this->name = $accountInformation['name'];
5554
}
5655

5756
/**

src/Model/Package/TrackPackageResult.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class TrackPackageResult implements \JsonSerializable
3535
public ?array $events = array();
3636

3737
/**
38-
* This is the latest event to have occurred in the `$events` array.
38+
* Returns the latest event to have occurred in the `$events` array.
3939
*
4040
* @return TrackingEvent
4141
*/
@@ -45,30 +45,30 @@ public function getLatestEvent(): TrackingEvent
4545
}
4646

4747
/**
48-
* Returns `true` if there are any EXCEPTION events.
48+
* Returns `true` if there are any exception events.
4949
*
5050
* @return bool
5151
*/
5252
public function hasErrors(): bool
5353
{
5454
foreach ($this->events as $event) {
55-
if ($event->status === 'EXCEPTION') {
55+
if ($event->status === 'exception') {
5656
return true;
5757
}
5858
}
5959
return false;
6060
}
6161

6262
/**
63-
* Returns **only** the EXCEPTION events.
63+
* Returns **only** the exception events.
6464
*
6565
* @return array
6666
*/
6767
public function getErrors(): array
6868
{
6969
$errors = array();
7070
foreach ($this->events as $event) {
71-
if ($event->status === 'EXCEPTION') {
71+
if ($event->status === 'exception') {
7272
$errors[] = $event;
7373
}
7474
}

src/ShipEngine.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ public function normalizeAddress(Address $address, $config = null): Address
104104
}
105105

106106
/**
107+
* Fetch the carrier accounts connected to your ShipEngine Account.
108+
*
107109
* @param array|ShipEngineConfig|null $config Optional configuration overrides for this method call {apiKey:string,
108110
* baseUrl:string, pageSize:int, retries:int, timeout:int, client:HttpClient|null}
109-
*
110111
* @param string|null $carrierCode
111112
* @return array An array of **CarrierAccount** objects that correspond the to carrier accounts connected
112113
* to a given ShipEngine account.
@@ -120,7 +121,7 @@ public function getCarrierAccounts(?string $carrierCode = null, $config = null):
120121

121122
/**
122123
* Track a package by `trackingNumber` and `carrierCode` via the **TrackingQuery** object, by using just the
123-
* **packageId**, or by using a **Package** object.
124+
* **packageId**.
124125
*
125126
* @param array|ShipEngineConfig|null $config Optional configuration overrides for this method call {apiKey:string,
126127
* baseUrl:string, pageSize:int, retries:int, timeout:int, client:HttpClient|null}

src/ShipEngineClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function sendRequest(
123123
$baseUri = !getenv('CLIENT_BASE_URI') ? $config->baseUrl : getenv('CLIENT_BASE_URI');
124124
$requestHeaders = array(
125125
'Api-Key' => $config->apiKey,
126-
'User-Agent' => $this->deriveUserAgent(ShipEngine::VERSION),
126+
'User-Agent' => $this->deriveUserAgent(),
127127
'Content-Type' => 'application/json',
128128
'Accept' => 'application/json'
129129
);
@@ -279,9 +279,9 @@ private function handleResponse(array $response): array
279279
*
280280
* @returns string
281281
*/
282-
private function deriveUserAgent(string $version): string
282+
private function deriveUserAgent(): string
283283
{
284-
$sdk_version = 'shipengine-php/' . $version;
284+
$sdk_version = 'shipengine-php/' . ShipEngine::VERSION;
285285

286286
$os = explode(' ', php_uname());
287287
$os_kernel = $os[0] . '/' . $os[2];

src/ShipEngineConfig.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* Class ShipEngineConfig - This is the configuration object for the ShipEngine object and it's properties are
13-
* used throughout this SDK>
13+
* used throughout this SDK.
1414
*
1515
* @package ShipEngine
1616
*/
@@ -163,10 +163,6 @@ public function merge(?array $newConfig = null): ShipEngineConfig
163163
($config['timeout'] = $newConfig['timeout']) :
164164
($config['timeout'] = $this->timeout);
165165

166-
isset($newConfig['timeout']) ?
167-
($config['timeout'] = $newConfig['timeout']) :
168-
($config['timeout'] = $this->timeout);
169-
170166
isset($newConfig['$this->eventListener']) ?
171167
($config['$this->eventListener'] = $newConfig['$this->eventListener']) :
172168
($config['$this->eventListener'] = $this->eventListener);

src/Util/Assert.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public function tooManyAddressLines(array $street): void
6060
}
6161

6262
/**
63-
* Asserts that city in not an empty string and is valid characters.
63+
* Asserts that city in not an empty string and contains valid characters.
6464
*
6565
* @param string $cityLocality
6666
* @throws ValidationException
6767
*/
6868
public function isCityValid(string $cityLocality): void
6969
{
70-
if (preg_match('/^[a-zA-Z0-9\s\W]*$/', $cityLocality) === false || $cityLocality === '') {
70+
if (preg_match('/^[a-zA-Z0-9\s]*$/', $cityLocality) === false || $cityLocality === '') {
7171
throw new ValidationException(
7272
'Invalid address. Either the postal code or the city/locality and state/province must be specified.',
7373
null,
@@ -86,7 +86,7 @@ public function isCityValid(string $cityLocality): void
8686
*/
8787
public function isStateValid(string $stateProvince): void
8888
{
89-
if (preg_match('/^[A-Z\W]{2}$/', $stateProvince) === false || $stateProvince === '') {
89+
if (preg_match('/^[A-Z]{2}$/', $stateProvince) === false || $stateProvince === '') {
9090
throw new ValidationException(
9191
'Invalid address. Either the postal code or the city/locality and state/province must be specified.',
9292
null,
@@ -264,7 +264,7 @@ public function isPackageIdValid(string $packageId): void
264264
$this->isPackageIdPrefixValid($packageId);
265265

266266
if (preg_match(
267-
'/^pkg_[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/',
267+
'/^pkg_[1-9a-zA-Z]+$/',
268268
$packageId
269269
) === 0
270270
) {

0 commit comments

Comments
 (0)