Passed
Push — master ( ece3c1...a0e7b2 )
by Florian
02:27
created

RegistrationRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 9
c 1
b 0
f 1
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A save() 0 14 2
1
<?php
2
3
/*
4
 * This file is part of the TheAlternativeZurich/events project.
5
 *
6
 * (c) Florian Moser <[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
namespace App\Repository;
13
14
use App\Entity\Registration;
15
use Doctrine\ORM\EntityRepository;
16
17
class RegistrationRepository extends EntityRepository
18
{
19
    public function save(Registration $registration)
20
    {
21
        $maxNumber = 0;
22
        foreach ($registration->getEvent()->getRegistrations() as $registration) {
23
            $maxNumber = max($registration->getNumber(), $maxNumber);
24
        }
25
26
        ++$maxNumber;
27
28
        $registration->setNumber($maxNumber);
29
30
        $manager = $this->getEntityManager();
31
        $manager->persist($registration);
32
        $manager->flush();
33
    }
34
}
35