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
*

src/Api/Addon/Linkers/Values.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function remove(string $id, array $params = [])
9696
/**
9797
* Build the values path from the given parts.
9898
*
99-
* @param string[] $parts
99+
* @param string ...$parts
100100
*
101101
* @throws \Bitbucket\Exception\InvalidArgumentException
102102
*

src/Api/Addon/Users/Events.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function create(string $event, array $params = [])
3838
/**
3939
* Build the events path from the given parts.
4040
*
41-
* @param string[] $parts
41+
* @param string ...$parts
4242
*
4343
* @throws \Bitbucket\Exception\InvalidArgumentException
4444
*

src/Api/CurrentUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function listWorkspaces(array $params = [])
122122
/**
123123
* Build the current user path from the given parts.
124124
*
125-
* @param string[] $parts
125+
* @param string ...$parts
126126
*
127127
* @throws \Bitbucket\Exception\InvalidArgumentException
128128
*

src/Api/HookEvents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function listWorkspaceEvents(array $params = [])
7979
/**
8080
* Build the hook events path from the given parts.
8181
*
82-
* @param string[] $parts
82+
* @param string ...$parts
8383
*
8484
* @throws \Bitbucket\Exception\InvalidArgumentException
8585
*

src/Api/PullRequests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function list(string $username, array $params = [])
3838
/**
3939
* Build the pull requests path from the given parts.
4040
*
41-
* @param string[] $parts
41+
* @param string ...$parts
4242
*
4343
* @throws \Bitbucket\Exception\InvalidArgumentException
4444
*

src/Api/Repositories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function workspaces(string $workspace)
4949
/**
5050
* Build the repositories path from the given parts.
5151
*
52-
* @param string[] $parts
52+
* @param string ...$parts
5353
*
5454
* @throws \Bitbucket\Exception\InvalidArgumentException
5555
*

src/Api/Repositories/Workspaces.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function issues(string $repo)
285285
/**
286286
* @param string $repo
287287
*
288-
* @return \Bitbucket\Api\Repositories\Workspaces\Patches
288+
* @return \Bitbucket\Api\Repositories\Workspaces\MergeBases
289289
*/
290290
public function mergeBases(string $repo)
291291
{
@@ -395,7 +395,7 @@ public function watchers(string $repo)
395395
/**
396396
* Build the workspaces path from the given parts.
397397
*
398-
* @param string[] $parts
398+
* @param string ...$parts
399399
*
400400
* @throws \Bitbucket\Exception\InvalidArgumentException
401401
*

src/Api/Repositories/Workspaces/BranchRestrictions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function remove(string $restriction, array $params = [])
9696
/**
9797
* Build the branch restrictions path from the given parts.
9898
*
99-
* @param string[] $parts
99+
* @param string ...$parts
100100
*
101101
* @throws \Bitbucket\Exception\InvalidArgumentException
102102
*

src/Api/Repositories/Workspaces/BranchingModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function updateSettings(array $params = [])
6565
/**
6666
* Build the branching model path from the given parts.
6767
*
68-
* @param string[] $parts
68+
* @param string ...$parts
6969
*
7070
* @throws \Bitbucket\Exception\InvalidArgumentException
7171
*

src/Api/Repositories/Workspaces/Commit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function statuses(string $commit)
105105
/**
106106
* Build the commit path from the given parts.
107107
*
108-
* @param string[] $parts
108+
* @param string ...$parts
109109
*
110110
* @throws \Bitbucket\Exception\InvalidArgumentException
111111
*

src/Api/Repositories/Workspaces/Commit/Approval.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function redact(array $params = [])
5151
/**
5252
* Build the approval path from the given parts.
5353
*
54-
* @param string[] $parts
54+
* @param string ...$parts
5555
*
5656
* @throws \Bitbucket\Exception\InvalidArgumentException
5757
*

src/Api/Repositories/Workspaces/Commit/Comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function show(string $comment, array $params = [])
6666
/**
6767
* Build the comments path from the given parts.
6868
*
69-
* @param string[] $parts
69+
* @param string ...$parts
7070
*
7171
* @throws \Bitbucket\Exception\InvalidArgumentException
7272
*

src/Api/Repositories/Workspaces/Commit/Properties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function remove(string $app, string $property, array $params = [])
7171
/**
7272
* Build the properties path from the given parts.
7373
*
74-
* @param string[] $parts
74+
* @param string ...$parts
7575
*
7676
* @throws \Bitbucket\Exception\InvalidArgumentException
7777
*

src/Api/Repositories/Workspaces/Commit/PullRequests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function list(array $params = [])
3737
/**
3838
* Build the pull requests path from the given parts.
3939
*
40-
* @param string[] $parts
40+
* @param string ...$parts
4141
*
4242
* @throws \Bitbucket\Exception\InvalidArgumentException
4343
*

src/Api/Repositories/Workspaces/Commit/Reports.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function annotations()
7676
/**
7777
* Build the reports path from the given parts.
7878
*
79-
* @param string[] $parts
79+
* @param string ...$parts
8080
*
8181
* @throws \Bitbucket\Exception\InvalidArgumentException
8282
*

src/Api/Repositories/Workspaces/Commit/Reports/Annotations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function remove(string $annotation, array $params = [])
9696
/**
9797
* Annotations the build path from the given parts.
9898
*
99-
* @param string[] $parts
99+
* @param string ...$parts
100100
*
101101
* @throws \Bitbucket\Exception\InvalidArgumentException
102102
*

src/Api/Repositories/Workspaces/Commit/Statuses.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function build()
4747
/**
4848
* Build the statuses path from the given parts.
4949
*
50-
* @param string[] $parts
50+
* @param string ...$parts
5151
*
5252
* @throws \Bitbucket\Exception\InvalidArgumentException
5353
*

src/Api/Repositories/Workspaces/Commit/Statuses/Build.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function update(string $key, array $params = [])
6767
/**
6868
* Build the build path from the given parts.
6969
*
70-
* @param string[] $parts
70+
* @param string ...$parts
7171
*
7272
* @throws \Bitbucket\Exception\InvalidArgumentException
7373
*

src/Api/Repositories/Workspaces/Commits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function show(string $commit, array $params = [])
5252
/**
5353
* Build the commits path from the given parts.
5454
*
55-
* @param string[] $parts
55+
* @param string ...$parts
5656
*
5757
* @throws \Bitbucket\Exception\InvalidArgumentException
5858
*

0 commit comments

Comments
 (0)