RegistrationListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace OSS\UserBundle\Listener;
4
5
use Doctrine\ORM\EntityManager;
6
use FOS\UserBundle\Event\UserEvent;
7
use OSS\CoreBundle\Entity\Player;
8
use OSS\CoreBundle\Entity\Team;
9
use OSS\UserBundle\Entity\User;
10
11
class RegistrationListener
12
{
13
    /**
14
     * @var EntityManager
15
     */
16
    private $entityManager;
17
18
    /**
19
     * @param EntityManager $entityManager
20
     */
21
    public function __construct(EntityManager $entityManager)
22
    {
23
        $this->entityManager = $entityManager;
24
    }
25
26
    /**
27
     * @param UserEvent $event
28
     */
29
    public function onRegister(UserEvent $event)
30
    {
31
        /** @var User $user */
32
        $user = $event->getUser();
33
34
        $player = new Player();
35
        $player->setName($user->getUsername());
36
        $player->setSkillDefense(rand(1, 100));
0 ignored issues
show
Bug introduced by
The method setSkillDefense() does not seem to exist on object<OSS\CoreBundle\Entity\Player>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
        $player->setSkillOffense(rand(1, 100));
0 ignored issues
show
Bug introduced by
The method setSkillOffense() does not seem to exist on object<OSS\CoreBundle\Entity\Player>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        /** @var Team[] $teams */
39
        $teams = $this->entityManager->getRepository('CoreBundle:Team')->findAll();
40
        $player->setTeam($teams[rand(0, count($teams) - 1)]);
41
        $this->entityManager->persist($player);
42
43
        $user->setPlayer($player);
44
45
        $this->entityManager->flush();
46
    }
47
}
48