Completed
Push — master ( 2f57a2...d63f8e )
by Christian
02:21
created

Statement::fromModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace XApi\Repository\Doctrine\Mapping;
13
14
use Xabbuh\XApi\Model\Actor;
15
use Xabbuh\XApi\Model\Result;
16
use Xabbuh\XApi\Model\Statement as StatementModel;
17
use Xabbuh\XApi\Model\StatementId;
18
19
/**
20
 * A {@link Statement} mapped to a storage backend.
21
 *
22
 * @author Christian Flothmann <[email protected]>
23
 */
24
class Statement
25
{
26
    /**
27
     * @var string
28
     */
29
    public $id;
30
31
    /**
32
     * @var Actor
33
     */
34
    public $actor;
35
36
    /**
37
     * @var Verb
38
     */
39
    public $verb;
40
41
    /**
42
     * @var \Xabbuh\XApi\Model\Object
43
     */
44
    public $object;
45
46
    /**
47
     * @var Result
48
     */
49
    public $result;
50
51
    /**
52
     * @var Actor
53
     */
54
    public $authority;
55
56
    /**
57
     * @var \DateTime
58
     */
59
    public $created;
60
61
    /**
62
     * @var \DateTime
63
     */
64
    public $stored;
65
66
    public function getModel()
67
    {
68
        return new StatementModel(StatementId::fromString($this->id), $this->actor, $this->verb->getModel(), $this->object, $this->result, $this->authority, $this->created, $this->stored);
69
    }
70
71
    public static function fromModel(StatementModel $statement)
72
    {
73
        $mappedStatement = new self();
74
        $mappedStatement->id = $statement->getId()->getValue();
75
        $mappedStatement->actor = $statement->getActor();
76
        $mappedStatement->verb = Verb::fromModel($statement->getVerb());
77
        $mappedStatement->object = $statement->getObject();
78
        $mappedStatement->result = $statement->getResult();
79
        $mappedStatement->authority = $statement->getAuthority();
80
        $mappedStatement->created = $statement->getCreated();
81
        $mappedStatement->stored = $statement->getStored();
82
83
        return $mappedStatement;
84
    }
85
}
86