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

AnswersOfIdsHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 48
wmc 2
lcom 1
cbo 3
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 10 1
1
<?php
2
3
namespace BenatEspina\StackExchangeApiClient\Application\Service\Answer;
4
5
use BenatEspina\StackExchangeApiClient\Application\DataTransformer\ResponseAnswerDataTransformer;
6
use BenatEspina\StackExchangeApiClient\Domain\Model\Http;
7
8
/**
9
 * Answers of ids command handler.
10
 *
11
 * @author Beñat Espiña <[email protected]>
12
 */
13
class AnswersOfIdsHandler
14
{
15
    /**
16
     * The data transformer.
17
     *
18
     * @var ResponseAnswerDataTransformer
19
     */
20
    private $dataTransformer;
21
22
    /**
23
     * The HTTP domain class.
24
     *
25
     * @var Http
26
     */
27
    private $http;
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param Http                          $http            The HTTP domain class
33
     * @param ResponseAnswerDataTransformer $dataTransformer The answer data transformer
34
     */
35
    public function __construct(Http $http, ResponseAnswerDataTransformer $dataTransformer)
36
    {
37
        $this->http = $http;
38
        $this->dataTransformer = $dataTransformer;
39
    }
40
41
    /**
42
     * Get answers identified by a set of ids.
43
     *
44
     * More info: http://api.stackexchange.com/docs/answers-by-ids
45
     *
46
     * @param AnswersOfIdsCommand $command The command
47
     *
48
     * @return mixed
49
     */
50
    public function handle(AnswersOfIdsCommand $command)
51
    {
52
        $response = $this->http->get(
53
            $command->url(),
54
            $command->params()
55
        );
56
        $this->dataTransformer->write($response);
57
58
        return $this->dataTransformer->read();
59
    }
60
}
61