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

Apps   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 16
loc 88
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOne() 0 6 1
A getAll() 0 6 1
A add() 8 8 1
A update() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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