Skip to content

Commit

Permalink
Fixes from PHPStan static analysis (#49)
Browse files Browse the repository at this point in the history
Fixes from PHPStan static analysis
  • Loading branch information
antonkomarev authored Jul 19, 2020
1 parent 4ea29dc commit 7c97967
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
paths:
- src
- tests
checkMissingIterableValueType: false # Fix it
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to `cybercog/youtrack-rest-php` will be documented in this f

## [Unreleased]

## [6.2.2] - 2020-07-19

### Fixed

- ([#49]) Fixes from PHPStan static analysis

## [6.2.1] - 2020-07-19

### Fixed
Expand Down Expand Up @@ -110,7 +116,8 @@ All notable changes to `cybercog/youtrack-rest-php` will be documented in this f

- Initial release.

[Unreleased]: https://github.com/cybercog/youtrack-rest-php/compare/6.2.1...master
[Unreleased]: https://github.com/cybercog/youtrack-rest-php/compare/6.2.2...master
[6.2.2]: https://github.com/cybercog/youtrack-rest-php/compare/6.2.1...6.2.2
[6.2.1]: https://github.com/cybercog/youtrack-rest-php/compare/6.2.0...6.2.1
[6.2.0]: https://github.com/cybercog/youtrack-rest-php/compare/6.1.0...6.2.0
[6.1.0]: https://github.com/cybercog/youtrack-rest-php/compare/6.0.2...6.1.0
Expand All @@ -123,6 +130,7 @@ All notable changes to `cybercog/youtrack-rest-php` will be documented in this f
[3.0.0]: https://github.com/cybercog/youtrack-rest-php/compare/2.0.1...3.0.0
[2.0.1]: https://github.com/cybercog/youtrack-rest-php/compare/1.0.0...2.0.1

[#49]: https://github.com/cybercog/youtrack-rest-php/pull/49
[#48]: https://github.com/cybercog/youtrack-rest-php/pull/48
[#43]: https://github.com/cybercog/youtrack-rest-php/pull/43
[#41]: https://github.com/cybercog/youtrack-rest-php/pull/41
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"require": {
"php": "^7.1",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.2"
"guzzlehttp/guzzle": "^6.2",
"phpstan/phpstan": "^0.12.32"
},
"require-dev": {
"mockery/mockery": "^1.0",
Expand All @@ -60,6 +61,7 @@
"cybercog/laravel-youtrack-sdk": "Laravel integration with PHP YouTrack SDK."
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse -c .phpstan.neon",
"test": "vendor/bin/phpunit"
},
"config": {
Expand Down
3 changes: 0 additions & 3 deletions src/Client/YouTrackClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@ public function request(string $method, string $uri, array $params = [], array $
switch ($e->getCode()) {
case 401:
throw new InvalidAuthorizationToken($e->getMessage(), $e->getCode());
break;
case 403:
throw new AuthenticationException($e->getMessage(), $e->getCode());
break;
default:
throw new ClientException($e->getMessage(), $e->getCode(), $e);
break;
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/HttpClient/GuzzleHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Cog\Contracts\YouTrack\Rest\HttpClient\Exceptions\HttpClientException;
use Cog\Contracts\YouTrack\Rest\HttpClient\HttpClient as HttpClientContract;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -31,16 +32,16 @@ class GuzzleHttpClient implements HttpClientContract
/**
* GuzzleHttp client.
*
* @var \GuzzleHttp\Client
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;

/**
* Create a new GuzzleHttpClient instance.
*
* @param \GuzzleHttp\Client|null $httpClient
* @param \GuzzleHttp\ClientInterface $httpClient
*/
public function __construct(Client $httpClient = null)
public function __construct(ClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}
Expand All @@ -59,9 +60,7 @@ public function request(string $method, string $uri, array $options = []): Respo
{
try {
return $this->httpClient->request($method, $uri, $this->buildOptions($options));
} catch (BadResponseException $e) {
throw new HttpClientException($e->getResponse()->getBody()->getContents(), $e->getCode(), $e);
} catch (RequestException $e) {
} catch (BadResponseException | RequestException $e) {
$rawResponse = $e->getResponse();
if (!$rawResponse instanceof ResponseInterface) {
throw new HttpClientException($e->getMessage(), $e->getCode(), $e);
Expand Down
2 changes: 1 addition & 1 deletion src/Response/YouTrackResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class YouTrackResponse implements ResponseContract
/**
* YouTrackResponse constructor.
*
* @param $response \Psr\Http\Message\ResponseInterface
* @param \Psr\Http\Message\ResponseInterface $response
*/
public function __construct(ResponseInterface $response)
{
Expand Down
15 changes: 14 additions & 1 deletion tests/Feature/AbstractFeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Cog\YouTrack\Rest\HttpClient\GuzzleHttpClient;
use Cog\YouTrack\Rest\Tests\AbstractTestCase;
use Cog\YouTrack\Rest\Tests\Traits\HasFakeHttpResponses;
use Exception;
use GuzzleHttp\Client as HttpClient;

abstract class AbstractFeatureTestCase extends AbstractTestCase
Expand All @@ -34,8 +35,20 @@ protected function initializeClient(): YouTrackClient
return new YouTrackClient($http, $authorizer);
}

/**
* @param string $path
* @return string
*
* @throws \Exception
*/
protected function stubsPath(string $path): string
{
return realpath(__DIR__ . '/stubs/' . $path);
$path = realpath(__DIR__ . '/stubs/' . $path);

if ($path === false) {
throw new Exception('Invalid stubs path');
}

return $path;
}
}
20 changes: 18 additions & 2 deletions tests/Traits/HasFakeHttpResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ protected function getFakeResponseHeaders(string $name): array
return [];
}

return json_decode(file_get_contents($filePath), true);
$file = file_get_contents($filePath);

if ($file === false) {
return [];
}

return json_decode($file, true);
}

/**
Expand All @@ -65,7 +71,17 @@ protected function getFakeResponseBody(string $name): ?string
{
$filePath = $this->buildFakeRequestFilePath($name, 'body');

return file_exists($filePath) ? file_get_contents($filePath) : null;
if (file_exists($filePath) === false) {
return null;
}

$file = file_get_contents($filePath);

if ($file === false) {
return null;
}

return $file;
}

/**
Expand Down

0 comments on commit 7c97967

Please sign in to comment.