Add::single()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 4
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
namespace ArianRashidi\PocketApi\Api;
3
4
/**
5
 * Class Add
6
 *
7
 * @package ArianRashidi\PocketApi\Api
8
 */
9
class Add extends Api
10
{
11
    /**
12
     * Add a single link to Pocket.
13
     *
14
     * @param string      $url
15
     * @param string|null $title
16
     * @param array|null  $tags
17
     * @param int|null    $tweetId
18
     *
19
     * @return mixed
20
     */
21
    public function single(string $url, string $title = null, array $tags = null, int $tweetId = null)
22
    {
23
        $data = $this->keys() + ['time' => time(), 'url' => utf8_encode($url)];
24
        if (!is_null($title)) {
25
            $data = $data + ['title' => utf8_encode($title)];
26
        }
27
        if (!is_null($tags)) {
28
            $data = $data + ['tags' => implode(',', $tags)];
29
        }
30
        if (!is_null($tweetId)) {
31
            $data = $data + ['tweet_id' => $tweetId];
32
        }
33
34
        $response = $this->request('/v3/add', $data);
35
        $responseData = json_decode($response->getBody());
36
37
        return $responseData;
38
    }
39
}
40