PersonRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 8
cts 13
cp 0.6153
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 4 1
A ofUsername() 0 9 2
A ofId() 0 9 2
1
<?php declare(strict_types = 1);
2
3
namespace Simplex\Quickstart\Module\Demo\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Simplex\Exception\ResourceNotFoundException;
7
use Simplex\Quickstart\Module\Demo\Model\Person;
8
9
final class PersonRepository extends EntityRepository
10
{
11
    const EMAIL_FIELD = 'email';
12
13 1
    public function ofId(string $id): Person
14
    {
15 1
        $person = $this->find($id);
16
17 1
        if (!$person instanceof Person) {
18
            throw new ResourceNotFoundException();
19
        }
20
21 1
        return $person;
22
    }
23
24 1
    public function ofUsername(string $username): Person
25
    {
26 1
        $person = $this->findOneBy([self::EMAIL_FIELD => $username]);
27
28 1
        if (!$person instanceof Person) {
29
            throw new ResourceNotFoundException();
30
        }
31
32 1
        return $person;
33
    }
34
35
    public function save(Person $person): void
36
    {
37
        $this->getEntityManager()->persist($person);
38
        $this->getEntityManager()->flush($person);
39
    }
40
}
41