Skip to content

Commit 7682438

Browse files
Ramp up static analysis
1 parent 561fdf6 commit 7682438

File tree

7 files changed

+89
-17
lines changed

7 files changed

+89
-17
lines changed

lib/Gitlab/Api/AbstractApi.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class AbstractApi implements ApiInterface
4545
public function __construct(Client $client, StreamFactory $streamFactory = null)
4646
{
4747
$this->client = $client;
48-
$this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find();
48+
$this->streamFactory = $streamFactory === null ? StreamFactoryDiscovery::find() : $streamFactory;
4949
}
5050

5151
/**
@@ -282,9 +282,11 @@ private function guessContentType($file)
282282
if (!class_exists(\finfo::class, false)) {
283283
return 'application/octet-stream';
284284
}
285+
285286
$finfo = new \finfo(FILEINFO_MIME_TYPE);
287+
$type = $finfo->file($file);
286288

287-
return $finfo->file($file) ?: 'application/octet-stream';
289+
return $type !== false ? $type : 'application/octet-stream';
288290
}
289291

290292
/**

lib/Gitlab/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Client
103103
*/
104104
public function __construct(Builder $httpClientBuilder = null)
105105
{
106-
$this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder();
106+
$this->httpClientBuilder = $builder = $httpClientBuilder === null ? new Builder() : $httpClientBuilder;
107107
$this->responseHistory = new History();
108108

109109
$builder->addPlugin(new GitlabExceptionThrower());

lib/Gitlab/HttpClient/Builder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public function __construct(
8383
RequestFactory $requestFactory = null,
8484
StreamFactory $streamFactory = null
8585
) {
86-
$this->httpClient = $httpClient ?: HttpClientDiscovery::find();
87-
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
88-
$this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find();
86+
$this->httpClient = $httpClient === null ? HttpClientDiscovery::find() : $httpClient;
87+
$this->requestFactory = $requestFactory === null ? MessageFactoryDiscovery::find() : $requestFactory;
88+
$this->streamFactory = $streamFactory === null ? StreamFactoryDiscovery::find() : $streamFactory;
8989
}
9090

9191
/**

lib/Gitlab/HttpClient/Plugin/GitlabExceptionThrower.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,33 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla
3939
$status = $response->getStatusCode();
4040

4141
if ($status >= 400 && $status < 600) {
42-
self::handleError($status, ResponseMediator::getErrorMessage($response) ?: $response->getReasonPhrase());
42+
$message = ResponseMediator::getErrorMessage($response);
43+
44+
throw self::createException($status, $message === null ? $response->getReasonPhrase() : $message);
4345
}
4446

4547
return $response;
4648
});
4749
}
4850

4951
/**
50-
* Handle an error response.
52+
* Create an exception from a status code and error message.
5153
*
5254
* @param int $status
5355
* @param string $message
5456
*
55-
* @throws ErrorException
56-
* @throws RuntimeException
57-
*
58-
* @return void
57+
* @return ErrorException|RuntimeException
5958
*/
60-
private static function handleError($status, $message)
59+
private static function createException($status, $message)
6160
{
6261
if (400 === $status || 422 === $status) {
63-
throw new ValidationFailedException($message, $status);
62+
return new ValidationFailedException($message, $status);
6463
}
6564

6665
if (429 === $status) {
67-
throw new ApiLimitExceededException($message, $status);
66+
return new ApiLimitExceededException($message, $status);
6867
}
6968

70-
throw new RuntimeException($message, $status);
69+
return new RuntimeException($message, $status);
7170
}
7271
}

phpstan-baseline.neon

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,67 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\StreamFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
5+
count: 1
6+
path: lib/Gitlab/Api/AbstractApi.php
7+
8+
-
9+
message: "#^Fetching deprecated class constant AUTH_URL_TOKEN of class Gitlab\\\\Client\\:\nsince version 9\\.18 and will be removed in 10\\.0\\.$#"
10+
count: 2
11+
path: lib/Gitlab/Client.php
12+
13+
-
14+
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\UriFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
15+
count: 1
16+
path: lib/Gitlab/Client.php
17+
18+
-
19+
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\MessageFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
20+
count: 1
21+
path: lib/Gitlab/HttpClient/Builder.php
22+
23+
-
24+
message: "#^Call to method find\\(\\) of deprecated class Http\\\\Discovery\\\\StreamFactoryDiscovery\\:\nThis will be removed in 2\\.0\\. Consider using Psr17FactoryDiscovery\\.$#"
25+
count: 1
26+
path: lib/Gitlab/HttpClient/Builder.php
27+
28+
-
29+
message: "#^Fetching deprecated class constant AUTH_URL_TOKEN of class Gitlab\\\\Client\\:\nsince version 9\\.18 and will be removed in 10\\.0\\.$#"
30+
count: 1
31+
path: lib/Gitlab/HttpClient/Plugin/Authentication.php
32+
33+
-
34+
message: "#^Return type \\(Gitlab\\\\Model\\\\Issue\\) of method Gitlab\\\\Model\\\\Issue\\:\\:close\\(\\) should be covariant with return type \\(static\\(Gitlab\\\\Model\\\\Stateful\\)\\) of method Gitlab\\\\Model\\\\Stateful\\:\\:close\\(\\)$#"
35+
count: 2
36+
path: lib/Gitlab/Model/Issue.php
37+
38+
-
39+
message: "#^Return type \\(Gitlab\\\\Model\\\\Issue\\) of method Gitlab\\\\Model\\\\Issue\\:\\:open\\(\\) should be covariant with return type \\(static\\(Gitlab\\\\Model\\\\Stateful\\)\\) of method Gitlab\\\\Model\\\\Stateful\\:\\:open\\(\\)$#"
40+
count: 2
41+
path: lib/Gitlab/Model/Issue.php
42+
43+
-
44+
message: "#^Return type \\(Gitlab\\\\Model\\\\Issue\\) of method Gitlab\\\\Model\\\\Issue\\:\\:reopen\\(\\) should be covariant with return type \\(static\\(Gitlab\\\\Model\\\\Stateful\\)\\) of method Gitlab\\\\Model\\\\Stateful\\:\\:reopen\\(\\)$#"
45+
count: 2
46+
path: lib/Gitlab/Model/Issue.php
47+
48+
-
49+
message: "#^Return type \\(Gitlab\\\\Model\\\\MergeRequest\\) of method Gitlab\\\\Model\\\\MergeRequest\\:\\:close\\(\\) should be covariant with return type \\(static\\(Gitlab\\\\Model\\\\Stateful\\)\\) of method Gitlab\\\\Model\\\\Stateful\\:\\:close\\(\\)$#"
50+
count: 2
51+
path: lib/Gitlab/Model/MergeRequest.php
52+
53+
-
54+
message: "#^Return type \\(Gitlab\\\\Model\\\\MergeRequest\\) of method Gitlab\\\\Model\\\\MergeRequest\\:\\:reopen\\(\\) should be covariant with return type \\(static\\(Gitlab\\\\Model\\\\Stateful\\)\\) of method Gitlab\\\\Model\\\\Stateful\\:\\:reopen\\(\\)$#"
55+
count: 2
56+
path: lib/Gitlab/Model/MergeRequest.php
57+
58+
-
59+
message: "#^Return type \\(Gitlab\\\\Model\\\\MergeRequest\\) of method Gitlab\\\\Model\\\\MergeRequest\\:\\:open\\(\\) should be covariant with return type \\(static\\(Gitlab\\\\Model\\\\Stateful\\)\\) of method Gitlab\\\\Model\\\\Stateful\\:\\:open\\(\\)$#"
60+
count: 2
61+
path: lib/Gitlab/Model/MergeRequest.php
62+
63+
-
64+
message: "#^Variable method call on Gitlab\\\\Api\\\\ApiInterface\\.$#"
65+
count: 1
66+
path: lib/Gitlab/ResultPager.php
367

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ parameters:
66
checkMissingIterableValueType: false
77
paths:
88
- lib
9+
ignoreErrors:
10+
- "#Anonymous function should have native return typehint#"
11+
- '#Only booleans are allowed in an if condition#'

vendor-bin/phpstan/composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"require": {
3-
"phpstan/phpstan": "~0.12.32"
3+
"phpstan/phpstan": "~0.12.32",
4+
"phpstan/extension-installer": "~1.0.4",
5+
"phpstan/phpstan-deprecation-rules": "~0.12.4",
6+
"phpstan/phpstan-strict-rules": "~0.12.2",
7+
"thecodingmachine/phpstan-strict-rules": "~0.12.0"
48
},
59
"config": {
610
"preferred-install": "dist"

0 commit comments

Comments
 (0)