Completed
Push — master ( a17d5b...ee5489 )
by Luka
02:36
created

Status::__construct()   D

Complexity

Conditions 8
Paths 128

Size

Total Lines 26
Code Lines 16

Duplication

Lines 6
Ratio 23.08 %

Code Coverage

Tests 17
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 16
nc 128
nop 1
dl 6
loc 26
ccs 17
cts 17
cp 1
crap 8
rs 4.6666
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 View Code Duplication
        if (isset($properties['account'])) {
0 ignored issues
show
Duplication introduced by
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...
68 1
            $properties['account'] = map (Account::class, $properties['account']);
69
        }
70 2
        if (isset($properties['reblog'])) {
71 1
            $properties['reblog'] = map(Status::class, $properties['reblog']);
72
        }
73 2 View Code Duplication
        if (isset($properties['created_at'])) {
0 ignored issues
show
Duplication introduced by
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...
74 1
            $properties['created_at'] = map(\DateTimeImmutable::class, $properties['created_at']);
75
        }
76 2
        if (isset($properties['media_attachments'])) {
77 1
            $properties['media_attachments'] = map([Attachment::class], $properties['media_attachments']);
78
        }
79 2
        if (isset($properties['mentions'])) {
80 1
            $properties['mentions'] = map([Mention::class], $properties['mentions']);
81
        }
82 2
        if (isset($properties['tags'])) {
83 1
            $properties['tags'] = map([Tag::class], $properties['tags']);
84
        }
85 2
        if (isset($properties['application'])) {
86 1
            $properties['application'] = map(Application::class, $properties['application']);
87
        }
88
89 2
        $this->setProperties($properties);
90 2
    }
91
92
    /**
93
     * Returns account data as array
94
     *
95
     * @return array
96
     */
97 3
    public function toArray()
98
    {
99
        return [
100 3
            'id'                => $this->id,
101 3
            'uri'               => $this->uri,
102 3
            'url'               => $this->url,
103 3
            'account'           => toArrayValue($this->account),
104 3
            'in_reply_to_id'    => $this->in_reply_to_id,
105 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...
106 3
            'reblog'            => toArrayValue($this->reblog),
107 3
            'content'           => $this->content,
108 3
            'created_at'        => toArrayValue($this->created_at),
109 3
            'reblogs_count'     => $this->reblogs_count,
110 3
            'favourites_count'  => $this->favourites_count,
111 3
            'reblogged'         => $this->reblogged,
112 3
            'favourited'        => $this->favourited,
113 3
            'sensitive'         => $this->sensitive,
114 3
            'spoiler_text'      => $this->spoiler_text,
115 3
            'visibility'        => $this->visibility,
116 3
            'media_attachments' => toArrayValue($this->media_attachments),
117 3
            'mentions'          => toArrayValue($this->mentions),
118 3
            'tags'              => toArrayValue($this->tags),
119 3
            'application'       => toArrayValue($this->application),
120
        ];
121
    }
122
}
123