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

Apps::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 9.2258
c 0
b 0
f 0
cc 1
eloc 45
nc 1
nop 1
1
<?php
2
3
namespace OneSignal;
4
5
use OneSignal\Resolver\ResolverFactory;
6
7
class Apps
8
{
9
    protected $api;
10
11
    private $resolverFactory;
12
13
    /**
14
     * Apps constructor.
15
     *
16
     * @param OneSignal       $api
17
     * @param ResolverFactory $resolverFactory
18
     */
19
    public function __construct(OneSignal $api, ResolverFactory $resolverFactory)
20
    {
21
        $this->api = $api;
22
        $this->resolverFactory = $resolverFactory;
23
    }
24
25
    /**
26
     * Get information about application with provided ID.
27
     *
28
     * User authentication key must be set.
29
     *
30
     * @param string $id ID of your application
31
     *
32
     * @return array
33
     */
34
    public function getOne($id)
35
    {
36
        return $this->api->request('GET', '/apps/'.$id, [
37
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
38
        ]);
39
    }
40
41
    /**
42
     * Get information about all your created applications.
43
     *
44
     * User authentication key must be set.
45
     *
46
     * @return array
47
     */
48
    public function getAll()
49
    {
50
        return $this->api->request('GET', '/apps', [
51
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
52
        ]);
53
    }
54
55
    /**
56
     * Create a new application with provided data.
57
     *
58
     * User authentication key must be set.
59
     *
60
     * @param array $data Application data
61
     *
62
     * @return array
63
     */
64 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...
65
    {
66
        $data = $this->resolverFactory->createAppResolver()->resolve($data);
67
68
        return $this->api->request('POST', '/apps', [
69
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
70
        ], json_encode($data));
71
    }
72
73
    /**
74
     * Update application with provided data.
75
     *
76
     * User authentication key must be set.
77
     *
78
     * @param string $id   ID of your application
79
     * @param array  $data New application data
80
     *
81
     * @return array
82
     */
83 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...
84
    {
85
        $data = $this->resolverFactory->createAppResolver()->resolve($data);
86
87
        return $this->api->request('PUT', '/apps/'.$id, [
88
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
89
        ], json_encode($data));
90
    }
91
}
92