Skip to content

Commit

Permalink
apply rector for 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jun 7, 2024
1 parent c88103c commit 3d2121d
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 61 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"test": "vendor/bin/pest --compact",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"analyse": "vendor/bin/phpstan analyse",
"rector": "./vendor/bin/rector --dry-run"
"rector": "./vendor/bin/rector --dry-run",
"baseline": "./vendor/bin/phpstan analyse --generate-baseline --memory-limit=2G"
},
"suggest": {
"laravel/slack-notification-channel": "Required for sending notifications via Slack"
Expand Down
9 changes: 9 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Deprecated in PHP 8\\.0\\: Required parameter \\$diskName follows optional parameter \\$disk\\.$#"
count: 1
path: src/BackupDestination/BackupDestination.php

-
message: "#^Deprecated in PHP 8\\.1\\: Required parameter \\$backupName follows optional parameter \\$disk\\.$#"
count: 1
path: src/BackupDestination/BackupDestination.php
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: max
level: 5
paths:
- src
- config
Expand Down
15 changes: 2 additions & 13 deletions src/BackupDestination/BackupDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,12 @@

class BackupDestination
{
protected ?Filesystem $disk;

protected string $diskName;

protected string $backupName;

public ?Exception $connectionError = null;

protected ?BackupCollection $backupCollectionCache = null;

public function __construct(Filesystem $disk = null, string $backupName, string $diskName)
public function __construct(protected ?Filesystem $disk = null, protected string $backupName, protected string $diskName)
{
$this->disk = $disk;

$this->diskName = $diskName;

$this->backupName = $backupName;
}

public function disk(): Filesystem
Expand All @@ -49,7 +38,7 @@ public function filesystemType(): string

$filesystemType = last(explode('\\', $adapterClass));

return strtolower($filesystemType);
return strtolower((string) $filesystemType);
}

public static function create(string $diskName, string $backupName): self
Expand Down
4 changes: 2 additions & 2 deletions src/BackupServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function configurePackage(Package $package): void
]);
}

public function packageBooted()
public function packageBooted(): void
{
$this->app['events']->subscribe(EventHandler::class);

Expand All @@ -43,7 +43,7 @@ public function packageBooted()
}
}

public function packageRegistered()
public function packageRegistered(): void
{
$this->app->singleton(ConsoleOutput::class);

Expand Down
6 changes: 1 addition & 5 deletions src/Commands/CleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ class CleanupCommand extends BaseCommand implements Isolatable
/** @var string */
protected $description = 'Remove all backups older than specified number of days in config.';

protected CleanupStrategy $strategy;

public function __construct(CleanupStrategy $strategy)
public function __construct(protected CleanupStrategy $strategy)
{
parent::__construct();

$this->strategy = $strategy;
}

public function handle(): int
Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/Channels/Discord/DiscordMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function toArray(): array
'type' => 'rich',
'description' => $this->description,
'fields' => $this->fields,
'color' => hexdec($this->color),
'color' => hexdec((string) $this->color),
'footer' => [
'text' => $this->footer ?? '',
],
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected function dumpDatabases(): array
->map(function (DbDumper $dbDumper, $key) {
consoleOutput()->info("Dumping database {$dbDumper->getDbName()}...");

$dbType = mb_strtolower(basename(str_replace('\\', '/', get_class($dbDumper))));
$dbType = mb_strtolower(basename(str_replace('\\', '/', $dbDumper::class)));


if (config('backup.backup.database_dump_filename_base') === 'connection') {
Expand Down
4 changes: 2 additions & 2 deletions src/Tasks/Backup/DbDumperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public static function createFromConnection(string $dbConnectionName): DbDumper
return $dbDumper;
}

public static function extend(string $driver, callable $callback)
public static function extend(string $driver, callable $callback): void
{
static::$custom[$driver] = $callback;
}

protected static function forDriver($dbDriver): DbDumper
{
$driver = strtolower($dbDriver);
$driver = strtolower((string) $dbDriver);

if (isset(static::$custom[$driver])) {
return (static::$custom[$driver])();
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Backup/FileSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ protected function getMatchingPaths(string $path): array

protected function canUseGlobBrace(string $path): bool
{
return strpos($path, '*') !== false && defined('GLOB_BRACE');
return str_contains($path, '*') && defined('GLOB_BRACE');
}
}
8 changes: 2 additions & 6 deletions src/Tasks/Backup/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@

class Manifest implements Countable
{
protected string $manifestPath;

public static function create(string $manifestPath): self
{
return new static($manifestPath);
}

public function __construct(string $manifestPath)
public function __construct(protected string $manifestPath)
{
$this->manifestPath = $manifestPath;

touch($manifestPath);
touch($this->manifestPath);
}

public function path(): string
Expand Down
10 changes: 3 additions & 7 deletions src/Tasks/Backup/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ class Zip

protected int $fileCount = 0;

protected string $pathToZip;

public static function createForManifest(Manifest $manifest, string $pathToZip): self
{
$relativePath = config('backup.backup.source.files.relative_path') ?
rtrim(config('backup.backup.source.files.relative_path'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : false;
rtrim((string) config('backup.backup.source.files.relative_path'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : false;

$zip = new static($pathToZip);

Expand Down Expand Up @@ -49,12 +47,10 @@ protected static function determineNameOfFileInZip(string $pathToFile, string $p
return $pathToFile;
}

public function __construct(string $pathToZip)
public function __construct(protected string $pathToZip)
{
$this->zipFile = new ZipArchive();

$this->pathToZip = $pathToZip;

$this->open();
}

Expand Down Expand Up @@ -106,7 +102,7 @@ public function add(string | iterable $files, string $nameInZip = null): self
}

if (is_file($file)) {
$this->zipFile->addFile($file, ltrim($nameInZip, DIRECTORY_SEPARATOR));
$this->zipFile->addFile($file, ltrim((string) $nameInZip, DIRECTORY_SEPARATOR));

if (is_int($compressionMethod)) {
$this->zipFile->setCompressionName(
Expand Down
12 changes: 2 additions & 10 deletions src/Tasks/Cleanup/CleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@

class CleanupJob
{
protected Collection $backupDestinations;

protected CleanupStrategy $strategy;

protected bool $sendNotifications = true;

public function __construct(
Collection $backupDestinations,
CleanupStrategy $strategy,
protected Collection $backupDestinations,
protected CleanupStrategy $strategy,
bool $disableNotifications = false,
) {
$this->backupDestinations = $backupDestinations;

$this->strategy = $strategy;

$this->sendNotifications = ! $disableNotifications;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Cleanup/Strategies/DefaultStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DefaultStrategy extends CleanupStrategy
{
protected ?Backup $newestBackup = null;

public function deleteOldBackups(BackupCollection $backups)
public function deleteOldBackups(BackupCollection $backups): void
{
// Don't ever delete the newest backup.
$this->newestBackup = $backups->shift();
Expand Down
6 changes: 3 additions & 3 deletions tests/BackupDestination/BackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
});

it('can determine its size', function () {
$backup = getBackupForFile('test.zip', 0, 'this backup has content');
$backup = getBackupForFile('test.zip', 0);

$fileSize = floatval(Storage::disk('local')->size('mysite.com/test.zip'));

Expand All @@ -72,7 +72,7 @@
});

it('can determine its size even after it has been deleted', function () {
$backup = getBackupForFile('test.zip', 0, 'this backup has content');
$backup = getBackupForFile('test.zip', 0);

$backup->delete();

Expand Down Expand Up @@ -113,7 +113,7 @@
});

it('need a float type size', function () {
$backup = getBackupForFile('test.zip', 0, 'this backup has content');
$backup = getBackupForFile('test.zip', 0);

expect($backup->sizeInBytes())->toBeFloat();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Commands/BackupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
}
$zip->close();

expect($zipFile)->toStartWith(ltrim($this->getStubDirectory(), DIRECTORY_SEPARATOR));
expect($zipFile)->toStartWith(ltrim((string) $this->getStubDirectory(), DIRECTORY_SEPARATOR));
});

it('excludes the temporary directory from the backup', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/Commands/CleanupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

return [
$this->createFileOnDisk('local', "mysite/test_{$date->format('Ymd')}_first.zip", $date),
$this->createFileOnDisk('local', "mysite/test_{$date->format('Ymd')}_second.zip", $date->addHour(2)),
$this->createFileOnDisk('local', "mysite/test_{$date->format('Ymd')}_second.zip", $date->addHour()),
];
})->partition(function (string $backupPath) {
return in_array($backupPath, [
Expand Down
2 changes: 1 addition & 1 deletion tests/Commands/MonitorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class MonitorCommandTest extends TestCase
{
/** @test */
public function it_warns_the_user_about_the_old_style_config_keys()
public function it_warns_the_user_about_the_old_style_config_keys(): void
{
$this->artisan('backup:monitor')
->assertSuccessful();
Expand Down
6 changes: 3 additions & 3 deletions tests/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Carbon::setTestNow(Carbon::create(2016, 1, 1)->startOfDay());

expect(Format::ageInDays(Carbon::now()->subSeconds(5)))->toEqual('0.00 (5 seconds ago)');
expect(Format::ageInDays(Carbon::now()->subHour(1)))->toEqual('0.04 (1 hour ago)');
expect(Format::ageInDays(Carbon::now()->subHour(1)->subDay(1)))->toEqual('1.04 (1 day ago)');
expect(Format::ageInDays(Carbon::now()->subHour(1)->subMonths(1)))->toEqual('30.04 (4 weeks ago)');
expect(Format::ageInDays(Carbon::now()->subHour()))->toEqual('0.04 (1 hour ago)');
expect(Format::ageInDays(Carbon::now()->subHour()->subDay()))->toEqual('1.04 (1 day ago)');
expect(Format::ageInDays(Carbon::now()->subHour()->subMonths(1)))->toEqual('30.04 (4 weeks ago)');
});
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function getTempDirectory(?string $file = null): string
return __DIR__.'/temp'.($file ? '/'.$file : '');
}

public function initializeTempDirectory()
public function initializeTempDirectory(): void
{
$this->initializeDirectory($this->getTempDirectory());
}
Expand Down

0 comments on commit 3d2121d

Please sign in to comment.