Notification::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Baguette\Mastodon\Entity;
4
5
/**
6
 * Attachment
7
 *
8
 * @author    USAMI Kenta <[email protected]>
9
 * @copyright 2017 Baguette HQ
10
 * @license   https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0
11
 * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#notification
12
 * @property-read int    $id   notification ID
13
 * @property-read string $type One of: "mention", "reblog", "favourite", "follow"
14
 * @property-read \DateTimeImmutable $created_at time the notification was created
15
 * @property-read Account $account The Account sending the notification to the user
16
 * @property-read Status  $status  The Status associated with the notification, if applicable
17
 */
18
class Notification extends Entity
19
{
20
    use \Teto\Object\TypedProperty;
21
22
    private static $property_types = [
0 ignored issues
show
Unused Code introduced by
The property $property_types is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
        'id'         => 'int',
24
        'type'       => 'enum',
25
        'created_at' => \DateTimeImmutable::class,
26
        'account'    => Account::class,
27
        'status'     => Status::class,
28
    ];
29
30
    private static $enum_values = [
0 ignored issues
show
Unused Code introduced by
The property $enum_values is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
31
        'type' => ['mention', 'reblog', 'favourite', 'follow'],
32
    ];
33
34 2
    public function __construct(array $properties)
35
    {
36 2
        $this->setProperties(mapValues($properties, [
37 2
            'created_at' =>\DateTimeImmutable::class,
38
            'account'    =>Account::class,
39
            'status'     =>Status::class,
40
        ]));
41 2
    }
42
43
    /**
44
     * Returns notification data as array
45
     *
46
     * @return array
47
     */
48 2
    public function toArray()
49
    {
50
        return [
51 2
            'id'         => $this->id,
52 2
            'type'       => $this->type,
53 2
            'created_at' => toArrayValue($this->created_at),
54 2
            'account'    => toArrayValue($this->account),
55 2
            'status'     => toArrayValue($this->status),
56
        ];
57
    }
58
}
59