Skip to content

Commit dcb5abd

Browse files
authored
Merge pull request #151 from xHeaven/patch-1
Code health updates
2 parents 6dd4680 + c8cfe1c commit dcb5abd

File tree

7 files changed

+24
-28
lines changed

7 files changed

+24
-28
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,17 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [ubuntu-latest]
19-
php: [8.2, 8.1, 8.0]
20-
laravel: ['8.*', '9.*', '10.*', '11.*']
19+
php: [8.4, 8.3, 8.2, 8.1]
20+
laravel: ['10.*', '11.*']
2121
stability: [prefer-lowest, prefer-stable]
2222
include:
2323
- laravel: 10.*
2424
testbench: 8.*
25-
- laravel: 9.*
26-
testbench: 7.*
27-
- laravel: 8.*
28-
testbench: ^6.23
2925
- laravel: 11.*
3026
testbench: 9.*
3127
exclude:
32-
- laravel: 10.*
33-
php: 8.0
3428
- laravel: 11.*
3529
php: 8.1
36-
- laravel: 11.*
37-
php: 8.0
3830

3931
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
4032

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.0",
20-
"illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0",
21-
"league/flysystem": "^1.0.41|^2.0|^3.0",
19+
"php": "^8.1",
20+
"illuminate/support": "^10.0|^11.0",
21+
"league/flysystem": "^3.0",
2222
"spatie/db-dumper": "^3.3",
2323
"spatie/laravel-package-tools": "^1.6",
2424
"spatie/temporary-directory": "^2.0"
2525
},
2626
"require-dev": {
2727
"mockery/mockery": "^1.4",
28-
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0",
29-
"pestphp/pest-plugin-laravel": "^1.3|^2.3",
30-
"phpunit/phpunit": "^9.5|^10.5"
28+
"orchestra/testbench": "^8.22.3|^9.0.4",
29+
"pestphp/pest-plugin-laravel": "^2.4",
30+
"phpunit/phpunit": "^10.5"
3131
},
3232
"autoload": {
3333
"psr-4": {

src/Commands/Cleanup.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\DbSnapshots\Commands;
44

55
use Illuminate\Console\Command;
6+
use Spatie\DbSnapshots\Snapshot;
67
use Spatie\DbSnapshots\SnapshotRepository;
78

89
class Cleanup extends Command
@@ -23,6 +24,6 @@ public function handle()
2324
return;
2425
}
2526

26-
$snapshots->splice($keep)->each(fn ($snapshot) => $snapshot->delete());
27+
$snapshots->splice($keep)->each(fn (Snapshot $snapshot) => $snapshot->delete());
2728
}
2829
}

src/Exceptions/CannotCreateDisk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public static function diskNotDefined(string $diskName): static
1616

1717
$existingDiskNames = implode(', ', array_keys($disks));
1818

19-
return new static("Cannot create a disk `{$diskName}`. Known disknames are {$existingDiskNames}.");
19+
return new static("Cannot create a disk `{$diskName}`. Known disk names are {$existingDiskNames}.");
2020
}
2121
}

src/Snapshot.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function __construct(Disk $disk, string $fileName)
4141
$this->name = pathinfo($fileName, PATHINFO_FILENAME);
4242
}
4343

44-
public function useStream()
44+
public function useStream(): self
4545
{
4646
$this->useStream = true;
4747

4848
return $this;
4949
}
5050

51-
public function load(string $connectionName = null, bool $dropTables = true): void
51+
public function load(?string $connectionName = null, bool $dropTables = true): void
5252
{
5353
event(new LoadingSnapshot($this));
5454

@@ -65,7 +65,7 @@ public function load(string $connectionName = null, bool $dropTables = true): vo
6565
event(new LoadedSnapshot($this));
6666
}
6767

68-
protected function loadAsync(string $connectionName = null)
68+
protected function loadAsync(?string $connectionName = null): void
6969
{
7070
$dbDumpContents = $this->disk->get($this->fileName);
7171

@@ -78,7 +78,7 @@ protected function loadAsync(string $connectionName = null)
7878

7979
protected function isASqlComment(string $line): bool
8080
{
81-
return substr($line, 0, 2) === '--';
81+
return str_starts_with($line, '--');
8282
}
8383

8484
protected function shouldIgnoreLine(string $line): bool
@@ -88,7 +88,7 @@ protected function shouldIgnoreLine(string $line): bool
8888
return empty($line) || $this->isASqlComment($line);
8989
}
9090

91-
protected function loadStream(string $connectionName = null)
91+
protected function loadStream(?string $connectionName = null): void
9292
{
9393
LazyCollection::make(function () {
9494
$stream = $this->compressionExtension === 'gz'
@@ -116,14 +116,14 @@ protected function loadStream(string $connectionName = null)
116116
break;
117117
}
118118

119-
if (substr(trim($statement), -1, 1) === ';') {
119+
if (str_ends_with(trim($statement), ';')) {
120120
yield $statement;
121121
$statement = '';
122122
}
123123
}
124124
}
125125

126-
if (substr(trim($statement), -1, 1) === ';') {
126+
if (str_ends_with(trim($statement), ';')) {
127127
yield $statement;
128128
}
129129
})->each(function (string $statement) use ($connectionName) {
@@ -150,7 +150,7 @@ public function createdAt(): Carbon
150150
return Carbon::createFromTimestamp($this->disk->lastModified($this->fileName));
151151
}
152152

153-
protected function dropAllCurrentTables()
153+
protected function dropAllCurrentTables(): void
154154
{
155155
DB::connection(DB::getDefaultConnection())
156156
->getSchemaBuilder()

src/SnapshotRepository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public function __construct(
1313
//
1414
}
1515

16+
/**
17+
* @return Collection<Snapshot>
18+
*/
1619
public function getAll(): Collection
1720
{
1821
return collect($this->disk->allFiles())
@@ -29,7 +32,7 @@ public function getAll(): Collection
2932
->sortByDesc(fn (Snapshot $snapshot) => $snapshot->createdAt()->toDateTimeString());
3033
}
3134

32-
public function findByName(string $name)
35+
public function findByName(string $name): ?Snapshot
3336
{
3437
return $this->getAll()->first(fn (Snapshot $snapshot) => $snapshot->name === $name);
3538
}

tests/Commands/CreateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
});
1616

1717
it('can create a snapshot with specific name')
18-
->tap(fn () => Artisan::call('snapshot:create', ['name' => 'test']))
18+
->defer(fn () => Artisan::call('snapshot:create', ['name' => 'test']))
1919
->expect('test.sql')
2020
->fileOnDiskToPassRegex('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/');
2121

0 commit comments

Comments
 (0)