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

AnswersOfIdsCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A url() 0 4 1
A params() 0 4 1
1
<?php
2
3
namespace BenatEspina\StackExchangeApiClient\Application\Service\Answer;
4
5
/**
6
 * Answers of ids command.
7
 *
8
 * @author Beñat Espiña <[email protected]>
9
 */
10
class AnswersOfIdsCommand
11
{
12
    const URL = '/answers/%s';
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, is_array($id) ? implode(';', $id) : $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