RegistrationListener   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 37
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onRegister() 0 18 1
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