Skip to content

Commit

Permalink
PHP 7 language features
Browse files Browse the repository at this point in the history
  • Loading branch information
janlanger committed Mar 30, 2016
2 parents b7caeed + 6674711 commit e2a5748
Show file tree
Hide file tree
Showing 83 changed files with 276 additions and 622 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.6
- 7.0
- nightly
- hhvm
Expand Down
2 changes: 2 additions & 0 deletions build/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
</rule>
<rule ref="SlevomatCodingStandard.Typehints.DeclareStrictTypes" />
<rule ref="SlevomatCodingStandard.Typehints.ReturnTypehintSpacing" />
<rule ref="Consistence.NamingConventions.ValidVariableName.NotCamelCaps">
<exclude-pattern>tests/unit/Crypto/GlobalFunctionsMock.php</exclude-pattern>
</rule>
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
},
"require": {
"ext-openssl": "*",
"php": "^5.6.0|^7.0"
"php": "^7.0"
},
"require-dev": {
"consistence/coding-standard": "^0.10.0",
"jakub-onderka/php-parallel-lint": "^0.9",
"phing/phing": "~2.12",
"phpunit/phpunit": "^5.0.4",
"slevomat/coding-standard": "^1.0.5",
"phpunit/phpunit": "^5.2.12",
"slevomat/coding-standard": "dev-php7#5dceec0",
"guzzlehttp/guzzle": "^6.1",
"satooshi/php-coveralls": "^1.0"
},
Expand Down
33 changes: 14 additions & 19 deletions src/Api/ApiClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down Expand Up @@ -28,15 +28,10 @@ class ApiClient
*/
private $apiUrl;

/**
* @param ApiClientDriver $driver
* @param CryptoService $cryptoService
* @param string|null $apiUrl
*/
public function __construct(
ApiClientDriver $driver,
CryptoService $cryptoService,
$apiUrl = null
string $apiUrl = null
)
{
$this->driver = $driver;
Expand All @@ -60,12 +55,12 @@ public function __construct(
* @throws ApiClientDriverException
*/
public function get(
$url,
string $url,
array $data = [],
SignatureDataFormatter $requestSignatureDataFormatter,
SignatureDataFormatter $responseSignatureDataFormatter,
\Closure $responseValidityCallback = null
)
): Response
{
return $this->request(
new HttpMethod(HttpMethod::GET),
Expand All @@ -92,11 +87,11 @@ public function get(
* @throws ApiClientDriverException
*/
public function post(
$url,
string $url,
array $data = [],
SignatureDataFormatter $requestSignatureDataFormatter,
SignatureDataFormatter $responseSignatureDataFormatter
)
): Response
{
return $this->request(
new HttpMethod(HttpMethod::POST),
Expand All @@ -122,11 +117,11 @@ public function post(
* @throws ApiClientDriverException
*/
public function put(
$url,
string $url,
array $data = [],
SignatureDataFormatter $requestSignatureDataFormatter,
SignatureDataFormatter $responseSignatureDataFormatter
)
): Response
{
return $this->request(
new HttpMethod(HttpMethod::PUT),
Expand Down Expand Up @@ -155,16 +150,16 @@ public function put(
*/
public function request(
HttpMethod $method,
$url,
string $url,
array $queries = [],
array $data = null,
SignatureDataFormatter $responseSignatureDataFormatter,
\Closure $responseValidityCallback = null
)
): Response
{
foreach ($queries as $key => $value) {
if (strpos($url, '{' . $key . '}') !== false) {
$url = str_replace('{' . $key . '}', urlencode($value), $url);
$url = str_replace('{' . $key . '}', urlencode((string) $value), $url);
unset($queries[$key]);
}
}
Expand Down Expand Up @@ -230,7 +225,7 @@ public function request(
* @throws PublicKeyFileException
* @throws VerificationFailedException
*/
public function createResponseByData(array $data, SignatureDataFormatter $responseSignatureDataFormatter)
public function createResponseByData(array $data, SignatureDataFormatter $responseSignatureDataFormatter): Response
{
$response = new Response(
new ResponseCode(ResponseCode::S200_OK),
Expand All @@ -252,7 +247,7 @@ public function createResponseByData(array $data, SignatureDataFormatter $respon
* @throws PrivateKeyFileException
* @throws SigningFailedException
*/
private function prepareData(array $data, SignatureDataFormatter $signatureDataFormatter)
private function prepareData(array $data, SignatureDataFormatter $signatureDataFormatter): array
{
$data['dttm'] = (new DateTimeImmutable())->format('YmdHis');
$data['signature'] = $this->cryptoService->signData($data, $signatureDataFormatter);
Expand All @@ -269,7 +264,7 @@ private function prepareData(array $data, SignatureDataFormatter $signatureDataF
* @throws PublicKeyFileException
* @throws VerificationFailedException
*/
private function decodeData(Response $response, SignatureDataFormatter $signatureDataFormatter)
private function decodeData(Response $response, SignatureDataFormatter $signatureDataFormatter): array
{
$data = $response->getData();

Expand Down
4 changes: 2 additions & 2 deletions src/Api/ApiClientDriver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand All @@ -12,6 +12,6 @@ interface ApiClientDriver
* @param string[] $headers
* @return Response
*/
public function request(HttpMethod $method, $url, array $data = null, array $headers = []);
public function request(HttpMethod $method, string $url, array $data = null, array $headers = []): Response;

}
2 changes: 1 addition & 1 deletion src/Api/ApiClientDriverException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/BadRequestException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
8 changes: 4 additions & 4 deletions src/Api/Driver/CurlDriver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api\Driver;

Expand All @@ -21,7 +21,7 @@ class CurlDriver implements ApiClientDriver
* @return Response
* @throws CurlDriverException
*/
public function request(HttpMethod $method, $url, array $data = null, array $headers = [])
public function request(HttpMethod $method, string $url, array $data = null, array $headers = []): Response
{
$ch = curl_init($url);

Expand Down Expand Up @@ -55,7 +55,7 @@ public function request(HttpMethod $method, $url, array $data = null, array $hea

return new Response(
$responseCode,
json_decode($body, JSON_OBJECT_AS_ARRAY),
json_decode($body, true),
$this->parseHeaders($headers)
);
}
Expand All @@ -64,7 +64,7 @@ public function request(HttpMethod $method, $url, array $data = null, array $hea
* @param string $rawHeaders
* @return string[]
*/
private function parseHeaders($rawHeaders)
private function parseHeaders(string $rawHeaders): array
{
$headers = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Driver/CurlDriverException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api\Driver;

Expand Down
8 changes: 4 additions & 4 deletions src/Api/Driver/GuzzleDriver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api\Driver;

Expand Down Expand Up @@ -29,7 +29,7 @@ public function __construct(Client $client)
* @return Response
* @throws GuzzleDriverException
*/
public function request(HttpMethod $method, $url, array $data = null, array $headers = [])
public function request(HttpMethod $method, string $url, array $data = null, array $headers = []): Response
{
$postData = null;
if ($method->equalsValue(HttpMethod::POST) || $method->equalsValue(HttpMethod::PUT)) {
Expand All @@ -52,10 +52,10 @@ public function request(HttpMethod $method, $url, array $data = null, array $hea

return new Response(
$responseCode,
json_decode($httpResponse->getBody(), JSON_OBJECT_AS_ARRAY),
json_decode((string) $httpResponse->getBody(), true),
$responseHeaders
);
} catch (\Exception $e) {
} catch (\Throwable $e) {
throw new GuzzleDriverException($e);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Driver/GuzzleDriverException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api\Driver;

Expand All @@ -7,9 +7,9 @@
class GuzzleDriverException extends \RuntimeException implements ApiClientDriverException
{

public function __construct(\Exception $e)
public function __construct(\Throwable $previous)
{
parent::__construct('Request error: ' . $e->getMessage(), $e->getCode(), $e);
parent::__construct('Request error: ' . $previous->getMessage(), $previous->getCode(), $previous);
}

}
2 changes: 1 addition & 1 deletion src/Api/ForbiddenException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/HttpMethod.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/InternalErrorException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
14 changes: 3 additions & 11 deletions src/Api/InvalidPaymentException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand All @@ -10,21 +10,13 @@ class InvalidPaymentException extends RequestException
/** @var ProcessPaymentRequest */
private $request;

/**
* @param ProcessPaymentRequest $request
* @param Response $response
* @param string $payId
*/
public function __construct(ProcessPaymentRequest $request, Response $response, $payId)
public function __construct(ProcessPaymentRequest $request, Response $response, string $payId)
{
parent::__construct(sprintf('PayId %s is invalid or expired.', $payId), $response);
$this->request = $request;
}

/**
* @return ProcessPaymentRequest
*/
public function getRequest()
public function getRequest(): ProcessPaymentRequest
{
return $this->request;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Api/InvalidSignatureException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/MethodNotAllowedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
13 changes: 3 additions & 10 deletions src/Api/RequestException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand All @@ -10,21 +10,14 @@ abstract class RequestException extends \RuntimeException
*/
private $response;

/**
* @param string $message
* @param Response $response
*/
public function __construct($message, Response $response)
public function __construct(string $message, Response $response)
{
parent::__construct($message);

$this->response = $response;
}

/**
* @return Response
*/
public function getResponse()
public function getResponse(): Response
{
return $this->response;
}
Expand Down
9 changes: 3 additions & 6 deletions src/Api/Response.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down Expand Up @@ -36,10 +36,7 @@ public function __construct(
$this->headers = $headers;
}

/**
* @return ResponseCode
*/
public function getResponseCode()
public function getResponseCode(): ResponseCode
{
return $this->responseCode;
}
Expand All @@ -55,7 +52,7 @@ public function getData()
/**
* @return string[]
*/
public function getHeaders()
public function getHeaders(): array
{
return $this->headers;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Api/ResponseCode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/ServiceUnavailableException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/TooManyRequestsException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Api;

Expand Down
Loading

0 comments on commit e2a5748

Please sign in to comment.