MinistryObserver::creating()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace FaithGen\SDK\Observers;
4
5
use FaithGen\SDK\Models\Ministry;
6
use FaithGen\SDK\Notifications\Ministry\AccountCreated;
7
use FaithGen\SDK\Traits\FileTraits;
8
use Illuminate\Support\Facades\Hash;
9
use Illuminate\Support\Str;
10
11
class MinistryObserver
12
{
13
    use FileTraits;
14
15
    public function creating(Ministry $ministry)
16
    {
17
        $ministry->password = Hash::make(request()->password);
18
        $ministry->id = (string) Str::uuid();
19
    }
20
21
    /**
22
     * Handle the ministry "created" event.
23
     *
24
     * @param  \App\Models\Ministry  $ministry
0 ignored issues
show
Bug introduced by
The type App\Models\Ministry was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
     *
26
     * @throws \Exception
27
     * @return void
28
     */
29
    public function created(Ministry $ministry)
30
    {
31
        $ministry->profile()->save(new Ministry\Profile());
32
        $ministry->account()->save(new Ministry\Account());
33
        $ministry->activation()->save(new Ministry\Activation());
34
        $ministry->apiKey()->save(new Ministry\APIKey([
35
            'api_key' => str_shuffle(Str::uuid()->toString()),
36
        ]));
37
38
        $ministry->notify(new AccountCreated($ministry));
39
    }
40
41
    /**
42
     * Handle the ministry "updated" event.
43
     *
44
     * @param  Ministry  $ministry
45
     *
46
     * @return void
47
     */
48
    public function updated(Ministry $ministry)
49
    {
50
        if (request()->has('services')) {
51
            $ministry->services()->insert(request()->services);
52
        }
53
    }
54
55
    /**
56
     * Handle the ministry "deleted" event.
57
     *
58
     * @param  Ministry  $ministry
59
     *
60
     * @return void
61
     */
62
    public function deleted(Ministry $ministry)
63
    {
64
        //todo remove aa lotta staff related to this ministry
65
        if ($ministry->image()->exists()) {
66
            $ministry->image()->delete();
67
        }
68
69
        try {
70
            $this->deleteFiles($ministry);
71
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
72
        }
73
    }
74
}
75