Skip to content

Commit

Permalink
Make code look prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed Jun 28, 2023
1 parent 8b403aa commit fc52548
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 36 deletions.
31 changes: 10 additions & 21 deletions src/CommandGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,18 @@ public function run(): Collection

public function commandsArray(): Collection
{
return collect($this->recipe)->map(function ($path, $key) {
return [
'origin' => ($this->operation === 'pull') ? $this->remotePath($key) : $this->localPath($key),
'target' => ($this->operation === 'pull') ? $this->localPath($key) : $this->remotePath($key),
'options' => $this->options,
'port' => $this->port(),
];
});
return collect($this->recipe)->map(fn ($path, $key) => [
'origin' => ($this->operation === 'pull') ? $this->remotePath($key) : $this->localPath($key),
'target' => ($this->operation === 'pull') ? $this->localPath($key) : $this->remotePath($key),
'options' => $this->options,
'port' => $this->port(),
]);
}

public function commandsString(): Collection
{
return $this->commandsArray()->map(function ($command) {
return "rsync -e 'ssh -p {$command['port']}' {$command['options']} {$command['origin']} {$command['target']}";
});
return $this->commandsArray()
->map(fn ($command) => "rsync -e 'ssh -p {$command['port']}' {$command['options']} {$command['origin']} {$command['target']}");
}

protected function port(): string
Expand All @@ -94,19 +91,11 @@ protected function remotePath(string $key): string

protected function localPathEqualsRemotePath(): bool
{
if ($this->localPath(0) !== $this->remotePath(0)) {
return false;
}

return true;
return $this->localPath(0) === $this->remotePath(0);
}

protected function remoteIsReadOnly(): bool
{
if (! Arr::get($this->remote, 'read_only', false)) {
return false;
}

return true;
return Arr::get($this->remote, 'read_only', false);
}
}
10 changes: 3 additions & 7 deletions src/PathGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ protected function joinPaths(): string
}
}

return preg_replace('#/+#', '/', join('/', $paths));
return preg_replace('#/+#', '/', implode('/', $paths));
}

protected function remoteHostEqualsLocalHost(string $remoteHost): bool
{
$ip = Http::get('https://api.ipify.org/?format=json')->json('ip');
$publicIp = Http::get('https://api.ipify.org/?format=json')->json('ip');

if ($ip !== $remoteHost) {
return false;
}

return true;
return $publicIp === $remoteHost;
}
}
4 changes: 2 additions & 2 deletions src/SyncProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class SyncProcessor
{
protected $commands;
protected Collection $commands;

protected $artisanCommand;
protected Command $artisanCommand;

public function commands(Collection $commands): self
{
Expand Down
7 changes: 1 addition & 6 deletions src/SyncServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SyncServiceProvider extends ServiceProvider
{
public function boot()
public function boot(): void
{
$this->commands([
Commands\Sync::class,
Expand All @@ -20,9 +20,4 @@ public function boot()

$this->mergeConfigFrom(__DIR__.'/../config/sync.php', 'sync');
}

public function register()
{
//
}
}

0 comments on commit fc52548

Please sign in to comment.