WosObject::getId()   A
last analyzed

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
 * PHP Client for DDN Web Object Scalar (WOS) API
5
 *
6
 * @package Wosclient
7
 * @author  Casey McLaughlin <[email protected]>
8
 * @license http://opensource.org/licenses/MIT MIT
9
 * @link    https://github.com/caseyamcl/wosclient
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 *
14
 * ------------------------------------------------------------------
15
 */
16
17
namespace WosClient;
18
19
use Psr\Http\Message\ResponseInterface;
20
use Psr\Http\Message\StreamInterface;
21
use WosClient\Exception\InvalidResponseException;
22
23
/**
24
 * WosObject
25
 *
26
 * Represents object returned by a WOS getObject request
27
 *
28
 * @author Casey McLaughlin <[email protected]>
29
 */
30
class WosObject implements WosObjectInterface
31
{
32
    /**
33
     * @var StreamInterface
34
     */
35
    private $responseData;
36
37
    /**
38
     * @var WosObjectMetadata
39
     */
40
    private $metadata;
41
42
    /**
43
     * @var WosObjectId
44
     */
45
    private $objectId;
46
47
    /**
48
     * WosObject constructor.
49
     *
50
     * @param ResponseInterface $httpResponse
51
     */
52
    public function __construct(ResponseInterface $httpResponse)
53
    {
54
        if (! $httpResponse->hasHeader('x-ddn-oid')) {
55
            throw new InvalidResponseException('x-ddn-oid', 'get object');
56
        }
57
58
        $this->responseData = $httpResponse->getBody();
59
        $this->metadata     = new WosObjectMetadata($httpResponse);
60
        $this->objectId     = new WosObjectId($httpResponse);
61
    }
62
63
    /**
64
     * @return StreamInterface
65
     */
66
    public function getData()
67
    {
68
        return $this->responseData;
69
    }
70
71
    /**
72
     * @return WosObjectMetadata
73
     */
74
    public function getMetadata()
75
    {
76
        return $this->metadata;
77
    }
78
79
    /**
80
     * @return WosObjectId
81
     */
82
    public function getId()
83
    {
84
        return $this->objectId;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function __toString()
91
    {
92
        return $this->responseData->__toString();
93
    }
94
}
95