AlbumObserver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A deleted() 0 3 1
A __construct() 0 3 1
A deleteAlbumCover() 0 10 3
1
<?php
2
3
namespace App\Observers;
4
5
use App\Models\Album;
6
use Exception;
7
use Illuminate\Log\Logger;
8
9
class AlbumObserver
10
{
11
    private $logger;
12
13
    public function __construct(Logger $logger)
14
    {
15
        $this->logger = $logger;
16
    }
17
18
    public function deleted(Album $album): void
19
    {
20
        $this->deleteAlbumCover($album);
21
    }
22
23
    private function deleteAlbumCover(Album $album): void
24
    {
25
        if (!$album->has_cover) {
26
            return;
27
        }
28
29
        try {
30
            unlink($album->cover_path);
31
        } catch (Exception $e) {
32
            $this->logger->error($e);
33
        }
34
    }
35
}
36