Folders   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 25
c 2
b 1
f 0
dl 0
loc 100
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteById() 0 6 1
A listAll() 0 7 1
A listContentsById() 0 10 1
A __construct() 0 5 1
A listById() 0 6 1
A create() 0 10 1
1
<?php
2
3
namespace vinicinbgs\Autentique;
4
5
use vinicinbgs\Autentique\Utils\Query;
6
7
/**
8
 * Class Folders
9
 * @package vinicinbgs\Autentique
10
 * @see https://beadev.net/autentique-v2/folders
11
 */
12
class Folders extends BaseResource
13
{
14
    /**
15
     * @var Query
16
     */
17
    private $query;
18
19
    /**
20
     * Documents constructor.
21
     *
22
     * @param string|null $token Autentique API Token
23
     * @param int $timeout=60 Request Timeout in seconds
24
     */
25
    public function __construct(string $token = null, int $timeout = 60)
26
    {
27
        parent::__construct($token, $timeout);
28
29
        $this->query = new Query($this->resourcesEnum::FOLDERS);
30
    }
31
32
    /**
33
     * List all folders
34
     *
35
     * @param int $page
36
     * @return array
37
     */
38
    public function listAll(int $page = 1): array
39
    {
40
        $graphQuery = $this->query->query(__FUNCTION__);
41
42
        $graphQuery = $this->query->setVariables("page", $page, $graphQuery);
43
44
        return $this->api->request($this->token, $graphQuery, "json");
45
    }
46
47
    /**
48
     * List folder by id
49
     *
50
     * @param string $folderId
51
     *
52
     * @return array
53
     */
54
    public function listById(string $folderId): array
55
    {
56
        $graphQuery = $this->query->query(__FUNCTION__);
57
        $graphQuery = $this->query->setVariables("folderId", $folderId, $graphQuery);
58
59
        return $this->api->request($this->token, $graphQuery, "json");
60
    }
61
62
    /**
63
     * List folder by id
64
     *
65
     * @param string $folderId
66
     *
67
     * @return array
68
     */
69
    public function listContentsById(string $folderId, int $page = 1): array
70
    {
71
        $graphQuery = $this->query->query(__FUNCTION__);
72
        $graphQuery = $this->query->setVariables(
73
            ["folderId", "page"],
74
            [$folderId, $page],
75
            $graphQuery
76
        );
77
78
        return $this->api->request($this->token, $graphQuery, "json");
79
    }
80
81
    /**
82
     * Create folder
83
     *
84
     * @param array $variables
85
     * @return array
86
     */
87
    public function create(array $variables): array
88
    {
89
        $graphMutation = $this->query->query(__FUNCTION__);
90
        $graphMutation = $this->query->setVariables(
91
            ["variables", "sandbox"],
92
            [json_encode($variables), $this->sandbox],
93
            $graphMutation
94
        );
95
96
        return $this->api->request($this->token, $graphMutation, "json");
97
    }
98
99
    /**
100
     * Delete folder by id
101
     *
102
     * @param string $folderId
103
     *
104
     * @return array
105
     */
106
    public function deleteById(string $folderId): array
107
    {
108
        $graphQuery = $this->query->query(__FUNCTION__);
109
        $graphQuery = $this->query->setVariables("folderId", $folderId, $graphQuery);
110
111
        return $this->api->request($this->token, $graphQuery, "json");
112
    }
113
}
114