Pad   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A deletePad() 0 15 3
A getAllPadIds() 0 16 3
A getLastEdited() 0 15 3
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