Completed
Pull Request — master (#74)
by
unknown
01:30
created

Apps::getOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace OneSignal;
4
5
use OneSignal\Resolver\ResolverFactory;
6
7
class Apps
8
{
9
    /**
10
     * @var OneSignal
11
     */
12
    protected $api;
13
14
    /**
15
     * @var ResolverFactory
16
     */
17
    private $resolverFactory;
18
19
    /**
20
     * Apps constructor.
21
     *
22
     * @param OneSignal       $api
23
     * @param ResolverFactory $resolverFactory
24
     */
25
    public function __construct(OneSignal $api, ResolverFactory $resolverFactory)
26
    {
27
        $this->api = $api;
28
        $this->resolverFactory = $resolverFactory;
29
    }
30
31
    /**
32
     * Get information about application with provided ID.
33
     *
34
     * User authentication key must be set.
35
     *
36
     * @param string $id ID of your application
37
     *
38
     * @return array
39
     */
40
    public function getOne($id)
41
    {
42
        return $this->api->request('GET', '/apps/'.$id, [
43
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
44
        ]);
45
    }
46
47
    /**
48
     * Get information about all your created applications.
49
     *
50
     * User authentication key must be set.
51
     *
52
     * @return array
53
     */
54
    public function getAll()
55
    {
56
        return $this->api->request('GET', '/apps', [
57
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
58
        ]);
59
    }
60
61
    /**
62
     * Create a new application with provided data.
63
     *
64
     * User authentication key must be set.
65
     *
66
     * @param array $data Application data
67
     *
68
     * @return array
69
     */
70 View Code Duplication
    public function add(array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $data = $this->resolverFactory->createAppResolver()->resolve($data);
73
74
        return $this->api->request('POST', '/apps', [
75
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
76
        ], json_encode($data));
77
    }
78
79
    /**
80
     * Update application with provided data.
81
     *
82
     * User authentication key must be set.
83
     *
84
     * @param string $id   ID of your application
85
     * @param array  $data New application data
86
     *
87
     * @return array
88
     */
89 View Code Duplication
    public function update($id, array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91
        $data = $this->resolverFactory->createAppResolver()->resolve($data);
92
93
        return $this->api->request('PUT', '/apps/'.$id, [
94
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
95
        ], json_encode($data));
96
    }
97
}
98