Skip to content

Commit 47805a5

Browse files
committed
Modernize code with rector
1 parent e780aea commit 47805a5

File tree

6 files changed

+36
-11
lines changed

6 files changed

+36
-11
lines changed

rector.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// uncomment to reach your current PHP version
18+
->withPhpSets(php82: true)
19+
->withTypeCoverageLevel(0)
20+
->withSkip([
21+
RemoveExtraParametersRector::class,
22+
ClosureToArrowFunctionRector::class,
23+
NullToStrictStringFuncCallArgRector::class,
24+
MixedTypeRector::class,
25+
AddClosureVoidReturnTypeWhereNoReturnRector::class,
26+
]);

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;

src/Schema/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public function table($table, Closure $callback)
8383
}
8484

8585
/** @inheritdoc */
86-
public function create($table, ?Closure $callback = null, array $options = [])
86+
public function create($table, ?Closure $callback = null)
8787
{
8888
$blueprint = $this->createBlueprint($table);
8989

90-
$blueprint->create($options);
90+
$blueprint->create();
9191

9292
if ($callback) {
9393
$callback($blueprint);

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)