Completed
Pull Request — master (#112)
by De Cramer
11:22
created

PlayerRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findByLogin() 0 5 1
A save() 0 13 3
1
<?php
2
3
namespace eXpansion\Framework\PlayersBundle\Repository;
4
5
use eXpansion\Framework\PlayersBundle\Entity\Player;
6
7
/**
8
 * PlayerRepository
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class PlayerRepository extends \Doctrine\ORM\EntityRepository
14
{
15
    /**
16
     * @param string $login Login of the player to laod.
17
     *
18
     * @return Player|null
19
     */
20
    public function findByLogin($login)
21
    {
22
        $player = $this->findOneBy(['login' => $login]);
23
        return $player;
24
    }
25
26
    /**
27
     * Save player data in database.
28
     *
29
     * @param Player[] $players
30
     */
31
    public function save(array $players)
32
    {
33
        if (empty($players)) {
34
            return;
35
        }
36
37
        foreach ($players as $player) {
38
            $this->getEntityManager()->persist($player);
39
        }
40
41
        $this->getEntityManager()->clear();
42
        $this->getEntityManager()->flush();
43
    }
44
}
45