Passed
Push — master ( 89c195...0658f3 )
by y
07:57
created

Change   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 30
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _setMapped() 0 6 2
A getValue() 0 7 1
1
<?php
2
3
namespace Helix\Asana\Event;
4
5
use Helix\Asana\Base\Data;
6
use Helix\Asana\Event;
7
use Helix\Asana\Project;
8
use Helix\Asana\Project\Section;
9
use Helix\Asana\Task;
10
use Helix\Asana\Task\Attachment;
11
use Helix\Asana\Task\FieldEntry;
12
use Helix\Asana\Task\Like;
13
use Helix\Asana\Task\Story;
14
use Helix\Asana\User;
15
16
/**
17
 * The change on the event's resource.
18
 *
19
 * @method string getAction () The change's action-verb.
20
 * @method string getField  ()
21
 */
22
class Change extends Data {
23
24
    protected const MAP = [
25
        'added_value' => '*',
26
        'added_value*' => Event::GRAPH,
27
        'removed_value' => '*',
28
        'removed_value*' => Event::GRAPH,
29
        'new_value' => '*',
30
        'new_value*' => Event::GRAPH
31
    ];
32
33
    protected function _setMapped (string $field, $value): void {
34
        if (!is_array($value)) {
35
            $this->data[$field] = $value;
36
        }
37
        else {
38
            parent::_setMapped($field, $value);
39
        }
40
    }
41
42
    /**
43
     * @return null|number|string|User|Project|Section|Task|FieldEntry|Attachment|Story|Like
44
     */
45
    public function getValue () {
46
        $key = [
47
            'added' => 'added_value',
48
            'removed' => 'removed_value',
49
            'changed' => 'new_value'
50
        ][$this->data['action']];
51
        return $this->data[$key] ?? null;
52
    }
53
}