Skip to content

Commit 3cd5680

Browse files
Merge branch '9.19' into 10.0
2 parents 0c24cd6 + 661f391 commit 3cd5680

Some content is hidden

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

50 files changed

+303
-140
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
/psalm.xml export-ignore
1515
/CHANGELOG.md export-ignore
1616
/README.md export-ignore
17+
/rector.yml export-ignore

.github/workflows/static.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,42 @@ jobs:
6868

6969
- name: Execute Psalm
7070
run: vendor/bin/psalm --no-progress --output-format=github
71+
72+
rector:
73+
name: Rector
74+
runs-on: ubuntu-20.04
75+
76+
steps:
77+
- name: Checkout code
78+
uses: actions/checkout@v2
79+
80+
- name: Setup PHP
81+
uses: shivammathur/setup-php@v2
82+
with:
83+
php-version: 7.4
84+
tools: composer:v2, cs2pr
85+
coverage: none
86+
87+
- name: Install Dependencies
88+
uses: nick-invision/retry@v1
89+
with:
90+
timeout_minutes: 5
91+
max_attempts: 5
92+
command: composer update --no-interaction --no-progress
93+
94+
- name: Install PHPUnit
95+
uses: nick-invision/retry@v1
96+
with:
97+
timeout_minutes: 5
98+
max_attempts: 5
99+
command: composer bin phpunit update --no-interaction --no-progress
100+
101+
- name: Install Rector
102+
uses: nick-invision/retry@v1
103+
with:
104+
timeout_minutes: 5
105+
max_attempts: 5
106+
command: composer bin rector update --no-interaction --no-progress
107+
108+
- name: Execute Rector
109+
run: vendor/bin/rector process --dry-run --output-format=checkstyle | cs2pr

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ psalm-baseline:
2020
psalm-show-info:
2121
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/psalm --rm registry.gitlab.com/grahamcampbell/php:7.4-cli --show-info=true
2222

23-
test: phpunit phpstan-analyze psalm-analyze
23+
rector-dry-run:
24+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/rector --rm registry.gitlab.com/grahamcampbell/php:7.4-cli process --dry-run
25+
26+
rector-fix:
27+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/rector --rm registry.gitlab.com/grahamcampbell/php:7.4-cli process
28+
29+
test: phpunit phpstan-analyze psalm-analyze rector-dry-run
2430

2531
clean:
2632
@rm -rf .phpunit.result.cache composer.lock vendor vendor-bin/*/composer.lock vendor-bin/*/vendor

rector.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
parameters:
2+
autoload_paths:
3+
- 'vendor/autoload.php'
4+
- 'vendor-bin/phpunit/vendor/autoload.php'
5+
auto_import_names: true
6+
import_short_classes: false
7+
import_doc_blocks: false
8+
php_version_features: '5.6'
9+
paths:
10+
- 'src'
11+
- 'tests'
12+
sets:
13+
- 'code-quality'
14+
- 'php52'
15+
- 'php53'
16+
- 'php54'
17+
- 'php55'
18+
- 'php56'
19+
- 'phpunit40'
20+
- 'phpunit50'
21+
22+
services:
23+
Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector: ~
24+
Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector: ~
25+
Rector\DeadCode\Rector\Assign\RemoveAssignOfVoidReturnFunctionRector: ~
26+
Rector\DeadCode\Rector\FunctionLike\RemoveCodeAfterReturnRector: ~
27+
Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector: ~
28+
Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector: ~
29+
Rector\DeadCode\Rector\Stmt\RemoveDeadStmtRector: ~
30+
Rector\DeadCode\Rector\TryCatch\RemoveDeadTryCatchRector: ~
31+
Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector: ~
32+
Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector: ~
33+
Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector: ~
34+
Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector: ~
35+
Rector\DeadCode\Rector\FunctionLike\RemoveDuplicatedIfReturnRector: ~
36+
Rector\DeadCode\Rector\Instanceof_\RemoveDuplicatedInstanceOfRector: ~
37+
Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector: ~
38+
Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector: ~
39+
Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector: ~
40+
Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector: ~
41+
Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateConstantRector: ~
42+
Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector: ~
43+
Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector: ~
44+
Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector: ~
45+
Rector\DeadCode\Rector\If_\SimplifyIfElseWithSameContentRector: ~
46+
Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector: ~
47+
Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector: ~
48+
Rector\Performance\Rector\FuncCall\PreslashSimpleFunctionRector: ~
49+
Rector\SOLID\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector: ~
50+
Rector\SOLID\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector: ~
51+
Rector\SOLID\Rector\If_\ChangeNestedIfsToEarlyReturnRector: ~
52+
Rector\SOLID\Rector\If_\RemoveAlwaysElseRector: ~

src/Api/AbstractApi.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ abstract class AbstractApi implements ApiInterface
5353
public function __construct(Client $client, int $perPage = null)
5454
{
5555
if (null !== $perPage && ($perPage < 1 || $perPage > 100)) {
56-
throw new ValueError(sprintf('%s::__construct(): Argument #2 ($perPage) must be between 1 and 100, or null', self::class));
56+
throw new ValueError(\sprintf('%s::__construct(): Argument #2 ($perPage) must be between 1 and 100, or null', self::class));
5757
}
5858

5959
$this->client = $client;
@@ -72,7 +72,7 @@ public function __construct(Client $client, int $perPage = null)
7272
public function perPage(?int $perPage)
7373
{
7474
if (null !== $perPage && ($perPage < 1 || $perPage > 100)) {
75-
throw new ValueError(sprintf('%s::perPage(): Argument #1 ($perPage) must be between 1 and 100, or null', self::class));
75+
throw new ValueError(\sprintf('%s::perPage(): Argument #1 ($perPage) must be between 1 and 100, or null', self::class));
7676
}
7777

7878
$copy = clone $this;
@@ -126,7 +126,7 @@ protected function get($uri, array $params = [], array $headers = [])
126126
*/
127127
protected function post($uri, array $params = [], array $headers = [], array $files = [])
128128
{
129-
if (0 < count($files)) {
129+
if (0 < \count($files)) {
130130
$builder = $this->createMultipartStreamBuilder($params, $files);
131131
$body = self::prepareMultipartBody($builder);
132132
$headers = self::addMultipartContentType($headers, $builder);
@@ -153,7 +153,7 @@ protected function post($uri, array $params = [], array $headers = [], array $fi
153153
*/
154154
protected function put($uri, array $params = [], array $headers = [], array $files = [])
155155
{
156-
if (0 < count($files)) {
156+
if (0 < \count($files)) {
157157
$builder = $this->createMultipartStreamBuilder($params, $files);
158158
$body = self::prepareMultipartBody($builder);
159159
$headers = self::addMultipartContentType($headers, $builder);
@@ -197,7 +197,7 @@ protected function delete($uri, array $params = [], array $headers = [])
197197
*/
198198
protected static function encodePath($uri)
199199
{
200-
return rawurlencode((string) $uri);
200+
return \rawurlencode((string) $uri);
201201
}
202202

203203
/**
@@ -256,11 +256,11 @@ protected function createOptionsResolver()
256256
*/
257257
private static function prepareUri(string $uri, array $query = [])
258258
{
259-
$query = array_filter($query, function ($value): bool {
259+
$query = \array_filter($query, function ($value): bool {
260260
return null !== $value;
261261
});
262262

263-
return sprintf('%s%s%s', self::URI_PREFIX, $uri, QueryStringBuilder::build($query));
263+
return \sprintf('%s%s%s', self::URI_PREFIX, $uri, QueryStringBuilder::build($query));
264264
}
265265

266266
/**
@@ -284,7 +284,7 @@ private function createMultipartStreamBuilder(array $params = [], array $files =
284284
'headers' => [
285285
'Content-Type' => self::guessFileContentType($file),
286286
],
287-
'filename' => basename($file),
287+
'filename' => \basename($file),
288288
]);
289289
}
290290

@@ -313,9 +313,9 @@ private static function prepareMultipartBody(MultipartStreamBuilder $builder)
313313
*/
314314
private static function addMultipartContentType(array $headers, MultipartStreamBuilder $builder)
315315
{
316-
$contentType = sprintf('%s; boundary=%s', ResponseMediator::MULTIPART_CONTENT_TYPE, $builder->getBoundary());
316+
$contentType = \sprintf('%s; boundary=%s', ResponseMediator::MULTIPART_CONTENT_TYPE, $builder->getBoundary());
317317

318-
return array_merge(['Content-Type' => $contentType], $headers);
318+
return \array_merge(['Content-Type' => $contentType], $headers);
319319
}
320320

321321
/**
@@ -327,11 +327,11 @@ private static function addMultipartContentType(array $headers, MultipartStreamB
327327
*/
328328
private static function prepareJsonBody(array $params)
329329
{
330-
$params = array_filter($params, function ($value): bool {
330+
$params = \array_filter($params, function ($value): bool {
331331
return null !== $value;
332332
});
333333

334-
if (0 === count($params)) {
334+
if (0 === \count($params)) {
335335
return null;
336336
}
337337

@@ -347,7 +347,7 @@ private static function prepareJsonBody(array $params)
347347
*/
348348
private static function addJsonContentType(array $headers)
349349
{
350-
return array_merge(['Content-Type' => ResponseMediator::JSON_CONTENT_TYPE], $headers);
350+
return \array_merge(['Content-Type' => ResponseMediator::JSON_CONTENT_TYPE], $headers);
351351
}
352352

353353
/**
@@ -368,17 +368,17 @@ private static function addJsonContentType(array $headers)
368368
private static function tryFopen($filename, $mode)
369369
{
370370
$ex = null;
371-
set_error_handler(function () use ($filename, $mode, &$ex) {
372-
$ex = new RuntimeException(sprintf(
371+
\set_error_handler(function () use ($filename, $mode, &$ex) {
372+
$ex = new RuntimeException(\sprintf(
373373
'Unable to open %s using mode %s: %s',
374374
$filename,
375375
$mode,
376-
func_get_args()[1]
376+
\func_get_args()[1]
377377
));
378378
});
379379

380-
$handle = fopen($filename, $mode);
381-
restore_error_handler();
380+
$handle = \fopen($filename, $mode);
381+
\restore_error_handler();
382382

383383
if (null !== $ex) {
384384
throw $ex;
@@ -397,7 +397,7 @@ private static function tryFopen($filename, $mode)
397397
*/
398398
private static function guessFileContentType(string $file)
399399
{
400-
if (!class_exists(\finfo::class, false)) {
400+
if (!\class_exists(\finfo::class, false)) {
401401
return ResponseMediator::STREAM_CONTENT_TYPE;
402402
}
403403

src/Api/Groups.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function create($name, $path, $description = null, $visibility = 'private
6565
'shared_runners_minutes_limit' => $shared_runners_minutes_limit,
6666
];
6767

68-
return $this->post('groups', array_filter($params, function ($value) {
69-
return null !== $value && (!is_string($value) || strlen($value) > 0);
68+
return $this->post('groups', \array_filter($params, function ($value) {
69+
return null !== $value && (!\is_string($value) || \strlen($value) > 0);
7070
}));
7171
}
7272

@@ -424,7 +424,7 @@ private function getGroupSearchResolver()
424424
$resolver->setDefined('skip_groups')
425425
->setAllowedTypes('skip_groups', 'array')
426426
->setAllowedValues('skip_groups', function (array $value) {
427-
return count($value) == count(array_filter($value, 'is_int'));
427+
return \count($value) === \count(\array_filter($value, 'is_int'));
428428
})
429429
;
430430
$resolver->setDefined('all_available')

src/Api/GroupsMilestones.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function all($group_id, array $parameters = [])
2727
$resolver->setDefined('iids')
2828
->setAllowedTypes('iids', 'array')
2929
->setAllowedValues('iids', function (array $value) {
30-
return count($value) == count(array_filter($value, 'is_int'));
30+
return \count($value) === \count(\array_filter($value, 'is_int'));
3131
})
3232
;
3333
$resolver->setDefined('state')

src/Api/Issues.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ protected function createOptionsResolver()
417417
$resolver->setDefined('iids')
418418
->setAllowedTypes('iids', 'array')
419419
->setAllowedValues('iids', function (array $value) {
420-
return count($value) == count(array_filter($value, 'is_int'));
420+
return \count($value) === \count(\array_filter($value, 'is_int'));
421421
})
422422
;
423423
$resolver->setDefined('scope')

src/Api/Jobs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected function createOptionsResolver()
201201
->setAllowedTypes('scope', ['string', 'array'])
202202
->setAllowedValues('scope', $allowedScopeValues)
203203
->addAllowedValues('scope', function ($value) use ($allowedScopeValues) {
204-
return is_array($value) && 0 === count(array_diff($value, $allowedScopeValues));
204+
return \is_array($value) && 0 === \count(\array_diff($value, $allowedScopeValues));
205205
})
206206
->setNormalizer('scope', function (OptionsResolver $resolver, $value) {
207207
return (array) $value;

src/Api/MergeRequests.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function all($project_id = null, array $parameters = [])
5050
$resolver->setDefined('iids')
5151
->setAllowedTypes('iids', 'array')
5252
->setAllowedValues('iids', function (array $value) {
53-
return count($value) == count(array_filter($value, 'is_int'));
53+
return \count($value) === \count(\array_filter($value, 'is_int'));
5454
})
5555
;
5656
$resolver->setDefined('state')
@@ -154,7 +154,7 @@ public function create($project_id, $source, $target, $title, array $parameters
154154

155155
return $this->post(
156156
$this->getProjectPath($project_id, 'merge_requests'),
157-
array_merge($baseParams, $parameters)
157+
\array_merge($baseParams, $parameters)
158158
);
159159
}
160160

@@ -481,7 +481,7 @@ public function createLevelRule($project_id, $mr_iid, $name, $approvals_required
481481

482482
return $this->post(
483483
$this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/approval_rules'),
484-
array_merge($baseParam, $parameters)
484+
\array_merge($baseParam, $parameters)
485485
);
486486
}
487487

@@ -504,7 +504,7 @@ public function updateLevelRule($project_id, $mr_iid, $approval_rule_id, $name,
504504

505505
return $this->put(
506506
$this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/approval_rules/'.self::encodePath($approval_rule_id)),
507-
array_merge($baseParam, $parameters)
507+
\array_merge($baseParam, $parameters)
508508
);
509509
}
510510

0 commit comments

Comments
 (0)