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

FileInfoCacheManager::deleteCaches()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
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