Metadata::update()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 1 Features 0
Metric Value
cc 5
eloc 13
c 6
b 1
f 0
nc 6
nop 1
dl 0
loc 20
rs 8.8571
1
<?php
2
3
namespace Clarify;
4
5
use Clarify\Exceptions\InvalidJSONException;
6
7
/**
8
 * Class Metadata
9
 * @package Clarify
10
 */
11
class Metadata extends Subresource
12
{
13
    protected $subresource = 'clarify:metadata';
14
15
    /**
16
     * @param array $options
17
     * @return mixed
18
     * @throws Exceptions\InvalidJSONException
19
     * @throws InvalidIntegerArgumentException
20
     */
21
    public function update(array $options)
22
    {
23
        $data = isset($options['data']) ? $options['data'] : '';
24
        $ob = json_decode($data);
25
        if($data != '' && $ob === null) {
26
            throw new InvalidJSONException();
27
        }
28
29
        $params = array();
30
        $params['data'] = $data;
31
        if (isset($options['version'])) {
32
            $params['version'] = (int) $options['version'];
33
        }
34
        $resourceURI = $this->getSubresourceURI($options['id']);
35
36
        $result = $this->client->put($resourceURI, $params);
37
        $this->detail = $this->client->detail;
38
39
        return $result;
40
    }
41
}
42