phpcollective /
menumaker
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace PhpCollective\MenuMaker\Observers; |
||||
| 4 | |||||
| 5 | |||||
| 6 | use Illuminate\Support\Facades\Cache; |
||||
| 7 | use PhpCollective\MenuMaker\Storage\Menu; |
||||
| 8 | use PhpCollective\MenuMaker\Storage\Role; |
||||
| 9 | use PhpCollective\MenuMaker\Jobs\RemoveUserMenuCache; |
||||
| 10 | |||||
| 11 | class MenuObserver |
||||
| 12 | { |
||||
| 13 | |||||
| 14 | /** |
||||
| 15 | * Handle the User "created" event. |
||||
| 16 | * |
||||
| 17 | * @param \App\Menu $menu |
||||
|
0 ignored issues
–
show
|
|||||
| 18 | * @return void |
||||
| 19 | */ |
||||
| 20 | public function created(Menu $menu) |
||||
|
0 ignored issues
–
show
The parameter
$menu is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 21 | { |
||||
| 22 | $this->removeAdminCache(); |
||||
| 23 | } |
||||
| 24 | |||||
| 25 | /** |
||||
| 26 | * Handle the Menu "updated" event. |
||||
| 27 | * |
||||
| 28 | * @param \App\Menu $menu |
||||
| 29 | * @return void |
||||
| 30 | */ |
||||
| 31 | public function updated(Menu $menu) |
||||
| 32 | { |
||||
| 33 | $this->removeAdminCache(); |
||||
| 34 | $this->removeUserCache($menu); |
||||
| 35 | } |
||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * Handle the Menu "deleting" event. |
||||
| 39 | * |
||||
| 40 | * @param Menu $menu |
||||
| 41 | * @return void |
||||
| 42 | */ |
||||
| 43 | public function deleting(Menu $menu) |
||||
| 44 | { |
||||
| 45 | $this->removeAdminCache(); |
||||
| 46 | $this->removeUserCache($menu); |
||||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * Handle User Cache delete. |
||||
| 51 | * |
||||
| 52 | * @param Menu $menu |
||||
| 53 | * @return void |
||||
| 54 | */ |
||||
| 55 | private function removeUserCache(Menu $menu) |
||||
| 56 | { |
||||
| 57 | $menu->load('roles', 'roles.users'); |
||||
| 58 | $menu->roles->each(function ($role) { |
||||
| 59 | $role->users->each(function ($user) { |
||||
| 60 | RemoveUserMenuCache::dispatch($user); |
||||
| 61 | }); |
||||
| 62 | }); |
||||
| 63 | } |
||||
| 64 | |||||
| 65 | /** |
||||
| 66 | * Handle Admin User Cache delete. |
||||
| 67 | * |
||||
| 68 | * @return void |
||||
| 69 | */ |
||||
| 70 | private function removeAdminCache() |
||||
| 71 | { |
||||
| 72 | Cache::forget('public-routes'); |
||||
| 73 | |||||
| 74 | $admin = Role::with('users')->admin()->first(); |
||||
| 75 | if(! $admin) |
||||
| 76 | { |
||||
| 77 | return; |
||||
| 78 | } |
||||
| 79 | |||||
| 80 | $admin->users->each(function ($user) { |
||||
|
0 ignored issues
–
show
|
|||||
| 81 | RemoveUserMenuCache::dispatch($user); |
||||
| 82 | }); |
||||
| 83 | } |
||||
| 84 | } |
||||
| 85 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths