Completed
Pull Request — master (#131)
by De Cramer
05:13 queued 02:26
created

PlayerQueryBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findByLogin() 0 5 1
A save() 0 4 1
A saveAll() 0 11 2
1
<?php
2
3
namespace eXpansion\Framework\PlayersBundle\Model;
4
5
use eXpansion\Framework\PlayersBundle\Model\Map\PlayerTableMap;
6
use Propel\Runtime\Propel;
7
8
/**
9
 * Class PlayerQueryBuilder
10
 *
11
 * @author    de Cramer Oliver<[email protected]>
12
 * @copyright 2017 Smile
13
 * @package eXpansion\Framework\PlayersBundle\Model
14
 */
15
class PlayerQueryBuilder
16
{
17
    /**
18
     * Find by login
19
     *
20
     * @param $login
21
     *
22
     * @return Player
23
     */
24
    public function findByLogin($login)
25
    {
26
        $playerQuery = PlayerQuery::create();
27
        return $playerQuery->findOneByLogin($login);
28
    }
29
30
    /**
31
     * Save individual player.
32
     *
33
     * @param Player $player
34
     */
35
    public function save(Player $player)
36
    {
37
        $player->save();
38
    }
39
40
    /**
41
     * Save multiple player models at the tume
42
     *
43
     * @param Player[] $players
44
     */
45
    public function saveAll($players)
46
    {
47
        $connection = Propel::getWriteConnection(PlayerTableMap::DATABASE_NAME);
48
        $connection->beginTransaction();
49
50
        foreach ($players as $record){
51
            $this->save($record);
52
        }
53
54
        $connection->commit();
55
    }
56
}
57