diff --git a/composer.json b/composer.json index f03fdc89d..4d679a95c 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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": { diff --git a/rector.php b/rector.php new file mode 100644 index 000000000..23afcb2ea --- /dev/null +++ b/rector.php @@ -0,0 +1,25 @@ +withPaths([ + __FILE__, + __DIR__ . '/docs', + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPhpSets() + ->withTypeCoverageLevel(0) + ->withSkip([ + RemoveExtraParametersRector::class, + ClosureToArrowFunctionRector::class, + NullToStrictStringFuncCallArgRector::class, + MixedTypeRector::class, + AddClosureVoidReturnTypeWhereNoReturnRector::class, + ]); diff --git a/src/Bus/MongoBatchRepository.php b/src/Bus/MongoBatchRepository.php index c6314ba69..2656bbc30 100644 --- a/src/Bus/MongoBatchRepository.php +++ b/src/Bus/MongoBatchRepository.php @@ -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, diff --git a/src/Helpers/QueriesRelationships.php b/src/Helpers/QueriesRelationships.php index 933b6ec32..1f1ffa34b 100644 --- a/src/Helpers/QueriesRelationships.php +++ b/src/Helpers/QueriesRelationships.php @@ -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 { @@ -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); } @@ -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()); diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 9b446f8e8..2bbd5a01a 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -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; diff --git a/tests/PHPStan/SarifErrorFormatter.php b/tests/PHPStan/SarifErrorFormatter.php index 1fb814cde..92c0255cc 100644 --- a/tests/PHPStan/SarifErrorFormatter.php +++ b/tests/PHPStan/SarifErrorFormatter.php @@ -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, ) { }