From b80dbb6a592eb1c0dd281c3a9db6a38cb45a5c3c Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Sat, 28 Dec 2024 00:47:53 +0100 Subject: [PATCH 1/7] Use PHP 8 str* methods for clarity --- src/Snapshot.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Snapshot.php b/src/Snapshot.php index dcde77b..ee61326 100644 --- a/src/Snapshot.php +++ b/src/Snapshot.php @@ -78,7 +78,7 @@ protected function loadAsync(string $connectionName = null) protected function isASqlComment(string $line): bool { - return substr($line, 0, 2) === '--'; + return str_starts_with($line, '--'); } protected function shouldIgnoreLine(string $line): bool @@ -116,14 +116,14 @@ protected function loadStream(string $connectionName = null) break; } - if (substr(trim($statement), -1, 1) === ';') { + if (str_ends_with(trim($statement), ';')) { yield $statement; $statement = ''; } } } - if (substr(trim($statement), -1, 1) === ';') { + if (str_ends_with(trim($statement), ';')) { yield $statement; } })->each(function (string $statement) use ($connectionName) { From 6940fe7656b71d2cc57347ef018b5006a7e8f8b9 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Sat, 28 Dec 2024 00:49:02 +0100 Subject: [PATCH 2/7] Mark parameters nullable explicitly Implicit nullability is deprecated as of PHP 8.4. --- src/Snapshot.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Snapshot.php b/src/Snapshot.php index ee61326..ce0ad1d 100644 --- a/src/Snapshot.php +++ b/src/Snapshot.php @@ -48,7 +48,7 @@ public function useStream() return $this; } - public function load(string $connectionName = null, bool $dropTables = true): void + public function load(?string $connectionName = null, bool $dropTables = true): void { event(new LoadingSnapshot($this)); @@ -65,7 +65,7 @@ public function load(string $connectionName = null, bool $dropTables = true): vo event(new LoadedSnapshot($this)); } - protected function loadAsync(string $connectionName = null) + protected function loadAsync(?string $connectionName = null) { $dbDumpContents = $this->disk->get($this->fileName); @@ -88,7 +88,7 @@ protected function shouldIgnoreLine(string $line): bool return empty($line) || $this->isASqlComment($line); } - protected function loadStream(string $connectionName = null) + protected function loadStream(?string $connectionName = null) { LazyCollection::make(function () { $stream = $this->compressionExtension === 'gz' From d05e3fdc0a3cff69cc9ad1c52f50237ec13243a3 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Sat, 28 Dec 2024 00:59:05 +0100 Subject: [PATCH 3/7] Fix typo --- src/Exceptions/CannotCreateDisk.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exceptions/CannotCreateDisk.php b/src/Exceptions/CannotCreateDisk.php index 2b42e75..8484f12 100644 --- a/src/Exceptions/CannotCreateDisk.php +++ b/src/Exceptions/CannotCreateDisk.php @@ -16,6 +16,6 @@ public static function diskNotDefined(string $diskName): static $existingDiskNames = implode(', ', array_keys($disks)); - return new static("Cannot create a disk `{$diskName}`. Known disknames are {$existingDiskNames}."); + return new static("Cannot create a disk `{$diskName}`. Known disk names are {$existingDiskNames}."); } } From 255603c751110846a38865149befe3d3f68961ec Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Sat, 28 Dec 2024 01:03:41 +0100 Subject: [PATCH 4/7] Add missing typehints --- src/Commands/Cleanup.php | 3 ++- src/Snapshot.php | 8 ++++---- src/SnapshotRepository.php | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Commands/Cleanup.php b/src/Commands/Cleanup.php index fe65f0c..50b6ce2 100644 --- a/src/Commands/Cleanup.php +++ b/src/Commands/Cleanup.php @@ -3,6 +3,7 @@ namespace Spatie\DbSnapshots\Commands; use Illuminate\Console\Command; +use Spatie\DbSnapshots\Snapshot; use Spatie\DbSnapshots\SnapshotRepository; class Cleanup extends Command @@ -23,6 +24,6 @@ public function handle() return; } - $snapshots->splice($keep)->each(fn ($snapshot) => $snapshot->delete()); + $snapshots->splice($keep)->each(fn (Snapshot $snapshot) => $snapshot->delete()); } } diff --git a/src/Snapshot.php b/src/Snapshot.php index ce0ad1d..7d2e07f 100644 --- a/src/Snapshot.php +++ b/src/Snapshot.php @@ -41,7 +41,7 @@ public function __construct(Disk $disk, string $fileName) $this->name = pathinfo($fileName, PATHINFO_FILENAME); } - public function useStream() + public function useStream(): self { $this->useStream = true; @@ -65,7 +65,7 @@ public function load(?string $connectionName = null, bool $dropTables = true): v event(new LoadedSnapshot($this)); } - protected function loadAsync(?string $connectionName = null) + protected function loadAsync(?string $connectionName = null): void { $dbDumpContents = $this->disk->get($this->fileName); @@ -88,7 +88,7 @@ protected function shouldIgnoreLine(string $line): bool return empty($line) || $this->isASqlComment($line); } - protected function loadStream(?string $connectionName = null) + protected function loadStream(?string $connectionName = null): void { LazyCollection::make(function () { $stream = $this->compressionExtension === 'gz' @@ -150,7 +150,7 @@ public function createdAt(): Carbon return Carbon::createFromTimestamp($this->disk->lastModified($this->fileName)); } - protected function dropAllCurrentTables() + protected function dropAllCurrentTables(): void { DB::connection(DB::getDefaultConnection()) ->getSchemaBuilder() diff --git a/src/SnapshotRepository.php b/src/SnapshotRepository.php index 232e9a0..4799d54 100644 --- a/src/SnapshotRepository.php +++ b/src/SnapshotRepository.php @@ -13,6 +13,9 @@ public function __construct( // } + /** + * @return Collection + */ public function getAll(): Collection { return collect($this->disk->allFiles()) @@ -29,7 +32,7 @@ public function getAll(): Collection ->sortByDesc(fn (Snapshot $snapshot) => $snapshot->createdAt()->toDateTimeString()); } - public function findByName(string $name) + public function findByName(string $name): ?Snapshot { return $this->getAll()->first(fn (Snapshot $snapshot) => $snapshot->name === $name); } From 7a3dc0d02850edbb6b9b9f72e2ec9e2e892c6e40 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Sat, 28 Dec 2024 01:03:59 +0100 Subject: [PATCH 5/7] Use defer instead of deprecated tap --- tests/Commands/CreateTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Commands/CreateTest.php b/tests/Commands/CreateTest.php index b0ffe33..59b57cd 100644 --- a/tests/Commands/CreateTest.php +++ b/tests/Commands/CreateTest.php @@ -15,7 +15,7 @@ }); it('can create a snapshot with specific name') - ->tap(fn () => Artisan::call('snapshot:create', ['name' => 'test'])) + ->defer(fn () => Artisan::call('snapshot:create', ['name' => 'test'])) ->expect('test.sql') ->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/'); From 4ac8bc06ca53ba65e0abdc90124cbbb31422246d Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Mon, 30 Dec 2024 11:47:50 +0100 Subject: [PATCH 6/7] Drop Laravel <10 and PHP <8.1 support --- .github/workflows/run-tests.yml | 12 ++---------- composer.json | 12 ++++++------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 493eafd..2cc06db 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,25 +16,17 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.2, 8.1, 8.0] - laravel: ['8.*', '9.*', '10.*', '11.*'] + php: [8.2, 8.1] + laravel: ['10.*', '11.*'] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* - - laravel: 9.* - testbench: 7.* - - laravel: 8.* - testbench: ^6.23 - laravel: 11.* testbench: 9.* exclude: - - laravel: 10.* - php: 8.0 - laravel: 11.* php: 8.1 - - laravel: 11.* - php: 8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index a5f3cad..1447b70 100644 --- a/composer.json +++ b/composer.json @@ -16,18 +16,18 @@ } ], "require": { - "php": "^8.0", - "illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0", - "league/flysystem": "^1.0.41|^2.0|^3.0", + "php": "^8.1", + "illuminate/support": "^10.0|^11.0", + "league/flysystem": "^3.0", "spatie/db-dumper": "^3.3", "spatie/laravel-package-tools": "^1.6", "spatie/temporary-directory": "^2.0" }, "require-dev": { "mockery/mockery": "^1.4", - "orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0", - "pestphp/pest-plugin-laravel": "^1.3|^2.3", - "phpunit/phpunit": "^9.5|^10.5" + "orchestra/testbench": "^8.22.3|^9.0.4", + "pestphp/pest-plugin-laravel": "^2.4", + "phpunit/phpunit": "^10.5" }, "autoload": { "psr-4": { From c8cfe1ce5d7581ba0803dee9513644b85eaf5ba8 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Mon, 30 Dec 2024 11:49:50 +0100 Subject: [PATCH 7/7] Update run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2cc06db..ebf7d86 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.2, 8.1] + php: [8.4, 8.3, 8.2, 8.1] laravel: ['10.*', '11.*'] stability: [prefer-lowest, prefer-stable] include: