Passed
Push — master ( 9c76a8...94f343 )
by Bertrand
34:04 queued 24:59
created

PageObserver::restored()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
namespace App\Observers;
4
5
6
use App\Src\UseCases\Infra\Sql\Model\CharacteristicsModel;
7
use App\Src\UseCases\Infra\Sql\Model\PageModel;
8
use App\Src\UseCases\Infra\Sql\Model\UserCharacteristicsModel;
9
use Illuminate\Support\Facades\DB;
10
use Illuminate\Support\Facades\Log;
11
12
class PageObserver
13
{
14
    public function created(PageModel $pageModel)
0 ignored issues
show
Unused Code introduced by
The parameter $pageModel 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 ignore-unused  annotation

14
    public function created(/** @scrutinizer ignore-unused */ PageModel $pageModel)

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...
15
    {
16
        //
17
    }
18
19
    public function updated(PageModel $pageModel)
0 ignored issues
show
Unused Code introduced by
The parameter $pageModel 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 ignore-unused  annotation

19
    public function updated(/** @scrutinizer ignore-unused */ PageModel $pageModel)

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...
20
    {
21
        //
22
    }
23
24
    public function deleted(PageModel $pageModel)
25
    {
26
        Log::info('Deleting all data from the page internal id: ' . $pageModel->id);
27
        DB::transaction(function () use($pageModel){
28
            try {
29
                $characteristic = CharacteristicsModel::query()->where('page_id', $pageModel->page_id)->first();
30
                if (isset($characteristic)) {
31
                    $characteristic->delete();
32
                    if (is_file($characteristic->picturePath())) {
33
                        unlink($characteristic->picturePath());
34
                    }
35
36
                    UserCharacteristicsModel::query()->where('characteristic_id', $characteristic->id)->delete();
37
                }
38
            } catch (\Throwable $e) {
39
                Log::emergency('Error deleting all data from the page internal id: ' . $pageModel->id);
40
                throw $e;
41
            }
42
        });
43
    }
44
45
    public function restored(PageModel $pageModel)
0 ignored issues
show
Unused Code introduced by
The parameter $pageModel 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 ignore-unused  annotation

45
    public function restored(/** @scrutinizer ignore-unused */ PageModel $pageModel)

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...
46
    {
47
        //
48
    }
49
50
    public function forceDeleted(PageModel $pageModel)
0 ignored issues
show
Unused Code introduced by
The parameter $pageModel 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 ignore-unused  annotation

50
    public function forceDeleted(/** @scrutinizer ignore-unused */ PageModel $pageModel)

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...
51
    {
52
        //
53
    }
54
}
55