GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Pins   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 8.14 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 7
loc 86
ccs 17
cts 20
cp 0.85
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 1
A fromBoard() 0 5 1
A create() 0 13 3
A edit() 7 7 2
A delete() 0 5 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
 * Copyright 2015 Dirk Groenen
4
 *
5
 * (c) Dirk Groenen <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace DirkGroenen\Pinterest\Endpoints;
12
13
use DirkGroenen\Pinterest\Models\Pin;
14
use DirkGroenen\Pinterest\Models\Collection;
15
16
class Pins extends Endpoint {
17
18
    /**
19
     * Get a pin object
20
     *
21
     * @access public
22
     * @param  string   $pin_id
23
     * @param array     $data
24
     * @throws \DirkGroenen\Pinterest\Exceptions\PinterestException
25
     * @return Pin
26
     */
27 3
    public function get($pin_id, array $data = [])
28
    {
29 3
        $response = $this->request->get(sprintf("pins/%s/", $pin_id), $data);
30 3
        return new Pin($this->master, $response);
31
    }
32
33
    /**
34
     * Get all pins from the given board
35
     *
36
     * @access public
37
     * @param  string   $board_id
38
     * @param array     $data
39
     * @throws \DirkGroenen\Pinterest\Exceptions\PinterestException
40
     * @return Collection
41
     */
42 1
    public function fromBoard($board_id, array $data = [])
43
    {
44 1
        $response = $this->request->get(sprintf("boards/%s/pins/", $board_id), $data);
45 1
        return new Collection($this->master, $response, "Pin");
46
    }
47
48
    /**
49
     * Create a pin
50
     *
51
     * @access public
52
     * @param  array    $data
53
     * @throws \DirkGroenen\Pinterest\Exceptions\PinterestException
54
     * @return Pin
55
     */
56 1
    public function create(array $data)
57
    {
58 1
        if (array_key_exists("image", $data)) {
59
            if (class_exists('\CURLFile')) {
60
                $data["image"] = new \CURLFile($data['image']);
61
            } else {
62
                $data["image"] = '@' . $data['image'];
63
            }
64
        }
65
66 1
        $response = $this->request->post("pins/", $data);
67 1
        return new Pin($this->master, $response);
68
    }
69
70
    /**
71
     * Edit a pin
72
     *
73
     * @access public
74
     * @param  string   $pin_id
75
     * @param  array    $data
76
     * @param  string   $fields
77
     * @throws \DirkGroenen\Pinterest\Exceptions\PinterestException
78
     * @return Pin
79
     */
80 1 View Code Duplication
    public function edit($pin_id, array $data, $fields = null)
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...
81
    {
82 1
        $query = (!$fields) ? array() : array("fields" => $fields);
83
84 1
        $response = $this->request->update(sprintf("pins/%s/", $pin_id), $data, $query);
85 1
        return new Pin($this->master, $response);
86
    }
87
88
    /**
89
     * Delete a pin
90
     *
91
     * @access public
92
     * @param  string   $pin_id
93
     * @throws \DirkGroenen\Pinterest\Exceptions\PinterestException
94
     * @return boolean
95
     */
96 1
    public function delete($pin_id)
97
    {
98 1
        $this->request->delete(sprintf("pins/%s/", $pin_id));
99 1
        return true;
100
    }
101
}
102