Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimGee authored and github-actions[bot] committed Mar 8, 2023
1 parent 957a8cd commit 0c53695
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 50 deletions.
7 changes: 0 additions & 7 deletions src/Commands/GeneratePermissionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class GeneratePermissionsCommand extends Command

/**
* Run the command.
*
* @return int
*/
public function handle(): int
{
Expand All @@ -49,8 +47,6 @@ public function handle(): int

/**
* Generate all permissions.
*
* @return void
*/
protected function generatePermissionsForAllModels(): void
{
Expand All @@ -61,9 +57,6 @@ protected function generatePermissionsForAllModels(): void

/**
* Generate permission for a given model.
*
* @param string $model
* @return void
*/
public function generatePermissions(string $model): void
{
Expand Down
53 changes: 14 additions & 39 deletions src/Commands/LaravelAuthorizerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class LaravelAuthorizerCommand extends Command

/**
* Run the command.
*
* @return int
*/
public function handle(): int
{
Expand Down Expand Up @@ -60,27 +58,22 @@ public function handle(): int

/**
* Generate policies for all models.
*
* @return void
*/
public function generateAllPolicies(): void
{
$this->getModels()->each(
fn(string $model) => $this->generatePolicy($model, $model)
fn (string $model) => $this->generatePolicy($model, $model)
);
}

/**
* Generate a plain policy without a model.
*
* @param string $name
* @return void
*/
public function generatePlainPolicy(string $name): void
{
if (
file_exists($this->getPolicyPath($name)) &&
!$this->option('force')
! $this->option('force')
) {
$this->error(sprintf('Policy "%s" already exists!', $name));

Expand All @@ -92,8 +85,8 @@ public function generatePlainPolicy(string $name): void
'namespace' => $this->getNamespace(),
'class' => $this->getClassName($name),
])->reduce(
fn($carry, $value, $key) => Str::replace(
'{{ ' . $key . ' }}',
fn ($carry, $value, $key) => Str::replace(
'{{ '.$key.' }}',
$value,
$carry
)
Expand All @@ -104,16 +97,12 @@ public function generatePlainPolicy(string $name): void

/**
* Generate a policy for a given model.
*
* @param string $name
* @param string $model
* @return void
*/
private function generatePolicy(string $name, string $model): void
{
if (
file_exists($this->getPolicyPath($name)) &&
!$this->option('force')
! $this->option('force')
) {
$this->error(sprintf('Policy "%s" already exists!', $name));

Expand All @@ -123,8 +112,7 @@ private function generatePolicy(string $name, string $model): void
$compiled = collect([
'name' => $name,
'model' => $model,
'modelVariable' =>
strtolower($model) ===
'modelVariable' => strtolower($model) ===
strtolower(
Str::afterLast($this->getNamespacedUserModel(), '\\')
)
Expand All @@ -138,8 +126,8 @@ private function generatePolicy(string $name, string $model): void
'namespacedUserModel' => $this->getNamespacedUserModel(),
'user' => Str::afterLast($this->getNamespacedUserModel(), '\\'),
])->reduce(
static fn($old, $value, $key) => Str::replace(
'{{ ' . $key . ' }}',
static fn ($old, $value, $key) => Str::replace(
'{{ '.$key.' }}',
$value,
$old
),
Expand All @@ -158,55 +146,46 @@ private function generatePolicy(string $name, string $model): void

/**
* Get the path to the policy.
*
* @param string $name
* @return string
*/
public function getPolicyPath(string $name): string
{
return app_path('Policies/' . $this->getClassName($name) . '.php');
return app_path('Policies/'.$this->getClassName($name).'.php');
}

/**
* Get the policies' namespace.
*
* @return string
*/
public function getNamespace(): string
{
return app()->getNamespace() . 'Policies';
return app()->getNamespace().'Policies';
}

/**
* Get the class name for the policy.
*
* @param string $name The name of the policy
* @return string
*/
public function getClassName(string $name): string
{
if (Str::endsWith(Str::lower($name), 'policy')) {
return Str::studly($name);
}

return Str::studly($name) . 'Policy';
return Str::studly($name).'Policy';
}

/**
* Get the namespace for the model.
*
* @param string $model The name of the model
* @return string
*/
public function getNamespacedModel(string $model): string
{
return app()->getNamespace() . 'Models\\' . Str::studly($model);
return app()->getNamespace().'Models\\'.Str::studly($model);
}

/**
* Get the namespace for the User model.
*
* @return string
*/
public function getNamespacedUserModel(): string
{
Expand All @@ -215,21 +194,17 @@ public function getNamespacedUserModel(): string

/**
* Get the path to the stub.
*
* @return string
*/
public function getStub(): string
{
return __DIR__ . '/stubs/policy.stub';
return __DIR__.'/stubs/policy.stub';
}

/**
* Get the path to the user policy stub
*
* @return string
*/
public function getUserPolicyPolicyStub(): string
{
return __DIR__ . '/stubs/policy.user.stub';
return __DIR__.'/stubs/policy.user.stub';
}
}
2 changes: 0 additions & 2 deletions src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class SetupCommand extends Command

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
Expand Down
2 changes: 0 additions & 2 deletions src/Commands/Traits/LocatesModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ trait LocatesModels
{
/**
* Get all models.
*
* @return Collection
*/
protected function getModels(): Collection
{
Expand Down

0 comments on commit 0c53695

Please sign in to comment.