Skip to content

Commit

Permalink
refactor: improve naming and readability
Browse files Browse the repository at this point in the history
fixes: #140
  • Loading branch information
jonsugar committed Mar 26, 2021
1 parent baebd7e commit 2870f97
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Shell;
use Illuminate\Support\Facades\File;

class SavedConfig
class EditConfigFile
{
use AbortsCommands;

Expand All @@ -16,7 +16,7 @@ public function __construct(Shell $shell)
$this->shell = $shell;
}

public function createOrEditConfigFile(string $fileName)
public function __invoke(string $fileName)
{
$configDir = config('home_dir') . '/.lambo';
$configFilePath = $configDir . '/' . $fileName;
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/EditAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Commands;

use App\Actions\SavedConfig;
use App\Actions\EditConfigFile;
use App\Configuration\CommandLineConfiguration;
use App\Configuration\LamboConfiguration;
use App\Configuration\SavedConfiguration;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function handle()
]);

try {
app(SavedConfig::class)->createOrEditConfigFile('after');
app(EditConfigFile::class)('after');
} catch (LamboException $e) {
app('console-writer')->exception($e->getMessage());
}
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/EditConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Commands;

use App\Actions\SavedConfig;
use App\Actions\EditConfigFile;
use App\Configuration\CommandLineConfiguration;
use App\Configuration\LamboConfiguration;
use App\Configuration\SavedConfiguration;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function handle()
]);

try {
app(SavedConfig::class)->createOrEditConfigFile('config');
app(EditConfigFile::class)('config');
} catch (LamboException $e) {
app('console-writer')->exception($e->getMessage());
}
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use App\Actions\CustomizeDotEnv;
use App\Actions\DisplayHelpScreen;
use App\Actions\DisplayLamboWelcome;
use App\Actions\EditConfigFile;
use App\Actions\GenerateAppKey;
use App\Actions\InitializeGitRepo;
use App\Actions\MigrateDatabase;
use App\Actions\OpenInBrowser;
use App\Actions\OpenInEditor;
use App\Actions\RunAfterScript;
use App\Actions\RunLaravelInstaller;
use App\Actions\SavedConfig;
use App\Actions\UpgradeSavedConfiguration;
use App\Actions\ValetLink;
use App\Actions\ValetSecure;
Expand Down Expand Up @@ -87,7 +87,7 @@ public function handle()
$this->consoleWriter->note('Your Lambo configuration (~/.lambo/config) has been updated.');
$this->consoleWriter->note('Please review the changes then run lambo again.');
if ($this->confirm(sprintf('Review the changes now in %s?', config('lambo.store.editor')))) {
app(SavedConfig::class)->createOrEditConfigFile('config');
app(EditConfigFile::class)('config');
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Tests\Feature;

use App\Actions\SavedConfig;
use App\Actions\EditConfigFile;
use App\LamboException;
use Illuminate\Support\Facades\File;
use Tests\Feature\Fakes\FakeProcess;
use Tests\TestCase;

class SavedConfigTest extends TestCase
class EditConfigFileTest extends TestCase
{
private $fileName;
private $configDirectory;
Expand Down Expand Up @@ -42,7 +42,7 @@ function it_creates_the_config_directory_and_file_then_opens_the_file_for_editin

$then->the_config_file_is_opened_for_editing();

app(SavedConfig::class)->createOrEditConfigFile($this->fileName);
app(EditConfigFile::class)($this->fileName);
}

/** @test */
Expand All @@ -53,7 +53,7 @@ function it_creates_a_config_file_then_opens_the_file_for_editing()
$this->successfullyCreateConfigFile();
$this->successfullyOpenInEditor();

app(SavedConfig::class)->createOrEditConfigFile($this->fileName);
app(EditConfigFile::class)($this->fileName);
}

/** @test */
Expand All @@ -63,7 +63,7 @@ function it_opens_a_config_file_for_editing()
$this->configFileExists();
$this->successfullyOpenInEditor();

app(SavedConfig::class)->createOrEditConfigFile($this->fileName);
app(EditConfigFile::class)($this->fileName);
}

/** @test */
Expand All @@ -75,7 +75,7 @@ function it_throws_an_exception_if_the_configured_editor_fails_to_open()

$this->expectException(LamboException::class);

app(SavedConfig::class)->createOrEditConfigFile($this->fileName);
app(EditConfigFile::class)($this->fileName);
}

/** @test */
Expand All @@ -86,19 +86,19 @@ function failing_to_create_the_configuration_directory_throws_an_exception()

$this->expectException(LamboException::class);

app(SavedConfig::class)->createOrEditConfigFile($this->fileName);
app(EditConfigFile::class)($this->fileName);
}

/** @test */
function failing_to_create_the_configuration_file_throws_an_exception()
public function failing_to_create_the_configuration_file_throws_an_exception()
{
$this->configDirectoryExists();
$this->configFileExists(false);
$this->successfullyCreateConfigFile(false);

$this->expectException(LamboException::class);

app(SavedConfig::class)->createOrEditConfigFile($this->fileName);
app(EditConfigFile::class)($this->fileName);
}

private function configDirectoryExists(bool $exists = true): void
Expand Down

0 comments on commit 2870f97

Please sign in to comment.