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

EventRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A save() 0 18 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\Event;
15
use App\Helper\IdentifierHelper;
16
use App\Helper\RandomHelper;
17
use Doctrine\ORM\EntityRepository;
18
19
class EventRepository extends EntityRepository
20
{
21
    public function save(Event $event)
22
    {
23
        $identifierContent = $event->getOrganizer().'-'.$event->getName();
24
        $optimalIdentifier = IdentifierHelper::getHumanReadableIdentifier($identifierContent);
25
        $identifier = $optimalIdentifier;
26
27
        $number = 1;
28
        while ($this->findOneBy(['identifier' => $identifier])) {
29
            $identifier = $optimalIdentifier.$number++;
30
        }
31
32
        $random = RandomHelper::generateHumanReadableRandom(9, '-');
33
34
        $event->setIdentifiers($identifier, $random);
35
36
        $manager = $this->getEntityManager();
37
        $manager->persist($event);
38
        $manager->flush();
39
    }
40
}
41