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

src/Entity/Account.php (1 issue)

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
 * Account
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#account
12
 * @property-read int    $id           The ID of the account
13
 * @property-read string $username     The username of the account
14
 * @property-read string $acct         Equals username for local users, includes @domain for remote ones
15
 * @property-read string $display_name The account's display name
16
 * @property-read bool   $locked       Boolean for when the account cannot be followed without waiting for approval first
17
 * @property-read \DateTimeImmutable $created_at The time the account was created
18
 * @property-read int    $followers_count The number of followers for the account
19
 * @property-read int    $following_count The number of accounts the given account is following
20
 * @property-read int    $statuses_count  The number of statuses the account has made
21
 * @property-read string $note Biography of user
22
 * @property-read string $url  URL of the user's profile page (can be remote)
23
 * @property-read string $avatar        URL to the avatar image
24
 * @property-read string $avatar_static URL to the avatar static image (gif)
25
 * @property-read string $header        URL to the header image
26
 * @property-read string $header_static URL to the header static image (gif)
27
 */
28
class Account extends Entity
29
{
30
    use \Teto\Object\TypedProperty;
31
32
    private static $property_types = [
33
        'id'              => 'int',
34
        'username'        => 'string',
35
        'acct'            => 'string',
36
        'display_name'    => 'string',
37
        'locked'          => 'bool',
38
        'created_at'      => \DateTimeImmutable::class,
39
        'followers_count' => 'int',
40
        'following_count' => 'int',
41
        'statuses_count'  => 'int',
42
        'note'            => 'string',
43
        'url'             => 'string',
44
        'avatar'          => 'string',
45
        'avatar_static'   => 'string',
46
        'header'          => 'string',
47
        'header_static'   => 'string',
48
    ];
49
50 3
    public function __construct(array $properties)
51
    {
52 3 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...
53 2
            $properties['created_at'] = map(\DateTimeImmutable::class, $properties['created_at']);
54
        }
55
56 3
        $this->setProperties($properties);
57 3
    }
58
59
    /**
60
     * Returns account data as array
61
     *
62
     * @return array
63
     */
64 4
    public function toArray()
65
    {
66
        return [
67 4
            'id'              => $this->id,
68 4
            'username'        => $this->username,
69 4
            'acct'            => $this->acct,
70 4
            'display_name'    => $this->display_name,
71 4
            'locked'          => $this->locked,
72 4
            'created_at'      => toArrayValue($this->created_at),
73 4
            'followers_count' => $this->followers_count,
74 4
            'following_count' => $this->following_count,
75 4
            'statuses_count'  => $this->statuses_count,
76 4
            'note'            => $this->note,
77 4
            'url'             => $this->url,
78 4
            'avatar'          => $this->avatar,
79 4
            'avatar_static'   => $this->avatar_static,
80 4
            'header'          => $this->header,
81 4
            'header_static'   => $this->header_static,
82
        ];
83
    }
84
}
85