Completed
Push — master ( ee5489...aa45e5 )
by Luka
03:39
created

src/Entity/Notification.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 = [
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 = [
31
        'type' => ['mention', 'reblog', 'favourite', 'follow'],
32
    ];
33
34 2
    public function __construct(array $properties)
35
    {
36 2 View Code Duplication
        if (isset($properties['created_at'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37 1
            $properties['created_at'] = map(\DateTimeImmutable::class, $properties['created_at']);
38
        }
39 2 View Code Duplication
        if (isset($properties['account'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40 1
            $properties['account'] = map(Account::class, $properties['account']);
41
        }
42 2
        if (isset($properties['status'])) {
43 1
            $properties['status'] = map(Status::class, $properties['status']);
44
        }
45
46 2
        $this->setProperties($properties);
47 2
    }
48
49
    /**
50
     * Returns notification data as array
51
     *
52
     * @return array
53
     */
54 2
    public function toArray()
55
    {
56
        return [
57 2
            'id'         => $this->id,
58 2
            'type'       => $this->type,
59 2
            'created_at' => toArrayValue($this->created_at),
60 2
            'account'    => toArrayValue($this->account),
61 2
            'status'     => toArrayValue($this->status),
62
        ];
63
    }
64
}
65