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

Status::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 12
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Baguette\Mastodon\Entity;
4
5
/**
6
 * Status
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#status
12
 * @property-read int      $id  The ID of the status
13
 * @property-read string   $uri A Fediverse-unique resource ID
14
 * @property-read string   $url URL to the status page (can be remote)
15
 * @property-read Account  $account The Account which posted the status
16
 * @property-read Attachments[] $media_attachments The Account which posted the status
17
 * @property-read int|null $in_reply_to_accountid  The ID of the status it replies to
18
 * @property-read int|null $in_reply_to_id The ID of the account it replies to
19
 * @property-read Status|null $reblog The reblogged Status
20
 * @property-read string   $content   Body of the status; this will contain HTML (remote HTML already sanitized)
21
 * @property-read \DateTimeImmutable $created_at The time the status was created
22
 * @property-read int    $reblogs_count    The number of reblogs for the status
23
 * @property-read int    $favourites_count The number of favourites for the status
24
 * @property-read bool   $reblogged    Whether the authenticated user has reblogged the status
25
 * @property-read bool   $favourited   Whether the authenticated user has favourited the status
26
 * @property-read string $sensitive    Whether media attachments should be hidden by default
27
 * @property-read string $spoiler_text If not empty, warning text that should be displayed before the actual content
28
 * @property-read string $visibility   One of: public, unlisted, private, direct
29
 * @property-read Attachment[] $media_attachments An array of Attachments
30
 * @property-read Mention[]    $mentions An array of Mentions
31
 * @property-read Tag[]        $tags     An array of Tags
32
 * @property-read Application  $application Application from which the status was posted
33
 */
34
class Status extends Entity
35
{
36
    use \Teto\Object\TypedProperty;
37
38
    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...
39
        'id'                => 'int',
40
        'uri'               => 'string',
41
        'url'               => 'string',
42
        'account'           => Account::class,
43
        'in_reply_to_id'    => '?int',
44
        'in_reply_to_account_id' => '?int',
45
        'reblog'            => Status::class,
46
        'content'           => 'string',
47
        'created_at'        => \DateTimeImmutable::class,
48
        'reblogs_count'     => 'int',
49
        'favourites_count'  => 'int',
50
        'reblogged'         => 'bool',
51
        'favourited'        => 'bool',
52
        'sensitive'         => 'bool',
53
        'spoiler_text'      => 'string',
54
        'visibility'        => 'enum',
55
        'media_attachments' => 'Baguette\Mastodon\Entity\Attachment[]',
56
        'mentions'          => 'Baguette\Mastodon\Entity\Mention[]',
57
        'tags'              => 'Baguette\Mastodon\Entity\Tag[]',
58
        'application'       => Application::class,
59
    ];
60
61
    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...
62
        'visibility' => ['direct', 'private', 'unlisted', 'public'],
63
    ];
64
65 2
    public function __construct(array $properties)
66
    {
67 2
        $this->setProperties(mapValues($properties, [
68 2
            'account'           => Account::class,
69
            'reblog'            => Status::class,
70
            'created_at'        => \DateTimeImmutable::class,
71
            'media_attachments' => [Attachment::class],
72
            'mentions'          => [Mention::class],
73
            'tags'              => [Tag::class],
74
            'application'       => Application::class,
75
        ]));
76 2
    }
77
78
    /**
79
     * Returns account data as array
80
     *
81
     * @return array
82
     */
83 3
    public function toArray()
84
    {
85
        return [
86 3
            'id'                => $this->id,
87 3
            'uri'               => $this->uri,
88 3
            'url'               => $this->url,
89 3
            'account'           => toArrayValue($this->account),
90 3
            'in_reply_to_id'    => $this->in_reply_to_id,
91 3
            'in_reply_to_account_id' => $this->in_reply_to_account_id,
0 ignored issues
show
Bug introduced by
The property in_reply_to_account_id does not seem to exist. Did you mean account?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
92 3
            'reblog'            => toArrayValue($this->reblog),
93 3
            'content'           => $this->content,
94 3
            'created_at'        => toArrayValue($this->created_at),
95 3
            'reblogs_count'     => $this->reblogs_count,
96 3
            'favourites_count'  => $this->favourites_count,
97 3
            'reblogged'         => $this->reblogged,
98 3
            'favourited'        => $this->favourited,
99 3
            'sensitive'         => $this->sensitive,
100 3
            'spoiler_text'      => $this->spoiler_text,
101 3
            'visibility'        => $this->visibility,
102 3
            'media_attachments' => toArrayValue($this->media_attachments),
103 3
            'mentions'          => toArrayValue($this->mentions),
104 3
            'tags'              => toArrayValue($this->tags),
105 3
            'application'       => toArrayValue($this->application),
106
        ];
107
    }
108
}
109