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

PlayerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 33
c 1
b 0
f 0
wmc 2
lcom 1
cbo 0
rs 10

2 Methods

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