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

AzureSyncStateRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A save() 0 16 2
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