Pad::getAllPadIds()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace EtherpadLite\Helper;
4
5
use EtherpadLite\Client;
6
use EtherpadLite\Response;
7
8
class Pad
9
{
10
    /**
11
     * @param $padId
12
     * @param $apiKey
13
     * @param string $host
14
     * @return boolean
15
     */
16
    public static function deletePad($padId, $apiKey, $host = 'http://localhost:9001')
17
    {
18
        $client = new Client($apiKey, $host);
19
        try {
20
           $response = $client->deletePad($padId);
21
        } catch (\Exception $e) {
22
            return false;
23
        }
24
25
        if ($response->getCode() == Response::CODE_OK) {
26
            return true;
27
        } else {
28
            return false;
29
        }
30
    }
31
32
    /**
33
     * @param $apiKey
34
     * @param string $host
35
     * @return array
36
     */
37
    public static function getAllPadIds($apiKey, $host = 'http://localhost:9001')
38
    {
39
        $client = new Client($apiKey, $host);
40
41
        try {
42
            $response = $client->listAllPads();
43
        } catch (\Exception $e) {
44
            return [];
45
        }
46
47
        if ($response->getCode() == Response::CODE_OK) {
48
            return $response->getData()['padIDs'];
49
        } else {
50
            return [];
51
        }
52
    }
53
54
    /**
55
     * @param $padId
56
     * @param $apiKey
57
     * @param string $host
58
     * @return int|false
59
     */
60
    public static function getLastEdited($padId, $apiKey, $host = 'http://localhost:9001')
61
    {
62
        $client = new Client($apiKey, $host);
63
        try {
64
            $response = $client->getLastEdited($padId);
65
        } catch (\Exception $e) {
66
            return false;
67
        }
68
69
        if ($response->getCode() == Response::CODE_OK) {
70
            return $response->getData()['lastEdited'] / 1000;
71
        } else {
72
            return false;
73
        }
74
    }
75
}
76