Router::setAppId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Aosmak\Laravel\Layer\Sdk\Routers;
4
5
use Aosmak\Laravel\Layer\Sdk\Traits\ContainerTrait;
6
7
/**
8
 * Class Router
9
 * @package namespace Aosmak\Laravel\Layer\Sdk\Routers
10
 */
11
class Router implements RouterInterface
12
{
13
    use ContainerTrait;
14
15
    /**
16
     * Application ID
17
     *
18
     * @var string application ID
19
     */
20
    protected $appId;
21
22
    /**
23
     * Set an application ID
24
     *
25
     * @param string $appId application ID
26
     *
27
     * @return void
28
     */
29
    public function setAppId(string $appId): void
30 53
    {
31
        $this->appId = $appId;
32 53
    }
33 53
34
    /**
35
     * Generate a request URL
36
     *
37
     * @param integer $id user ID
38
     * @param array $data user data
39
     *
40
     * @return string
41
     */
42
    public function genereteURL(string $url, array $data): string
43 85
    {
44
        $data[':app_id'] = $this->appId;
45 85
46
        if (!empty($url)) {
47 85
            $url = '/' . $url;
48 83
        }
49
50
        return str_replace(array_keys($data), $data, ':app_id' . $url);
51 85
    }
52
53
    /**
54
     * Get a URL
55
     *
56
     * @param string $pattern base uri pattern
57
     * @param string $entityId entity ID
58
     * @param string $path path
59
     *
60
     * @return string
61
     */
62
    public function getShortUrl(string $pattern, string $entityId = null, string $path = null): string
63 74
    {
64
        if (!empty($entityId)) {
65 74
            $pattern = implode([$pattern, '/:entity_id']);
66
        }
67 74
68 57
        if (!empty($path)) {
69 57
            $pattern = implode([
70
                $pattern,
71
                '/',
72 74
                $path
73 44
            ]);
74 44
        }
75 44
76 44
        return $this->genereteURL($pattern, [':entity_id' => $entityId]);
77
    }
78
79
    /**
80 74
     * Get a content URL
81
     *
82
     * @param string $conversationId user ID
83
     * @param string $contentId contentId content item ID
84
     *
85
     * @return string
86
     */
87
    public function getContentUrl(string $conversationId, string $contentId): string
88
    {
89
        return $this->genereteURL('conversations/:conversation_id/content/:content_id', [
90
            ':conversation_id' => $conversationId,
91 2
            ':content_id'      => $contentId
92
        ]);
93 2
    }
94 2
95 2
    /**
96
     * Send message URL
97
     *
98
     * @param string $userId user ID
99
     * @param string $conversationId conversation ID
100
     *
101
     * @return string
102
     */
103
    public function sendMessagesURL(string $userId, string $conversationId): string
104
    {
105
        return $this->genereteURL('users/:user_id/conversations/:conversation_id/messages', [
106
            ':user_id'         => $userId,
107 2
            ':conversation_id' => $conversationId,
108
        ]);
109 2
    }
110 2
111 2
    /**
112
     * Get user message receipts URL
113
     *
114
     * @param string $userId user ID
115
     * @param string $messageId message ID
116
     *
117
     * @return string
118
     */
119
    public function getMessageReceiptsURL(string $userId, string $messageId): string
120
    {
121
        return $this->genereteURL('users/:user_id/messages/:message_id/receipts', [
122
            ':user_id'    => $userId,
123 2
            ':message_id' => $messageId,
124
        ]);
125 2
    }
126 2
127 2
    /**
128
     * Get a user message URL
129
     *
130
     * @param string $userId user ID
131
     * @param string $messageId message ID
132
     *
133
     * @return string
134
     */
135
    public function deleteMessageURL(string $userId, string $messageId): string
136
    {
137
        return $this->genereteURL('users/:user_id/messages/:message_id?mode=all_participants', [
138
            ':user_id'    => $userId,
139 2
            ':message_id' => $messageId,
140
        ]);
141 2
    }
142 2
143 2
    /**
144
     * Get a message URL
145
     *
146
     * @param string $messageId message ID
147
     * @param string $conversationId user ID
148
     *
149
     * @return string
150
     */
151
    public function getMessageURL(string $messageId, string $conversationId): string
152
    {
153
        return $this->genereteURL('conversations/:conversation_id/messages/:message_id', [
154
            ':conversation_id' => $conversationId,
155 4
            ':message_id'      => $messageId
156
        ]);
157 4
    }
158
}
159