Passed
Pull Request — master (#6357)
by
unknown
08:17
created

AzureSyncStateRepository::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
rs 10
1
<?php
2
3
namespace Chamilo\CoreBundle\Repository;
4
5
use Chamilo\CoreBundle\Entity\AzureSyncState;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7
use Doctrine\Persistence\ManagerRegistry;
8
9
/**
10
 * @extends ServiceEntityRepository<AzureSyncState>
11
 */
12
class AzureSyncStateRepository extends ServiceEntityRepository
13
{
14
    public function __construct(ManagerRegistry $registry)
15
    {
16
        parent::__construct($registry, AzureSyncState::class);
17
    }
18
19
    public function save(string $title, string $value): void
20
    {
21
        $em = $this->getEntityManager();
22
23
        $state = $this->findOneBy(['title' => $title]);
24
25
        if (!$state) {
26
            $state = new AzureSyncState();
27
            $state->setTitle($title);
28
29
            $em->persist($state);
30
        }
31
32
        $state->setValue($value);
33
34
        $em->flush();
35
    }
36
}
37