AvatarUploaderObserver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 30
rs 10
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A created() 0 9 2
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace App\Models\User;
11
12
use App\Models\User;
13
use App\Jobs\UploadAvatarProcess;
14
use Illuminate\Contracts\Bus\Dispatcher;
15
16
/**
17
 * Class AvatarUploaderObserver.
18
 */
19
class AvatarUploaderObserver
20
{
21
    /**
22
     * @var Dispatcher
23
     */
24
    private $dispatcher;
25
26
    /**
27
     * AvatarUploaderObserver constructor.
28
     *
29
     * @param Dispatcher $dispatcher
30
     */
31
    public function __construct(Dispatcher $dispatcher)
32
    {
33
        $this->dispatcher = $dispatcher;
34
    }
35
36
    /**
37
     * @param User $user
38
     */
39
    public function created(User $user): void
40
    {
41
        // Avatar already defined for user
42
        if ($user->hasAvatar()) {
43
            return;
44
        }
45
46
        $this->dispatcher->dispatch(new UploadAvatarProcess($user));
47
    }
48
}
49