-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathBattleFactory.php
58 lines (44 loc) · 1.42 KB
/
BattleFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace App\Battle\Domain\Factory;
use App\Battle\Domain\Battle;
use App\Battle\Domain\ValueObjects\BattleStatus;
use DateTimeImmutable;
final class BattleFactory
{
public static function create(array $values = [])
{
$battle = new Battle();
$battle->setCreatedAt(new DateTimeImmutable());
$battle->setEndedAt(null);
if (empty($values)) {
return $battle;
}
if (isset($values['id'])) {
$values['id'] = (int)$values['id'];
}
if (isset($values['created_at'])) {
$values['created_at'] = new DateTimeImmutable($values['created_at']);
}
if (isset($values['status'])) {
$battle->setStatus(new BattleStatus($values['status']));
unset($values['status']);
}
if (isset($values['trainer1'])) {
$battle->setTrainer1($values['trainer1']);
unset($values['trainer1']);
}
if (isset($values['trainer2'])) {
$battle->setTrainer2($values['trainer2']);
unset($values['trainer2']);
}
if (isset($values['xp_earned'])) {
$values['xp_earned'] = (int)$values['xp_earned'];
}
if (isset($values['money_earned'])) {
$values['money_earned'] = (float)$values['money_earned'];
}
$battle->fill($values);
return $battle;
}
}