@@ -27,8 +27,6 @@ class LaravelAuthorizerCommand extends Command
2727
2828 /**
2929 * Run the command.
30- *
31- * @return int
3230 */
3331 public function handle (): int
3432 {
@@ -60,27 +58,22 @@ public function handle(): int
6058
6159 /**
6260 * Generate policies for all models.
63- *
64- * @return void
6561 */
6662 public function generateAllPolicies (): void
6763 {
6864 $ this ->getModels ()->each (
69- fn (string $ model ) => $ this ->generatePolicy ($ model , $ model )
65+ fn (string $ model ) => $ this ->generatePolicy ($ model , $ model )
7066 );
7167 }
7268
7369 /**
7470 * Generate a plain policy without a model.
75- *
76- * @param string $name
77- * @return void
7871 */
7972 public function generatePlainPolicy (string $ name ): void
8073 {
8174 if (
8275 file_exists ($ this ->getPolicyPath ($ name )) &&
83- !$ this ->option ('force ' )
76+ ! $ this ->option ('force ' )
8477 ) {
8578 $ this ->error (sprintf ('Policy "%s" already exists! ' , $ name ));
8679
@@ -92,8 +85,8 @@ public function generatePlainPolicy(string $name): void
9285 'namespace ' => $ this ->getNamespace (),
9386 'class ' => $ this ->getClassName ($ name ),
9487 ])->reduce (
95- fn ($ carry , $ value , $ key ) => Str::replace (
96- '{{ ' . $ key . ' }} ' ,
88+ fn ($ carry , $ value , $ key ) => Str::replace (
89+ '{{ ' . $ key. ' }} ' ,
9790 $ value ,
9891 $ carry
9992 )
@@ -104,16 +97,12 @@ public function generatePlainPolicy(string $name): void
10497
10598 /**
10699 * Generate a policy for a given model.
107- *
108- * @param string $name
109- * @param string $model
110- * @return void
111100 */
112101 private function generatePolicy (string $ name , string $ model ): void
113102 {
114103 if (
115104 file_exists ($ this ->getPolicyPath ($ name )) &&
116- !$ this ->option ('force ' )
105+ ! $ this ->option ('force ' )
117106 ) {
118107 $ this ->error (sprintf ('Policy "%s" already exists! ' , $ name ));
119108
@@ -123,8 +112,7 @@ private function generatePolicy(string $name, string $model): void
123112 $ compiled = collect ([
124113 'name ' => $ name ,
125114 'model ' => $ model ,
126- 'modelVariable ' =>
127- strtolower ($ model ) ===
115+ 'modelVariable ' => strtolower ($ model ) ===
128116 strtolower (
129117 Str::afterLast ($ this ->getNamespacedUserModel (), '\\' )
130118 )
@@ -138,8 +126,8 @@ private function generatePolicy(string $name, string $model): void
138126 'namespacedUserModel ' => $ this ->getNamespacedUserModel (),
139127 'user ' => Str::afterLast ($ this ->getNamespacedUserModel (), '\\' ),
140128 ])->reduce (
141- static fn ($ old , $ value , $ key ) => Str::replace (
142- '{{ ' . $ key . ' }} ' ,
129+ static fn ($ old , $ value , $ key ) => Str::replace (
130+ '{{ ' . $ key. ' }} ' ,
143131 $ value ,
144132 $ old
145133 ),
@@ -158,55 +146,46 @@ private function generatePolicy(string $name, string $model): void
158146
159147 /**
160148 * Get the path to the policy.
161- *
162- * @param string $name
163- * @return string
164149 */
165150 public function getPolicyPath (string $ name ): string
166151 {
167- return app_path ('Policies/ ' . $ this ->getClassName ($ name ) . '.php ' );
152+ return app_path ('Policies/ ' . $ this ->getClassName ($ name ). '.php ' );
168153 }
169154
170155 /**
171156 * Get the policies' namespace.
172- *
173- * @return string
174157 */
175158 public function getNamespace (): string
176159 {
177- return app ()->getNamespace () . 'Policies ' ;
160+ return app ()->getNamespace (). 'Policies ' ;
178161 }
179162
180163 /**
181164 * Get the class name for the policy.
182165 *
183166 * @param string $name The name of the policy
184- * @return string
185167 */
186168 public function getClassName (string $ name ): string
187169 {
188170 if (Str::endsWith (Str::lower ($ name ), 'policy ' )) {
189171 return Str::studly ($ name );
190172 }
191173
192- return Str::studly ($ name ) . 'Policy ' ;
174+ return Str::studly ($ name ). 'Policy ' ;
193175 }
194176
195177 /**
196178 * Get the namespace for the model.
197179 *
198180 * @param string $model The name of the model
199- * @return string
200181 */
201182 public function getNamespacedModel (string $ model ): string
202183 {
203- return app ()->getNamespace () . 'Models \\' . Str::studly ($ model );
184+ return app ()->getNamespace (). 'Models \\' . Str::studly ($ model );
204185 }
205186
206187 /**
207188 * Get the namespace for the User model.
208- *
209- * @return string
210189 */
211190 public function getNamespacedUserModel (): string
212191 {
@@ -215,21 +194,17 @@ public function getNamespacedUserModel(): string
215194
216195 /**
217196 * Get the path to the stub.
218- *
219- * @return string
220197 */
221198 public function getStub (): string
222199 {
223- return __DIR__ . '/stubs/policy.stub ' ;
200+ return __DIR__ . '/stubs/policy.stub ' ;
224201 }
225202
226203 /**
227204 * Get the path to the user policy stub
228- *
229- * @return string
230205 */
231206 public function getUserPolicyPolicyStub (): string
232207 {
233- return __DIR__ . '/stubs/policy.user.stub ' ;
208+ return __DIR__ . '/stubs/policy.user.stub ' ;
234209 }
235210}
0 commit comments