Skip to content

Commit 5472eaf

Browse files
author
Given Ncube
committed
merge conflict
1 parent 3764226 commit 5472eaf

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

src/Commands/GeneratePermissionsCommand.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ public function handle(): int
5252

5353
/**
5454
* Generate all permissions.
55+
*
56+
* @return void
5557
*/
5658
protected function generatePermissionsForAllModels(): void
5759
{
58-
$models = $this->getModels();
59-
60-
$models->each(fn (string $model) => $this->generatePermissions($model));
60+
$this->getModels()->each(
61+
fn(string $model) => $this->generatePermissions($model)
62+
);
6163
}
6264

6365
/**
@@ -71,33 +73,43 @@ public function generatePermissions(string $model): void
7173
$permissions = config('authorizer.permissions');
7274

7375
collect($permissions)->each(
74-
fn (string $permission) => $this->generatePermission(
76+
fn(string $permission) => $this->generatePermission(
7577
$model,
7678
$permission
7779
)
7880
);
7981
}
8082

81-
public function generatePermission(string $model, string $permission)
83+
/**
84+
* Generate a permission for a given model.
85+
*
86+
* @param string $model
87+
* @param string $permission
88+
* @return mixed
89+
*/
90+
public function generatePermission(string $model, string $permission): mixed
8291
{
8392
if (
8493
Str::contains($permission, 'any') ||
8594
Str::contains($permission, 'all')
8695
) {
8796
return Permission::updateOrCreate([
88-
'name' => $permission.' '.Str::plural(Str::lower($model)),
97+
'name' =>
98+
$permission .
99+
' ' .
100+
Str::snake(Str::plural(Str::lower($model))),
89101
]);
90102
}
91103

92104
return Permission::updateOrCreate([
93-
'name' => $permission.' '.Str::lower($model),
105+
'name' => $permission . ' ' . Str::snake(Str::lower($model)),
94106
]);
95107
}
96108

97109
/**
98110
* Get all models.
99111
*
100-
* @return array
112+
* @return array|Collection
101113
*/
102114
public function getModels(): array|Collection
103115
{
@@ -119,8 +131,8 @@ public function getModels(): array|Collection
119131
}
120132

121133
return $reflection->isSubclassOf(Model::class) &&
122-
! $reflection->isAbstract();
134+
!$reflection->isAbstract();
123135
})
124-
->map(fn ($model) => Str::afterLast($model, '\\'));
136+
->map(fn($model) => Str::afterLast($model, '\\'));
125137
}
126138
}

src/Commands/LaravelAuthorizerCommand.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public function generateAllPolicies(): void
8585
}
8686

8787
return $reflection->isSubclassOf(Model::class) &&
88-
! $reflection->isAbstract();
88+
!$reflection->isAbstract();
8989
})
90-
->map(fn ($model) => Str::afterLast($model, '\\'));
90+
->map(fn($model) => Str::afterLast($model, '\\'));
9191

9292
$models->each(function (string $model) {
9393
$this->generatePolicy($model, $model);
@@ -104,7 +104,7 @@ public function generatePlainPolicy(string $name): void
104104
{
105105
if (
106106
file_exists($this->getPolicyPath($name)) &&
107-
! $this->option('force')
107+
!$this->option('force')
108108
) {
109109
$this->error(sprintf('Policy "%s" already exists!', $name));
110110

@@ -116,8 +116,8 @@ public function generatePlainPolicy(string $name): void
116116
'namespace' => $this->getNamespace(),
117117
'class' => $this->getClassName($name),
118118
])->reduce(
119-
fn ($carry, $value, $key) => Str::replace(
120-
'{{ '.$key.' }}',
119+
fn($carry, $value, $key) => Str::replace(
120+
'{{ ' . $key . ' }}',
121121
$value,
122122
$carry
123123
)
@@ -137,7 +137,7 @@ private function generatePolicy(string $name, string $model): void
137137
{
138138
if (
139139
file_exists($this->getPolicyPath($name)) &&
140-
! $this->option('force')
140+
!$this->option('force')
141141
) {
142142
$this->error(sprintf('Policy "%s" already exists!', $name));
143143

@@ -147,7 +147,8 @@ private function generatePolicy(string $name, string $model): void
147147
$compiled = collect([
148148
'name' => $name,
149149
'model' => $model,
150-
'modelVariable' => strtolower($model) ===
150+
'modelVariable' =>
151+
strtolower($model) ===
151152
strtolower(
152153
Str::afterLast($this->getNamespacedUserModel(), '\\')
153154
)
@@ -161,8 +162,8 @@ private function generatePolicy(string $name, string $model): void
161162
'namespacedUserModel' => $this->getNamespacedUserModel(),
162163
'user' => Str::afterLast($this->getNamespacedUserModel(), '\\'),
163164
])->reduce(
164-
static fn ($old, $value, $key) => Str::replace(
165-
'{{ '.$key.' }}',
165+
static fn($old, $value, $key) => Str::replace(
166+
'{{ ' . $key . ' }}',
166167
$value,
167168
$old
168169
),
@@ -175,11 +176,12 @@ private function generatePolicy(string $name, string $model): void
175176
/**
176177
* Get the path to the policy.
177178
*
179+
* @param string $name
178180
* @return string
179181
*/
180182
public function getPolicyPath(string $name): string
181183
{
182-
return app_path('Policies/'.$this->getClassName($name).'.php');
184+
return app_path('Policies/' . $this->getClassName($name) . '.php');
183185
}
184186

185187
/**
@@ -189,7 +191,7 @@ public function getPolicyPath(string $name): string
189191
*/
190192
public function getNamespace(): string
191193
{
192-
return app()->getNamespace().'Policies';
194+
return app()->getNamespace() . 'Policies';
193195
}
194196

195197
/**
@@ -204,7 +206,7 @@ public function getClassName(string $name): string
204206
return Str::studly($name);
205207
}
206208

207-
return Str::studly($name).'Policy';
209+
return Str::studly($name) . 'Policy';
208210
}
209211

210212
/**
@@ -215,7 +217,7 @@ public function getClassName(string $name): string
215217
*/
216218
public function getNamespacedModel(string $model): string
217219
{
218-
return app()->getNamespace().'Models\\'.Str::studly($model);
220+
return app()->getNamespace() . 'Models\\' . Str::studly($model);
219221
}
220222

221223
/**
@@ -235,6 +237,6 @@ public function getNamespacedUserModel(): string
235237
*/
236238
public function getStub(): string
237239
{
238-
return __DIR__.'/stubs/policy.stub';
240+
return __DIR__ . '/stubs/policy.stub';
239241
}
240242
}

src/LaravelAuthorizerServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public function configurePackage(Package $package): void
2020
$package
2121
->name('laravel-authorizer')
2222
->hasConfigFile()
23-
->hasViews()
24-
->hasMigration('create_laravel-authorizer_table')
2523
->hasCommands([
2624
LaravelAuthorizerCommand::class,
2725
GeneratePermissionsCommand::class,

0 commit comments

Comments
 (0)