ImageObserver::creating()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace App\Listeners\Observers;
4
5
use App\Services\ImageProcessor;
6
use Log;
7
8
class ImageObserver extends Observer
9
{
10
    /**
11
     * On creating.
12
     *
13
     * @param $model
14
     * @return \Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Documentation introduced by
The doc-type \Illuminate\Database\Eloquent\Model; could not be parsed: Expected "|" or "end of type", but got ";" at position 35. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
15
     */
16
    public function creating($model)
17
    {
18
        $lastRank = $model->getLastRank();
19
20
        $model->rank = ($lastRank) ? $lastRank->rank + 1 : 1;
21
22
        if ($this->recordLogs())
23
            Log::info('[' . __METHOD__ . '()] -> User added to model rank ' . $lastRank->rank, [
24
                'id' => \Auth::id()
25
            ]);
26
27
        return $model;
28
    }
29
30
    /**
31
     * On deleting.
32
     *
33
     * @param $model
34
     * @return \Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Documentation introduced by
The doc-type \Illuminate\Database\Eloquent\Model; could not be parsed: Expected "|" or "end of type", but got ";" at position 35. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
35
     */
36
    public function deleting($model)
37
    {
38
        if ($this->recordLogs())
39
            Log::info('[' . __METHOD__ . '()] -> User deleting model with id ' . $model->id, [
40
                'id' => \Auth::id()
41
            ]);
42
43
        $destroyed =(new ImageProcessor)->destroyImageOnly($model);
44
45
        if($this->recordLogs() && $destroyed)
46
            Log::info('[' . __METHOD__ . '()] -> Image '.$model->image.' was deleted from folder');
47
    }
48
49
    /**
50
     * On deleted.
51
     *
52
     * @param $model
53
     * @return \Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Documentation introduced by
The doc-type \Illuminate\Database\Eloquent\Model; could not be parsed: Expected "|" or "end of type", but got ";" at position 35. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
54
     */
55
    public function deleted($model)
56
    {
57
        if ($this->recordLogs())
58
            Log::info('[' . __METHOD__ . '()] -> Deleted model with id ' . $model->id);
59
    }
60
}