Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php exit function replace to return #234

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Commands/MakeShieldDoctorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MakeShieldDoctorCommand extends Command

public $description = 'Show useful info about Filament Shield';

public function handle(): void
public function handle(): int
{
AboutCommand::add('Filament Shield', [
'Auth Provider' => Utils::getAuthProviderFQCN() . '|' . static::authProviderConfigured(),
Expand All @@ -31,7 +31,7 @@ public function handle(): void
'--only' => 'filament_shield',
]);

exit(self::SUCCESS);
return self::SUCCESS;
}

protected static function authProviderConfigured(): string
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/MakeShieldGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ class MakeShieldGenerateCommand extends Command
*/
public $description = 'Generate Permissions and/or Policies for Filament entities.';

public function handle(): void
public function handle(): int
{
$this->determinGeneratorOptionAndEntities();

if ($this->option('exclude') && blank($this->option('resource')) && blank($this->option('page')) && blank($this->option('widget'))) {
$this->components->error('No entites provided for the generators ...');
$this->components->alert('Generation skipped');

exit(self::INVALID);
return self::INVALID;
}

if (filled($this->option('resource')) || $this->option('all')) {
Expand All @@ -105,7 +105,7 @@ public function handle(): void
Cache::forget('shield_general_exclude');
}

exit(self::SUCCESS);
return self::SUCCESS;
}

protected function determinGeneratorOptionAndEntities(): void
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/MakeShieldInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class MakeShieldInstallCommand extends Command

public $description = 'Setup Core Package requirements and Install Shield';

public function handle(): void
public function handle(): int
{
if (! Utils::isAuthProviderConfigured()) {
$this->components->error('Please make sure your Auth Provider model (\App\\Models\\User) uses either `HasRoles` or `HasFilamentShield` trait');

exit(self::INVALID);
return self::INVALID;
}

if ($this->option('minimal')) {
Expand All @@ -50,7 +50,7 @@ public function handle(): void
$this->install(true);
}

exit(self::INVALID);
return self::INVALID;
}

if ($confirmed) {
Expand All @@ -75,7 +75,7 @@ public function handle(): void
}
}

exit(self::SUCCESS);
return self::SUCCESS;
}

protected function CheckIfAlreadyInstalled(): bool
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/MakeShieldPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class MakeShieldPublishCommand extends Command

public $description = "Publish filament shield's Resource.";

public function handle(Filesystem $filesystem): void
public function handle(Filesystem $filesystem): int
{
$baseResourcePath = app_path((string) Str::of('Filament\\Resources\\Shield')->replace('\\', '/'));
$roleResourcePath = app_path((string) Str::of('Filament\\Resources\\Shield\\RoleResource.php')->replace('\\', '/'));

if ($this->checkForCollision([$roleResourcePath])) {
$confirmed = confirm('Shield Resource already exists. Overwrite?');
if (! $confirmed) {
exit(self::INVALID);
return self::INVALID;
}
}

Expand All @@ -42,6 +42,6 @@ public function handle(Filesystem $filesystem): void

$this->components->info("Shield's Resource have been published successfully!");

exit(self::SUCCESS);
return self::SUCCESS;
}
}
8 changes: 4 additions & 4 deletions src/Commands/MakeShieldSeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class MakeShieldSeederCommand extends Command
*/
public $description = 'Create a seeder file from existing/configured roles and permission, that could be used within your deploy script.';

public function handle(): void
public function handle(): int
{
$path = database_path('seeders/ShieldSeeder.php');

if (! $this->option('force') && $this->checkForCollision(paths: [$path])) {
exit(self::INVALID);
return self::INVALID;
}

if ($this->option('generate')) {
Expand All @@ -45,7 +45,7 @@ public function handle(): void
if (Utils::getRoleModel()::doesntExist() && Utils::getPermissionModel()::doesntExist()) {
$this->components->warn('There are no roles or permissions to create the seeder. Please first run `shield:generate --all`');

exit(self::INVALID);
return self::INVALID;
}

$directPermissionNames = collect();
Expand Down Expand Up @@ -90,6 +90,6 @@ public function handle(): void
$this->components->info('ShieldSeeder generated successfully.');
$this->components->info('Now you can use it in your deploy script. i.e: <fg=yellow>php artisan db:seed --class=ShieldSeeder</>');

exit(self::SUCCESS);
return self::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion src/Commands/MakeShieldSuperAdminCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function handle(): int

$this->components->info("Success! {$this->superAdmin->email} may now log in at {$loginUrl}.");

exit(self::SUCCESS);
return self::SUCCESS;
}

protected function createSuperAdmin(): Authenticatable
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/MakeShieldUpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MakeShieldUpgradeCommand extends Command

public $description = 'Upgrade shield';

public function handle(): void
public function handle(): int
{
try {
$path = glob(database_path('migrations/*_filament_shield_settings_table.php'));
Expand All @@ -37,11 +37,11 @@ public function handle(): void
} catch (Throwable $e) {
$this->components->info($e);

exit(self::FAILURE);
return self::FAILURE;
}

$this->components->info('Filament Shield upgraded.');

exit(self::SUCCESS);
return self::SUCCESS;
}
}