Skip to content

Commit

Permalink
Make Code Standards
Browse files Browse the repository at this point in the history
  • Loading branch information
LauLaman committed Nov 17, 2017
1 parent 9131b26 commit eb9701f
Show file tree
Hide file tree
Showing 29 changed files with 90 additions and 67 deletions.
10 changes: 5 additions & 5 deletions src/Client/ApiScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ public function setImageScope(Rights $rights): void
public function getUrlParameters(): string
{
$scope = [];
if (!is_null($this->finance)) {
if ($this->finance !== null) {
$scope[] = self::FINANCE . ':' . $this->finance->getValue();
}
if (!is_null($this->purchase)) {
if ($this->purchase !== null) {
$scope[] = self::PURCHASE . ':' . $this->purchase->getValue();
}
if (!is_null($this->product)) {
if ($this->product !== null) {
$scope[] = self::PRODUCT . ':' . $this->product->getValue();
}
if (!is_null($this->inventory)) {
if ($this->inventory !== null) {
$scope[] = self::INVENTORY . ':' . $this->inventory->getValue();
}
if (!is_null($this->image)) {
if ($this->image !== null) {
$scope[] = self::IMAGE . ':' . $this->image->getValue();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Client/Exception/GuzzleClientExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ private static function handleClient400Exception(ClientException $exception): vo
switch ($responseData['error']) {
case 'invalid_grant':
self::handleInvalidGrantException($responseData);
// no break
case 'invalid_client':
self::handleInvalidClientException($responseData);
// no break
case 'unauthorized_client':
throw new InvalidClientException($responseData['error_description']);
default:
Expand Down
8 changes: 4 additions & 4 deletions src/Client/Image/ImageFileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ public function getPostBodyData(): string
return json_encode($data);
}

private function validateFile(string $file)
private function validateFile(string $file): void
{
self::validateFileSize($file);
self::validatedImageType($file);
self::validateImageSize($file);
}

private static function validateFileSize($file)
private static function validateFileSize($file): void
{
$maxFileSizeBytes = (self::MAX_FILE_SIZE_MB * 1024 * 1024);
if (filesize($file) > $maxFileSizeBytes) {
throw new MaximumImageFileSizeExcededException(sprintf('Max file size is \'%d Mb\'', self::MAX_FILE_SIZE_MB));
}
}

private static function validatedImageType(string $file)
private static function validatedImageType(string $file): void
{
$type = false;

Expand All @@ -80,7 +80,7 @@ private static function validatedImageType(string $file)
}
}

private static function validateImageSize(string $file)
private static function validateImageSize(string $file): void
{
list($width, $height) = getimagesize($file);

Expand Down
2 changes: 1 addition & 1 deletion src/GuzzleIzettleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getAccessTokenFromUserLogin(string $username, string $password):

try {
$this->setAccessToken($this->requestAccessToken(self::API_ACCESS_TOKEN_REQUEST_URL, $options));
} catch (ClientException $exception){
} catch (ClientException $exception) {
GuzzleClientExceptionHandler::handleClientException($exception);
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Integration/Client/ImageClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ public function getPurchaseHistory(): void
$image = $imageClient->postImage(new ImageUrlUpload(''));

self::assertInstanceOf(Image::class, $image);


}
}
3 changes: 1 addition & 2 deletions tests/Integration/GuzzleIzettleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use LauLamanApps\IzettleApi\GuzzleIzettleClient;
use PHPUnit\Framework\TestCase;


/**
* @medium
*/
Expand All @@ -39,6 +38,6 @@ public function getAccessTokenFromUserLogin_WrongCredentials(): void
$handler = HandlerStack::create($mock);

$izettleClient = new GuzzleIzettleClient(new GuzzleClient(['handler' => $handler]), '', '');
$izettleClient->getAccessTokenFromUserLogin('','');
$izettleClient->getAccessTokenFromUserLogin('', '');
}
}
16 changes: 11 additions & 5 deletions tests/Unit/Api/ImageCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
use LauLamanApps\IzettleApi\API\Image;
use LauLamanApps\IzettleApi\API\ImageCollection;
use PHPUnit\Framework\TestCase;

/**
* @small
*/
final class ImageCollectionTest extends TestCase
{
/** @test */
public function imageCollection()
/**
* @test
*/
public function imageCollection(): void
{
$image1 = $this->getImageWithUuid('a.jpg');
$image2 = $this->getImageWithUuid('b.png');
Expand All @@ -37,8 +41,10 @@ public function imageCollection()
self::assertFalse(array_key_exists($image2->getFilename(), $collection));
}

/** @test */
public function get()
/**
* @test
*/
public function get(): void
{
$filename = 'test.jpg';
$imageCollection = new ImageCollection([$this->getImageWithUuid($filename)]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Api/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ImageTest extends TestCase
/**
* @test
*/
public function image()
public function image(): void
{
$filename = 'image.jpg';

Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/Api/Product/CategoryCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
*/
final class CategoryCollectionTest extends TestCase
{
/** @test */
public function categoryCollection()
/**
* @test
*/
public function categoryCollection(): void
{
$category1 = $this->getCategoryWithUuid((string) Uuid::uuid1());
$category2 = $this->getCategoryWithUuid((string) Uuid::uuid1());
Expand Down
8 changes: 6 additions & 2 deletions tests/Unit/Api/Product/CategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;

/** * @small */
/**
* @small
*/
final class CategoryTest extends TestCase
{
/** @test */
/**
* @test
*/
public function new(): void
{
$name = 'name';
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Api/Product/DiscountCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
use LauLamanApps\IzettleApi\API\Product\DiscountCollection;
use PHPUnit\Framework\TestCase;

/** * @small */
/**
* @small
*/
final class DiscountCollectionTest extends TestCase
{
/** @test */
public function discountCollection()
/**
* @test
*/
public function discountCollection(): void
{
$discount1 = $this->getDiscountWithUuid();
$discount2 = $this->getDiscountWithUuid();
Expand Down
9 changes: 7 additions & 2 deletions tests/Unit/Api/Product/ProductCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
use LauLamanApps\IzettleApi\API\Product\VariantCollection;
use PHPUnit\Framework\TestCase;

/**
* @small
*/
final class ProductCollectionTest extends TestCase
{
/** @test */
public function productCollection()
/**
* @test
*/
public function productCollection(): void
{
$product1 = $this->getProductWithUuid();
$product2 = $this->getProductWithUuid();
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Api/Product/VariantCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

/** * @small */
/**
* @small
*/
final class VariantCollectionTest extends TestCase
{
/** @test */
public function variantCollection()
/**
* @test
*/
public function variantCollection(): void
{
$variant1 = $this->getVariantWithUuid();
$variant2 = $this->getVariantWithUuid();
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Api/Purchase/CoordinatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class CoordinatesTest extends TestCase
* @test
* @dataProvider getCoordinates
*/
public function coordinate(float $latitude, float $longitude, float $accuracyMeters)
public function coordinate(float $latitude, float $longitude, float $accuracyMeters): void
{
$coordinate = new Coordinates($latitude, $longitude, $accuracyMeters);

Expand All @@ -39,7 +39,7 @@ public function getCoordinates(): array
* @expectedException \LauLamanApps\IzettleApi\API\Purchase\Exception\InvalidLatitudeException
* @dataProvider getInvalidLatitude
*/
public function invalidLatitude(float $latitude)
public function invalidLatitude(float $latitude): void
{
new Coordinates($latitude, 5.1511458, 10.0);
}
Expand All @@ -57,7 +57,7 @@ public function getInvalidLatitude(): array
* @expectedException \LauLamanApps\IzettleApi\API\Purchase\Exception\InvalidLongitudeException
* @dataProvider getInvalidLongitude
*/
public function invalidLongitude(float $longitude)
public function invalidLongitude(float $longitude): void
{
new Coordinates(52.3504547, $longitude, 10.0);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Api/Purchase/Payment/CashPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class CashPaymentTest extends TestCase
* @test
* @dataProvider getAmounts
*/
public function changedAmount($shouldPay, $payed)
public function changedAmount($shouldPay, $payed): void
{
$shouldReceiveChange = ($payed - $shouldPay);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Api/Purchase/PurchaseHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class PurchaseHistoryTest extends TestCase
/**
* @test
*/
public function purchaseHistory()
public function purchaseHistory(): void
{
$initialPurchases = 2;
$purchaseHistory = new PurchaseHistory(
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Api/Purchase/PurchaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class PurchaseTest extends TestCase
/**
* @test
*/
public function purchase()
public function purchase(): void
{
$products = ['products'];
$payments = ['payments'];
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Client/ApiScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public function setImageScope(Rights $rights): void
public function getRights(): array
{
$rights = [];
foreach (Rights::getValidOptions() as $right){
foreach (Rights::getValidOptions() as $right) {
$rights[$right] = [Rights::get($right)];
}

return $rights;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use GuzzleHttp\Exception\RequestException as GuzzleRequestException;
use LauLamanApps\IzettleApi\Client\Exception\ClientException;
use LauLamanApps\IzettleApi\Client\Exception\GuzzleClientExceptionHandler;
use LauLamanApps\IzettleApi\Client\Exception\InvalidClientException;
use LauLamanApps\IzettleApi\Client\Exception\InvalidClient\InvalidClientIdException;
use LauLamanApps\IzettleApi\Client\Exception\InvalidClientException;
use LauLamanApps\IzettleApi\Client\Exception\InvalidGrant\InvalidUsernameOrPasswordException;
use LauLamanApps\IzettleApi\Client\Exception\InvalidGrant\TooManyFailedAttemptsException;
use LauLamanApps\IzettleApi\Client\Exception\InvalidGrantException;
Expand Down Expand Up @@ -78,7 +78,7 @@ public function getRequestExceptions(): array
];
}

private function getClientException(int $code ,string $error, string $errorDescription): GuzzleClientException
private function getClientException(int $code, string $error, string $errorDescription): GuzzleClientException
{
/** @var RequestInterface|MockInterface $request */
$request = Mockery::mock(RequestInterface::class);
Expand Down Expand Up @@ -106,5 +106,4 @@ private function getResponse(int $code, array $returnData): ResponseInterface

return $response;
}

}
6 changes: 3 additions & 3 deletions tests/Unit/Client/Product/DiscountParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class DiscountBuilderTest extends TestCase
/**
* @test
*/
public function buildFromJsonSingle()
public function buildFromJsonSingle(): void
{
$json = file_get_contents(dirname(__FILE__) . '/json-files/single-discount.json');
$data = json_decode($json, true)[0];
Expand Down Expand Up @@ -56,7 +56,7 @@ public function buildFromJsonSingle()
/**
* @test
*/
public function buildFromJsonMultiple()
public function buildFromJsonMultiple(): void
{
$json = file_get_contents(dirname(__FILE__) . '/json-files/multiple-discount.json');
$data = json_decode($json, true);
Expand Down Expand Up @@ -93,7 +93,7 @@ public function buildFromJsonMultiple()
/**
* @test
*/
public function buildFromArray()
public function buildFromArray(): void
{
$json = file_get_contents(dirname(__FILE__) . '/json-files/multiple-discount.json');
$data = json_decode($json, true);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Client/Product/LibraryParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class LibraryBuilderTest extends TestCase
/**
* @test
*/
public function createFromResponse()
public function createFromResponse(): void
{
$json = file_get_contents(dirname(__FILE__) . '/json-files/library.json');
$data = json_decode($json, true);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Client/Product/ProductParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class ProductBuilderTest extends TestCase
* @test
* @dataProvider getProductJsonData
*/
public function buildFromJson($json, $data)
public function buildFromJson($json, $data): void
{
$categoryBuilderMock = Mockery::mock(CategoryBuilderInterface::class);
$imageBuilderMock = Mockery::mock(ImageBuilderInterface::class);
Expand Down Expand Up @@ -64,7 +64,7 @@ public function buildFromJson($json, $data)
* @test
* @dataProvider getProductArrayData
*/
public function buildFromArray($data)
public function buildFromArray($data): void
{
$categoryBuilderMock = Mockery::mock(CategoryBuilderInterface::class);
$imageBuilderMock = Mockery::mock(ImageBuilderInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Client/Product/VariantsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class VariantsBuilderTest extends TestCase
* @test
* @dataProvider getVariantArrayData
*/
public function buildFromArray(array $data)
public function buildFromArray(array $data): void
{
$builder = new VariantBuilder();
$variantCollection = $builder->buildFromArray($data);
Expand Down
Loading

0 comments on commit eb9701f

Please sign in to comment.