Conditions | 5 |
Paths | 1 |
Total Lines | 33 |
Code Lines | 18 |
Lines | 22 |
Ratio | 66.67 % |
Changes | 0 |
1 | <?php |
||
15 | public function boot(AuthManager $auth) |
||
16 | { |
||
17 | $auth->provider('dummy', function (Application $app, array $config) { |
||
18 | /** @var \Illuminate\Contracts\Cache\Repository $cache */ |
||
19 | $cache = $app->make(CacheContract::class); |
||
20 | |||
21 | View Code Duplication | $this->app['events']->listen(Login::class, function ($event) use ($config, $cache) { |
|
|
|||
22 | if (! $event->user instanceof Authenticatable) { |
||
23 | return false; |
||
24 | } |
||
25 | |||
26 | $id = $event->user->id; |
||
27 | if (! $id) { |
||
28 | return false; |
||
29 | } |
||
30 | $cache->put('users.' . $id, $event->user, $config['lifetime']); |
||
31 | }); |
||
32 | |||
33 | View Code Duplication | $this->app['events']->listen(Logout::class, function ($event) use ($config, $cache) { |
|
34 | if (! $event->user instanceof Authenticatable) { |
||
35 | return false; |
||
36 | } |
||
37 | |||
38 | $id = $event->user->id; |
||
39 | if (! $id) { |
||
40 | return false; |
||
41 | } |
||
42 | $cache->forget('users.' . $id); |
||
43 | }); |
||
44 | |||
45 | return new DummyUserProvider($cache, $config); |
||
46 | }); |
||
47 | } |
||
48 | |||
50 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.