BaseNoteService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOneFromDb() 0 4 1
A saveInCache() 0 6 1
A deleteFromCache() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service\Note;
6
7
use App\Service\BaseService;
8
use App\Service\RedisService;
9
use App\Repository\NoteRepository;
10
11
abstract class BaseNoteService extends BaseService
12
{
13
    const REDIS_KEY = 'note:%s';
14
15
    /**
16
     * @var NoteRepository
17
     */
18
    protected $noteRepository;
19
20
    /**
21
     * @var RedisService
22
     */
23
    protected $redisService;
24
25
    public function __construct(NoteRepository $noteRepository, RedisService $redisService)
26
    {
27
        $this->noteRepository = $noteRepository;
28
        $this->redisService = $redisService;
29
    }
30
31
    public function getOneFromDb(int $noteId)
32
    {
33
        return $this->noteRepository->checkAndGetNote($noteId);
34
    }
35
36
    public function saveInCache($id, $note)
37
    {
38
        $redisKey = sprintf(self::REDIS_KEY, $id);
39
        $key = $this->redisService->generateKey($redisKey);
40
        $this->redisService->setex($key, $note);
41
    }
42
43
    public function deleteFromCache($noteId)
44
    {
45
        $redisKey = sprintf(self::REDIS_KEY, $noteId);
46
        $key = $this->redisService->generateKey($redisKey);
47
        $this->redisService->del($key);
48
    }
49
}
50