Passed
Push — master ( 705018...c55970 )
by Daniel
12:42 queued 06:12
created

FileInfoCacheManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 29
ccs 4
cts 16
cp 0.25
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveCache() 0 3 1
A saveCache() 0 4 1
A deleteCaches() 0 7 2
A __construct() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Helper\Uploadable;
15
16
use Doctrine\ORM\EntityManagerInterface;
17
use Silverback\ApiComponentsBundle\Entity\Core\FileInfo;
18
use Silverback\ApiComponentsBundle\Repository\Core\FileInfoRepository;
19
20
class FileInfoCacheManager
21
{
22
    private EntityManagerInterface $entityManager;
23
    private FileInfoRepository $repository;
24
25 7
    public function __construct(EntityManagerInterface $entityManager, FileInfoRepository $fileInfoRepository)
26
    {
27 7
        $this->entityManager = $entityManager;
28 7
        $this->repository = $fileInfoRepository;
29 7
    }
30
31
    public function saveCache(FileInfo $fileInfo): void
32
    {
33
        $this->entityManager->persist($fileInfo);
34
        $this->entityManager->flush();
35
    }
36
37
    public function deleteCaches(array $paths, ?array $filters): void
38
    {
39
        $results = $this->repository->findByPathsAndFilters($paths, $filters);
40
        foreach ($results as $result) {
41
            $this->entityManager->remove($result);
42
        }
43
        $this->entityManager->flush();
44
    }
45
46
    public function resolveCache(string $path, ?string $filter = null): ?FileInfo
47
    {
48
        return $this->repository->findOneByPathAndFilter($path, $filter);
49
    }
50
}
51