Skip to content

Commit

Permalink
Modernize code with rector (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Sep 6, 2024
1 parent 74f219c commit 2ee0dd9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"mockery/mockery": "^1.4.4",
"doctrine/coding-standard": "12.0.x-dev",
"spatie/laravel-query-builder": "^5.6",
"phpstan/phpstan": "^1.10"
"phpstan/phpstan": "^1.10",
"rector/rector": "^1.2"
},
"suggest": {
"league/flysystem-gridfs": "Filesystem storage in MongoDB with GridFS",
Expand Down Expand Up @@ -73,7 +74,8 @@
"test": "phpunit",
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
"cs": "phpcs",
"cs:fix": "phpcbf"
"cs:fix": "phpcbf",
"rector": "rector"
},
"config": {
"allow-plugins": {
Expand Down
25 changes: 25 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__FILE__,
__DIR__ . '/docs',
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets()
->withTypeCoverageLevel(0)
->withSkip([
RemoveExtraParametersRector::class,
ClosureToArrowFunctionRector::class,
NullToStrictStringFuncCallArgRector::class,
MixedTypeRector::class,
AddClosureVoidReturnTypeWhereNoReturnRector::class,
]);
2 changes: 1 addition & 1 deletion src/Bus/MongoBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// are called by PruneBatchesCommand
class MongoBatchRepository extends DatabaseBatchRepository implements PrunableBatchRepository
{
private Collection $collection;
private readonly Collection $collection;

public function __construct(
BatchFactory $factory,
Expand Down
7 changes: 3 additions & 4 deletions src/Helpers/QueriesRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
use function array_map;
use function class_basename;
use function collect;
use function get_class;
use function in_array;
use function is_array;
use function is_string;
use function method_exists;
use function strpos;
use function str_contains;

trait QueriesRelationships
{
Expand All @@ -45,7 +44,7 @@ trait QueriesRelationships
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', ?Closure $callback = null)
{
if (is_string($relation)) {
if (strpos($relation, '.') !== false) {
if (str_contains($relation, '.')) {
return $this->hasNested($relation, $operator, $count, $boolean, $callback);
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ protected function performUpdate(array $update, array $options = [])
$wheres = $this->aliasIdForQuery($wheres);
$result = $this->collection->updateMany($wheres, $update, $options);
if ($result->isAcknowledged()) {
return $result->getModifiedCount() ? $result->getModifiedCount() : $result->getUpsertedCount();
return $result->getModifiedCount() ?: $result->getUpsertedCount();
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/SarifErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class SarifErrorFormatter implements ErrorFormatter
private const URI_BASE_ID = 'WORKINGDIR';

public function __construct(
private RelativePathHelper $relativePathHelper,
private string $currentWorkingDirectory,
private bool $pretty,
private readonly RelativePathHelper $relativePathHelper,
private readonly string $currentWorkingDirectory,
private readonly bool $pretty,
) {
}

Expand Down

0 comments on commit 2ee0dd9

Please sign in to comment.