Completed
Push — v3 ( d12fea )
by Beñat
05:39
created

AcceptAnswerCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 58
loc 58
wmc 4
lcom 0
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 2
A url() 4 4 1
A params() 4 4 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 BenatEspina\StackExchangeApiClient\Application\Service\Answer;
4
5
/**
6
 * Accept answer command.
7
 *
8
 * @author Beñat Espiña <[email protected]>
9
 */
10 View Code Duplication
class AcceptAnswerCommand
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    const URL = '/answers/%s/accept';
13
14
    /**
15
     * The API URL.
16
     *
17
     * @var string
18
     */
19
    private $url;
20
21
    /**
22
     * Array that contains StackExchange API params.
23
     *
24
     * @var array
25
     */
26
    private $params;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param array|string $id     The answer id. Also, it can be multiple ids separated by semicolon.
32
     * @param array        $params Array that contains StackExchange API params
33
     */
34
    public function __construct($id, array $params = ['site' => 'stackoverflow'])
35
    {
36
        if (empty($params)) {
37
            $params = [
38
                'order' => 'desc',
39
                'sort'  => 'activity',
40
                'site'  => 'stackoverflow',
41
            ];
42
        }
43
44
        $this->params = $params;
45
        $this->url = sprintf(self::URL, $id);
46
    }
47
48
    /**
49
     * The API URL.
50
     *
51
     * @return string
52
     */
53
    public function url()
54
    {
55
        return $this->url;
56
    }
57
58
    /**
59
     * Gets the params.
60
     *
61
     * @return array
62
     */
63
    public function params()
64
    {
65
        return $this->params;
66
    }
67
}
68