Completed
Pull Request — master (#72)
by Thibaud
08:29
created

QuarantineSession::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of Phraseanet SDK.
5
 *
6
 * (c) Alchemy <[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 PhraseanetSDK\Entity;
13
14
use PhraseanetSDK\Annotation\ApiField as ApiField;
15
use PhraseanetSDK\Annotation\ApiRelation as ApiRelation;
16
use PhraseanetSDK\Annotation\Id as Id;
17
18
class QuarantineSession
19
{
20
21
    public static function fromList(array $values)
22
    {
23
        $sessions = array();
24
25
        foreach ($values as $value) {
26
            $sessions[$value->id] = self::fromValue($value);
27
        }
28
29
        return $sessions;
30
    }
31
32 2
    public static function fromValue(\stdClass $value)
33
    {
34 2
        return new self($value);
35
    }
36
37
    /**
38
     * @var \stdClass
39
     */
40
    protected $source;
41
42
    /**
43
     * @var User
44
     */
45
    protected $user;
46
47
    /**
48
     * @param \stdClass $source
49
     */
50 2
    public function __construct(\stdClass $source)
51
    {
52 2
        $this->source = $source;
53 2
    }
54
55
    /**
56
     * @return \stdClass
57
     */
58
    public function getRawData()
59
    {
60 2
        return $this->source;
61
    }
62 2
63
    /**
64
     * The session id
65
     *
66
     * @return integer
67
     */
68
    public function getId()
69
    {
70 2
        return $this->source->id;
71
    }
72 2
73
    /**
74
     * The user id
75
     *
76
     * @return integer
77
     */
78
    public function getUser()
79
    {
80
        return $this->user ?: $this->user = User::fromValue($this->source->user);
81
    }
82
}
83