Skip to content

Commit c8baa93

Browse files
AlexJump24jbrooksuk
authored andcommitted
changes from feedback
1 parent 4331b0d commit c8baa93

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

src/Commands/InstallCommand.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,23 @@ protected function configureDatabaseSettings(AppSettings $settings): AppSettings
115115
)
116116
->filter(fn (ReflectionProperty $property) => array_key_exists($property->getName(), $settings->installable()) )
117117
->each(function (ReflectionProperty $property) use ($settings) {
118-
$description = $property->getAttributes(Description::class)[0]->getArguments()[0];
118+
$descriptionAttribute = $property->getAttributes(Description::class);
119+
120+
if (empty($descriptionAttribute)) {
121+
return;
122+
}
123+
124+
$descriptionAttributeClass = $descriptionAttribute[0]->newInstance();
125+
$default = $descriptionAttributeClass->getDefault();
126+
$required = $descriptionAttributeClass->getRequired();
127+
128+
if ($required === false) {
129+
return;
130+
}
131+
119132
$value = match($property->getType()?->getName()) {
120-
'bool' => confirm($description ?? $property->getName()),
121-
default => text($description ?? $property->getName(), default: $property->getDefaultValue() ?? '', required: true),
133+
'bool' => confirm($default ?? $property->getName()),
134+
default => text($default ?? $property->getName(), default: $property->getDefaultValue() ?? '', required: true),
122135
};
123136

124137
$settings->{$property->getName()} = $value;

src/Settings/AppSettings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppSettings extends Settings
1414
#[Description('What is the name of your application?')]
1515
public ?string $name = 'Cachet';
1616

17-
#[Description('What is your application about?')]
17+
#[Description('What is your application about?', required: false)]
1818
public ?string $about;
1919

2020
#[Description('Do you want to show support for Cachet?')]
@@ -32,7 +32,7 @@ class AppSettings extends Settings
3232
#[Description('How many incident days should be shown in the timeline?')]
3333
public int $incident_days = 7;
3434

35-
#[Description('After how many seconds should the status page automatically refresh?')]
35+
#[Description('After how many seconds should the status page automatically refresh?', required: false)]
3636
public ?int $refresh_rate;
3737

3838
#[Description('Should the dashboard login link be shown?')]

src/Settings/Attributes/Description.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,15 @@
77
#[Attribute(Attribute::TARGET_PROPERTY)]
88
final class Description
99
{
10-
public function __construct(private string $description) {}
10+
public function __construct(private readonly string $default, private readonly bool $required = true) {}
11+
12+
public function getDefault(): string
13+
{
14+
return $this->default;
15+
}
16+
17+
public function getRequired(): bool
18+
{
19+
return $this->required;
20+
}
1121
}

tests/Unit/Commands/InstallCommandTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
->expectsQuestion('Which database connection do you wish to use for Cachet?', 'default')
2727
->expectsQuestion('Do you wish to send anonymous data to cachet to help us understand how Cachet is used?', true)
2828
->expectsQuestion('What is the name of your application?', 'Laravel Envoyer')
29-
->expectsQuestion('What is your application about?', 'Zero downtime deployment tool.')
3029
->expectsConfirmation('Do you want to show support for Cachet?', 'yes')
3130
->expectsQuestion('What timezone is is the application located in?', 'America/New_York')
3231
->expectsConfirmation('Would you like to show your timezone on the status page?', 'yes')
3332
->expectsConfirmation('Would you like to only show the days with disruption?', 'yes')
3433
->expectsQuestion('How many incident days should be shown in the timeline?', 14)
35-
->expectsQuestion('After how many seconds should the status page automatically refresh?', 10)
3634
->expectsConfirmation('Should the dashboard login link be shown?', 'no')
3735
->expectsQuestion('Major outage threshold %', 50)
3836
->expectsOutputToContain('Installing Cachet...')
@@ -49,13 +47,11 @@
4947

5048
$settings = app(AppSettings::class);
5149
expect($settings->name)->toBe('Laravel Envoyer')
52-
->and($settings->about)->toBe('Zero downtime deployment tool.')
5350
->and($settings->show_support)->toBeTrue()
5451
->and($settings->timezone)->toBe('America/New_York')
5552
->and($settings->show_timezone)->toBeTrue()
5653
->and($settings->only_disrupted_days)->toBeTrue()
5754
->and($settings->incident_days)->toBe(14)
58-
->and($settings->refresh_rate)->toBe(10)
5955
->and($settings->dashboard_login_link)->toBeFalse()
6056
->and($settings->major_outage_threshold)->toBe(50);
6157
});

0 commit comments

Comments
 (0)