Skip to content

Commit 2ee0dd9

Browse files
authored
Modernize code with rector (#3139)
1 parent 74f219c commit 2ee0dd9

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"mockery/mockery": "^1.4.4",
4242
"doctrine/coding-standard": "12.0.x-dev",
4343
"spatie/laravel-query-builder": "^5.6",
44-
"phpstan/phpstan": "^1.10"
44+
"phpstan/phpstan": "^1.10",
45+
"rector/rector": "^1.2"
4546
},
4647
"suggest": {
4748
"league/flysystem-gridfs": "Filesystem storage in MongoDB with GridFS",
@@ -73,7 +74,8 @@
7374
"test": "phpunit",
7475
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
7576
"cs": "phpcs",
76-
"cs:fix": "phpcbf"
77+
"cs:fix": "phpcbf",
78+
"rector": "rector"
7779
},
7880
"config": {
7981
"allow-plugins": {

rector.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Rector\Config\RectorConfig;
4+
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
5+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
6+
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
7+
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
8+
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
9+
10+
return RectorConfig::configure()
11+
->withPaths([
12+
__FILE__,
13+
__DIR__ . '/docs',
14+
__DIR__ . '/src',
15+
__DIR__ . '/tests',
16+
])
17+
->withPhpSets()
18+
->withTypeCoverageLevel(0)
19+
->withSkip([
20+
RemoveExtraParametersRector::class,
21+
ClosureToArrowFunctionRector::class,
22+
NullToStrictStringFuncCallArgRector::class,
23+
MixedTypeRector::class,
24+
AddClosureVoidReturnTypeWhereNoReturnRector::class,
25+
]);

src/Bus/MongoBatchRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// are called by PruneBatchesCommand
2929
class MongoBatchRepository extends DatabaseBatchRepository implements PrunableBatchRepository
3030
{
31-
private Collection $collection;
31+
private readonly Collection $collection;
3232

3333
public function __construct(
3434
BatchFactory $factory,

src/Helpers/QueriesRelationships.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
use function array_map;
2222
use function class_basename;
2323
use function collect;
24-
use function get_class;
2524
use function in_array;
2625
use function is_array;
2726
use function is_string;
2827
use function method_exists;
29-
use function strpos;
28+
use function str_contains;
3029

3130
trait QueriesRelationships
3231
{
@@ -45,7 +44,7 @@ trait QueriesRelationships
4544
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', ?Closure $callback = null)
4645
{
4746
if (is_string($relation)) {
48-
if (strpos($relation, '.') !== false) {
47+
if (str_contains($relation, '.')) {
4948
return $this->hasNested($relation, $operator, $count, $boolean, $callback);
5049
}
5150

@@ -139,7 +138,7 @@ private function handleMorphToMany($hasQuery, $relation)
139138
{
140139
// First we select the parent models that have a relation to our related model,
141140
// Then extracts related model's ids from the pivot column
142-
$hasQuery->where($relation->getTable() . '.' . $relation->getMorphType(), get_class($relation->getParent()));
141+
$hasQuery->where($relation->getTable() . '.' . $relation->getMorphType(), $relation->getParent()::class);
143142
$relations = $hasQuery->pluck($relation->getTable());
144143
$relations = $relation->extractIds($relations->flatten(1)->toArray(), $relation->getForeignPivotKeyName());
145144

src/Query/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ protected function performUpdate(array $update, array $options = [])
10791079
$wheres = $this->aliasIdForQuery($wheres);
10801080
$result = $this->collection->updateMany($wheres, $update, $options);
10811081
if ($result->isAcknowledged()) {
1082-
return $result->getModifiedCount() ? $result->getModifiedCount() : $result->getUpsertedCount();
1082+
return $result->getModifiedCount() ?: $result->getUpsertedCount();
10831083
}
10841084

10851085
return 0;

tests/PHPStan/SarifErrorFormatter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class SarifErrorFormatter implements ErrorFormatter
2626
private const URI_BASE_ID = 'WORKINGDIR';
2727

2828
public function __construct(
29-
private RelativePathHelper $relativePathHelper,
30-
private string $currentWorkingDirectory,
31-
private bool $pretty,
29+
private readonly RelativePathHelper $relativePathHelper,
30+
private readonly string $currentWorkingDirectory,
31+
private readonly bool $pretty,
3232
) {
3333
}
3434

0 commit comments

Comments
 (0)