Completed
Push — master ( f869ef...8eea69 )
by Thibaud
06:32 queued 03:32
created

Order::getArchiveUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of phraseanet/php-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\Orders;
13
14
/**
15
 * Class Order
16
 * @package PhraseanetSDK\Orders
17
 */
18
class Order 
19
{
20
21
    const STATUS_PENDING = 'pending';
22
23
    const STATUS_FINISHED = 'finished';
24
25
    /**
26
     * @param array $values
27
     * @return array
28
     */
29
    public static function fromList(array $values)
30
    {
31
        $orders = array();
32
33
        foreach ($values as $key => $value) {
34
            $orders[$key] = self::fromValue($value);
35
        }
36
37
        return $orders;
38
    }
39
40
    /**
41
     * @param \stdClass $value
42
     * @return Order
43
     */
44
    public static function fromValue(\stdClass $value)
45
    {
46
        return new self($value);
47
    }
48
49
    /**
50
     * @var \stdClass
51
     */
52
    private $source;
53
54
    /**
55
     * @var \DateTimeInterface|null
56
     */
57
    private $created;
58
59
    /**
60
     * @var \DateTimeInterface|null
61
     */
62
    private $deadline;
63
64
    /**
65
     * @var OrderElement[]|null
66
     */
67
    private $elements;
68
69
    /**
70
     * @param \stdClass $value
71
     */
72
    public function __construct(\stdClass $value)
73
    {
74
        $this->source = $value;
75
    }
76
77
    /**
78
     * @return int
79
     */
80
    public function getId()
81
    {
82
        return $this->source->id;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getStatus()
89
    {
90
        return $this->source->status;
91
    }
92
93
    /**
94
     * @return \DateTimeInterface
95
     */
96
    public function getCreated()
97
    {
98
        return $this->created ?: $this->created = new \DateTime($this->source->created);
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getUsage()
105
    {
106
        return $this->source->usage;
107
    }
108
109
    /**
110
     * @return \DateTimeInterface|null
111
     */
112
    public function getDeadline()
113
    {
114
        return $this->deadline ?: $this->deadline = new \DateTime($this->source->deadline);
115
    }
116
117
    /**
118
     * @return OrderElement[]
119
     */
120
    public function getElements()
121
    {
122
        return $this->elements ?: $this->elements = OrderElement::fromList($this->source->elements->data);
123
    }
124
125
    /**
126
     * @return string|null
127
     */
128
    public function getArchiveUrl()
129
    {
130
        return $this->source->archive_url;
131
    }
132
}
133