WosObjectId::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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 WosClient\Exception\InvalidResponseException;
21
22
/**
23
 * Class WosObjectId
24
 *
25
 * Simple value object to represent a response for a WOS reserve OID request
26
 *
27
 * @author Casey McLaughlin <[email protected]>
28
 */
29
class WosObjectId implements WosObjectIdInterface
30
{
31
    /**
32
     * @var string
33
     */
34
    private $objectId;
35
36
    /**
37
     * WosObjectId constructor.
38
     *
39
     * @param ResponseInterface $httpResponse
40
     */
41
    public function __construct(ResponseInterface $httpResponse)
42
    {
43
        if (! $httpResponse->hasHeader('x-ddn-oid')) {
44
            throw new InvalidResponseException('x-ddn-oid', 'reserve object');
45
        }
46
47
        $this->objectId = $httpResponse->getHeaderLine('x-ddn-oid');
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getObjectId()
54
    {
55
        return $this->objectId;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        return $this->getObjectId();
64
    }
65
}
66