Skip to content

Commit 8b72b62

Browse files
style changes, minor refactorings
1 parent b44e7e5 commit 8b72b62

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

src/Commands/Create.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Spatie\DbSnapshots\Commands;
44

5-
use DB;
65
use Carbon\Carbon;
76
use Illuminate\Console\Command;
87
use Spatie\DbSnapshots\Helpers\Format;
@@ -24,13 +23,13 @@ public function handle()
2423

2524
$snapshotName = $this->argument('name') ?: Carbon::now()->format('Y-m-d_H-i-s');
2625

27-
$compress = $this->option('compress');
26+
$compress = $this->option('compress', null);
2827

2928
$snapshot = app(SnapshotFactory::class)->create(
3029
$snapshotName,
3130
config('db-snapshots.disk'),
3231
$connectionName,
33-
$compress ?: null
32+
($compress !== null) ? $compress : (bool) config('db-snapshots.compress', false)
3433
);
3534

3635
$size = Format::humanReadableSize($snapshot->size());

src/Snapshot.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Snapshot
2323
public $name;
2424

2525
/** @var string */
26-
public $compressionExt = null;
26+
public $compressionExtension = null;
2727

2828
public function __construct(Disk $disk, string $fileName)
2929
{
@@ -34,7 +34,7 @@ public function __construct(Disk $disk, string $fileName)
3434
$pathinfo = pathinfo($fileName);
3535

3636
if ($pathinfo['extension'] === 'gz') {
37-
$this->compressionExt = $pathinfo['extension'];
37+
$this->compressionExtension = $pathinfo['extension'];
3838
$fileName = $pathinfo['filename'];
3939
}
4040

@@ -53,7 +53,7 @@ public function load(string $connectionName = null)
5353

5454
$dbDumpContents = $this->disk->get($this->fileName);
5555

56-
if ($this->compressionExt === 'gz') {
56+
if ($this->compressionExtension === 'gz') {
5757
$dbDumpContents = gzdecode($dbDumpContents);
5858
}
5959

src/SnapshotFactory.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ public function __construct(DbDumperFactory $dumperFactory, Factory $filesystemF
2626
$this->filesystemFactory = $filesystemFactory;
2727
}
2828

29-
public function create(string $snapshotName, string $diskName, string $connectionName, bool $compress = null): Snapshot
29+
public function create(string $snapshotName, string $diskName, string $connectionName, bool $compress = false): Snapshot
3030
{
3131
$disk = $this->getDisk($diskName);
3232

3333
$fileName = $snapshotName.'.sql';
3434
$fileName = pathinfo($fileName, PATHINFO_BASENAME);
3535

36-
$compress = ($compress === true) ?: (bool) config('db-snapshots.compress', false);
37-
3836
if ($compress) {
3937
$fileName .= '.gz';
4038
}

tests/Commands/CreateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public function it_can_create_a_snapshot_without_a_specific_name()
1515

1616
$fileName = Carbon::now()->format('Y-m-d_H-i-s').'.sql';
1717

18-
$this->assertFileOnDiskContains($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/', true);
18+
$this->assertFileOnDiskPassesRegex($fileName, '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/');
1919
}
2020

2121
/** @test */
2222
public function it_can_create_a_snapshot_with_specific_name()
2323
{
2424
Artisan::call('snapshot:create', ['name' => 'test']);
2525

26-
$this->assertFileOnDiskContains('test.sql', '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/', true);
26+
$this->assertFileOnDiskPassesRegex('test.sql', '/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/');
2727
}
2828

2929
/** @test */

tests/SnapshotRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function it_can_find_gz_compressed_snapshots()
4242

4343
$this->assertInstanceOf(Snapshot::class, $snapshot);
4444

45-
$this->assertEquals('gz', $snapshot->compressionExt);
45+
$this->assertEquals('gz', $snapshot->compressionExtension);
4646

4747
$this->assertNull($this->repository->findByName('snapshot5'));
4848
}

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ protected function getEnvironmentSetUp($app)
5656
]);
5757
}
5858

59-
protected function assertFileOnDiskContains($fileName, $needle, bool $isRegex = false)
59+
protected function assertFileOnDiskPassesRegex($fileName, $needle)
6060
{
6161
$this->disk->assertExists($fileName);
6262

6363
$contents = $this->disk->get($fileName);
6464

65-
($isRegex) ? $this->assertRegExp($needle, $contents) : $this->assertContains($needle, $contents);
65+
$this->assertRegExp($needle, $contents);
6666
}
6767

6868
protected function setupDatabase()

0 commit comments

Comments
 (0)