Skip to content

Commit 57989d6

Browse files
Cleanup code using phpstan
1 parent 164f3a0 commit 57989d6

File tree

107 files changed

+350
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+350
-165
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
* text=auto
22

33
/tests export-ignore
4+
/vendor-bin export-ignore
45
/.gitattributes export-ignore
56
/.github export-ignore
67
/.gitignore export-ignore
8+
/phpstan-baseline.neon export-ignore
9+
/phpstan.neon.dist export-ignore
710
/phpunit.xml.dist export-ignore
811
/CHANGELOG.md export-ignore
912
/README.md export-ignore

.github/workflows/static.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 4 * * 1'
8+
9+
jobs:
10+
analyse:
11+
12+
runs-on: ubuntu-latest
13+
14+
name: PHPStan
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Run Composer
19+
run: docker run --rm -w /data -v ${{ github.workspace }}:/data --entrypoint composer registry.gitlab.com/grahamcampbell/php:$7.4-base update -n -o
20+
- name: Install PHPStan
21+
run: docker run --rm -w /data -v ${{ github.workspace }}:/data --entrypoint composer registry.gitlab.com/grahamcampbell/php:$7.4-base bin phpstan update -n -o
22+
- name: Run PHPUnit
23+
run: docker run --rm -w /data -v ${{ github.workspace }}:/data --entrypoint vendor/bin/phpstan registry.gitlab.com/grahamcampbell/php:$7.4-cli analyse

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v2
2222
- name: Run Composer
23-
run: docker run --rm -w /data -v ${{ github.workspace }}:/data --entrypoint composer registry.gitlab.com/grahamcampbell/php:${{ matrix.php }}-base install --prefer-dist -n -o
23+
run: docker run --rm -w /data -v ${{ github.workspace }}:/data --entrypoint composer registry.gitlab.com/grahamcampbell/php:${{ matrix.php }}-base update --prefer-dist -n -o
2424
- name: Run PHPUnit
2525
run: docker run --rm -w /data -v ${{ github.workspace }}:/data --entrypoint vendor/bin/phpunit registry.gitlab.com/grahamcampbell/php:${{ matrix.php }}-cli

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.phpunit.result.cache
22
composer.lock
3+
phpstan.neon
34
phpunit.xml
45
vendor

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"psr/http-message": "^1.0"
2222
},
2323
"require-dev": {
24-
"graham-campbell/analyzer": "^2.4",
24+
"bamarni/composer-bin-plugin": "^1.4.1",
25+
"graham-campbell/analyzer": "^3.0",
2526
"phpunit/phpunit": "^8.5|^9.0",
2627
"php-http/guzzle6-adapter": "^2.0",
2728
"php-http/mock-client": "^1.3"
@@ -38,7 +39,5 @@
3839
},
3940
"config": {
4041
"preferred-install": "dist"
41-
},
42-
"minimum-stability": "dev",
43-
"prefer-stable": true
42+
}
4443
}

phpstan-baseline.neon

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Anonymous function should have native return typehint \"string\"\\.$#"
5+
count: 1
6+
path: src/Api/AbstractApi.php
7+
8+
-
9+
message: "#^Anonymous function should have native return typehint \"bool\"\\.$#"
10+
count: 1
11+
path: src/HttpClient/Message/ResponseMediator.php
12+
13+
-
14+
message: "#^Anonymous function should have native return typehint \"Psr\\\\Http\\\\Message\\\\ResponseInterface\"\\.$#"
15+
count: 1
16+
path: src/HttpClient/Plugin/ExceptionThrower.php
17+
18+
-
19+
message: "#^Variable method call on Bitbucket\\\\Api\\\\ApiInterface\\.$#"
20+
count: 1
21+
path: src/ResultPager.php
22+
23+
-
24+
message: "#^Offset string does not exist on array\\|null\\.$#"
25+
count: 1
26+
path: src/ResultPager.php
27+

phpstan.neon.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: max
6+
paths:
7+
- src
8+
checkMissingIterableValueType: false

src/Api/AbstractApi.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Bitbucket\Exception\InvalidArgumentException;
1717
use Bitbucket\HttpClient\Message\ResponseMediator;
18+
use Bitbucket\JsonArray;
1819
use Http\Client\Common\HttpMethodsClientInterface;
1920

2021
/**
@@ -125,7 +126,7 @@ protected function pureGet(string $path, array $params = [], array $headers = []
125126
$params['pagelen'] = $this->perPage;
126127
}
127128

128-
if ($params) {
129+
if (count($params) === 0) {
129130
$path .= '?'.http_build_query($params);
130131
}
131132

@@ -147,7 +148,7 @@ protected function post(string $path, array $params = [], array $headers = [])
147148
{
148149
$body = self::createJsonBody($params);
149150

150-
if ($body) {
151+
if ($body !== null) {
151152
$headers = self::addJsonContentType($headers);
152153
}
153154

@@ -187,7 +188,7 @@ protected function put(string $path, array $params = [], array $headers = [])
187188
{
188189
$body = self::createJsonBody($params);
189190

190-
if ($body) {
191+
if ($body !== null) {
191192
$headers = self::addJsonContentType($headers);
192193
}
193194

@@ -227,7 +228,7 @@ protected function delete(string $path, array $params = [], array $headers = [])
227228
{
228229
$body = self::createJsonBody($params);
229230

230-
if ($body) {
231+
if ($body !== null) {
231232
$headers = self::addJsonContentType($headers);
232233
}
233234

@@ -255,16 +256,16 @@ protected function deleteRaw(string $path, $body = null, array $headers = [])
255256
/**
256257
* Build a URL path from the given parts.
257258
*
258-
* @param string[] $parts
259+
* @param string ...$parts
259260
*
260261
* @throws \Bitbucket\Exception\InvalidArgumentException
261262
*
262263
* @return string
263264
*/
264265
protected static function buildPath(string ...$parts)
265266
{
266-
$parts = array_map(function (string $part) {
267-
if (!$part) {
267+
$parts = array_map(function (string $part) {
268+
if ($part === '') {
268269
throw new InvalidArgumentException('Missing required parameter.');
269270
}
270271

@@ -295,17 +296,19 @@ private static function computePath(string $path)
295296
*/
296297
private static function createJsonBody(array $params)
297298
{
298-
if ($params) {
299-
return json_encode($params);
299+
if (count($params) === 0) {
300+
return JsonArray::encode($params);
300301
}
302+
303+
return null;
301304
}
302305

303306
/**
304307
* Add the JSON content type to the headers if one is not already present.
305308
*
306-
* @param array $headers
309+
* @param array<string,string> $headers
307310
*
308-
* @return array
311+
* @return array<string,string>
309312
*/
310313
private static function addJsonContentType(array $headers)
311314
{

src/Api/Addon.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function users()
7070
/**
7171
* Build the addon path from the given parts.
7272
*
73-
* @param string[] $parts
73+
* @param string ...$parts
7474
*
7575
* @throws \Bitbucket\Exception\InvalidArgumentException
7676
*

src/Api/Addon/Linkers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function values(string $linker)
6464
/**
6565
* Build the linkers path from the given parts.
6666
*
67-
* @param string[] $parts
67+
* @param string ...$parts
6868
*
6969
* @throws \Bitbucket\Exception\InvalidArgumentException
7070
*

0 commit comments

Comments
 (0)