Passed
Push — master ( 181037...98502e )
by y
02:11
created

External   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 48
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A _set() 0 3 1
A getDataJsonDecoded() 0 5 2
A setDataJsonEncoded() 0 5 2
1
<?php
2
3
namespace Helix\Asana\Task;
4
5
use Helix\Asana\Base\Data;
6
use Helix\Asana\Task;
7
8
/**
9
 * Custom task data.
10
 *
11
 * @see https://developers.asana.com/docs/custom-external-data
12
 *
13
 * @method null|string  getGid  ()
14
 * @method bool         hasGid  ()
15
 * @method $this        setGid  (null|string $gid) 1024 chars max.
16
 * @method null|string  getData ()
17
 * @method bool         hasData ()
18
 * @method $this        setData (null|string $data) 32768 chars max.
19
 */
20
class External extends Data {
21
22
    /**
23
     * @var Task
24
     */
25
    protected $task;
26
27
    public function __construct (Task $task, array $data = []) {
28
        parent::__construct($task, $data);
29
        $this->task = $task;
30
    }
31
32
    /**
33
     * Marks the task's `external` diff.
34
     *
35
     * @param string $field
36
     * @param mixed $value
37
     * @return $this
38
     */
39
    protected function _set (string $field, $value) {
40
        $this->task->diff['external'] = true;
41
        return parent::_set($field, $value);
42
    }
43
44
    /**
45
     * The JSON decoded data, or `null`.
46
     *
47
     * @return null|bool|number|string|array
48
     */
49
    public function getDataJsonDecoded () {
50
        if (strlen($data = $this->getData())) {
51
            return json_decode($data, true, 512, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR);
52
        }
53
        return null;
54
    }
55
56
    /**
57
     * JSON encodes and sets.
58
     * This field is nullable, so `null` is not encoded.
59
     *
60
     * @param mixed $data
61
     * @return $this
62
     */
63
    public function setDataJsonEncoded ($data) {
64
        if (isset($data)) {
65
            return $this->setData(json_encode($data, JSON_THROW_ON_ERROR));
1 ignored issue
show
Unused Code introduced by
The call to Helix\Asana\Task\External::setData() has too many arguments starting with json_encode($data, Helix...sk\JSON_THROW_ON_ERROR). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
            return $this->/** @scrutinizer ignore-call */ setData(json_encode($data, JSON_THROW_ON_ERROR));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
66
        }
67
        return $this->setData(null);
68
    }
69
}