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

RegistrationRepository::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 14
rs 10
cc 2
nc 2
nop 1
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