Completed
Push — master ( b3bf60...ff8f47 )
by De Cramer
9s
created

PlayerFactory::createPlayer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
c 1
b 0
f 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace eXpansion\Core\Storage\Data;
4
use Maniaplanet\DedicatedServer\Structures\PlayerDetailedInfo;
5
use Maniaplanet\DedicatedServer\Structures\PlayerInfo;
6
7
/**
8
 * Factory to create player data.
9
 *
10
 * @package eXpansion\Core\Storage\Data
11
 */
12
class PlayerFactory
13
{
14
    protected $class;
15
16
    /**
17
     * PlayerFactory constructor.
18
     *
19
     * @param string $class
20
     */
21
    public function __construct($class)
22
    {
23
        $this->class = $class;
24
    }
25
26
    /**
27
     * Create a player obhect.
28
     *
29
     * @param PlayerInfo $playerInfo
30
     * @param PlayerDetailedInfo $playerDetailedInfo
31
     *
32
     * @return Player
33
     */
34
    public function createPlayer(PlayerInfo $playerInfo, PlayerDetailedInfo $playerDetailedInfo)
35
    {
36
        $class = $this->class;
37
        $player = new $class();
38
39
        $player->merge($playerInfo);
40
        $player->merge($playerDetailedInfo);
41
42
        return $player;
43
    }
44
}
45