Passed
Push — develop ( 3e77ee...386e9a )
by Edwin
02:50
created

Article::authors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ShopifyClient\Resource;
4
5
/**
6
 * https://help.shopify.com/api/reference/article
7
 */
8
class Article extends AbstractResource
9
{
10
    /**
11
     * @param float $blogId
12
     * @param float $id
13
     * @param array $fields
14
     * @return array
15
     */
16 1
    public function get(float $blogId, float $id, array $fields = [])
17
    {
18 1
        $response = $this->request('GET', sprintf('/admin/blogs/%s/articles/%s.json', $blogId, $id), [
19
            'query' => [
20 1
                'fields' => $fields
21
            ]
22
        ]);
23
24 1
        return $response['article'];
25
    }
26
27
    /**
28
     * @param float $id
29
     * @param array $query
30
     * @return array
31
     */
32 1
    public function all(float $id, array $query = [])
33
    {
34 1
        $response = $this->request('GET', sprintf('/admin/blogs/%s/articles.json', $id), [
35 1
            'query' => $query
36
        ]);
37
38 1
        return $response['articles'];
39
    }
40
41
    /**
42
     * @param float $id
43
     * @param array $query
44
     * @return array
45
     */
46 1
    public function count(float $id, array $query = [])
47
    {
48 1
        $response = $this->request('GET', sprintf('/admin/blogs/%s/articles/count.json', $id), [
49 1
            'query' => $query
50
        ]);
51
52 1
        return $response['count'];
53
    }
54
55
    /**
56
     * @param float $id
57
     * @param array $params
58
     * @return array
59
     */
60 1
    public function create(float $id, array $params = [])
61
    {
62 1
        $response = $this->request('POST', sprintf('/admin/blogs/%s/articles.json', $id), [
63 1
            'body' => json_encode([
64 1
                'article' => $params,
65
            ]),
66
        ]);
67
68 1
        return $response['article'];
69
    }
70
71
    /**
72
     * @param float $blogId
73
     * @param float $id
74
     * @param array $params
75
     * @return array
76
     */
77 1
    public function update(float $blogId, float $id, array $params = [])
78
    {
79 1
        $response = $this->request('PUT', sprintf('/admin/blogs/%s/articles/%s.json', $blogId, $id), [
80 1
            'body' => json_encode([
81 1
                'article' => $params,
82
            ]),
83
        ]);
84
85 1
        return $response['article'];
86
    }
87
88
    /**
89
     * @param float $blogId
90
     * @param float $id
91
     */
92 1
    public function delete(float $blogId, float $id)
93
    {
94 1
        $this->request('DELETE', sprintf('/admin/blogs/%s/articles/%s.json', $blogId, $id));
95 1
    }
96
97
    /**
98
     * @param float $id
99
     * @param array $query
100
     * @return array
101
     */
102 1
    public function tags(float $id, array $query = [])
103
    {
104 1
        $response = $this->request('GET', sprintf('/admin/blogs/%s/articles/tags.json', $id), [
105 1
            'query' => $query,
106
        ]);
107
108 1
        return $response['tags'];
109
    }
110
111
    /**
112
     * @return array
113
     */
114 1
    public function authors()
115
    {
116 1
        $response = $this->request('GET', '/admin/articles/authors.json');
117
118 1
        return $response['authors'];
119
    }
120
}
121