GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PostsApi   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 129
ccs 33
cts 33
cp 1
rs 10
wmc 13

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createPost() 0 5 1
A unpinPost() 0 9 2
A getPost() 0 9 2
A deletePost() 0 9 2
A patchPost() 0 9 2
A updatePost() 0 9 2
A pinPost() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pnz\MattermostClient\Api;
6
7
use Pnz\MattermostClient\Exception\InvalidArgumentException;
8
use Pnz\MattermostClient\Model\Post\Post;
9
use Pnz\MattermostClient\Model\Status;
10
use Psr\Http\Message\ResponseInterface;
11
12
final class PostsApi extends HttpApi
13
{
14
    /**
15
     * Create a post. Required parameters: 'channel_id', 'message'.
16
     *
17
     * @return Post|ResponseInterface
18
     */
19 8
    public function createPost(array $params)
20
    {
21 8
        $response = $this->httpPost('/posts', $params);
22
23 8
        return $this->handleResponse($response, Post::class);
24
    }
25
26
    /**
27
     * Partially update a post by providing only the fields you want to update.
28
     * Omitted fields will not be updated.
29
     *
30
     * @see https://api.mattermost.com/v4/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1patch%2Fput
31
     *
32
     * @return Post|ResponseInterface
33
     */
34 9
    public function patchPost(string $postId, array $params)
35
    {
36 9
        if (empty($postId)) {
37 1
            throw new InvalidArgumentException('PostId can not be empty');
38
        }
39
40 8
        $response = $this->httpPut(sprintf('/posts/%s/patch', $postId), $params);
41
42 8
        return $this->handleResponse($response, Post::class);
43
    }
44
45
    /**
46
     * Update a post.
47
     *
48
     * @see https://api.mattermost.com/v4/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D%2Fput
49
     *
50
     * @param string $postId ID of the post to update
51
     *
52
     * @return Post|ResponseInterface
53
     */
54 9
    public function updatePost(string $postId, array $params)
55
    {
56 9
        if (empty($postId)) {
57 1
            throw new InvalidArgumentException('PostId can not be empty');
58
        }
59
60 8
        $response = $this->httpPut(sprintf('/posts/%s', $postId), $params);
61
62 8
        return $this->handleResponse($response, Post::class);
63
    }
64
65
    /**
66
     * Get a single post.
67
     *
68
     * @param string $postId ID of the post to get
69
     *
70
     * @return Post|ResponseInterface
71
     */
72 9
    public function getPost(string $postId)
73
    {
74 9
        if (empty($postId)) {
75 1
            throw new InvalidArgumentException('PostId can not be empty');
76
        }
77
78 8
        $response = $this->httpGet(sprintf('/posts/%s', $postId));
79
80 8
        return $this->handleResponse($response, Post::class);
81
    }
82
83
    /**
84
     * Pin a post to a channel it is in based from the provided post id string.
85
     *
86
     * @see https://api.mattermost.com/v4/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1pin%2Fpost
87
     *
88
     * @param string $postId Post GUID
89
     *
90
     * @return Status|ResponseInterface
91
     */
92 9
    public function pinPost($postId)
93
    {
94 9
        if (empty($postId)) {
95 1
            throw new InvalidArgumentException('PostId can not be empty');
96
        }
97
98 8
        $response = $this->httpPost(sprintf('/posts/%s/pin', $postId));
99
100 8
        return $this->handleResponse($response, Status::class);
101
    }
102
103
    /**
104
     * Unpin a post to a channel it is in based from the provided post id string.
105
     *
106
     * @see https://api.mattermost.com/v4/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1unpin%2Fpost
107
     *
108
     * @param string $postId Post GUID
109
     *
110
     * @return Status|ResponseInterface
111
     */
112 9
    public function unpinPost($postId)
113
    {
114 9
        if (empty($postId)) {
115 1
            throw new InvalidArgumentException('PostId can not be empty');
116
        }
117
118 8
        $response = $this->httpPost(sprintf('/posts/%s/unpin', $postId));
119
120 8
        return $this->handleResponse($response, Status::class);
121
    }
122
123
    /**
124
     * Soft deletes a post, by marking the post as deleted in the database. Soft deleted posts will not be returned in post queries.
125
     *
126
     * @see https://api.mattermost.com/v4/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D%2Fdelete
127
     *
128
     * @param string $postId ID of the post to delete
129
     *
130
     * @return Status|ResponseInterface
131
     */
132 9
    public function deletePost(string $postId)
133
    {
134 9
        if (empty($postId)) {
135 1
            throw new InvalidArgumentException('PostId can not be empty');
136
        }
137
138 8
        $response = $this->httpDelete(sprintf('/posts/%s', $postId));
139
140 8
        return $this->handleResponse($response, Status::class);
141
    }
142
}
143