Extensions::getModel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
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\Extensions as ExtensionsModel;
15
use Xabbuh\XApi\Model\IRI;
16
17
/**
18
 * @author Christian Flothmann <[email protected]>
19
 */
20
class Extensions
21
{
22
    public $identifier;
23
    public $extensions;
24
25
    public static function fromModel(ExtensionsModel $model)
26
    {
27
        $extensions = new self();
28
        $extensions->extensions = array();
29
30
        foreach ($model->getExtensions() as $key) {
31
            $extensions->extensions[$key->getValue()] = $model[$key];
32
        }
33
34
        return $extensions;
35
    }
36
37
    public function getModel()
38
    {
39
        $extensions = new \SplObjectStorage();
40
41
        foreach ($this->extensions as $key => $extension) {
42
            $extensions->attach(IRI::fromString($key), $extension);
43
        }
44
45
        return new ExtensionsModel($extensions);
46
    }
47
}
48