Code Duplication    Length = 62-62 lines in 2 locations

src/BenatEspina/StackExchangeApiClient/Application/Service/Answer/AllAnswersHandler.php 1 location

@@ 23-84 (lines=62) @@
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class AllAnswersHandler
24
{
25
    /**
26
     * The data transformer.
27
     *
28
     * @var ResponseAnswerDataTransformer
29
     */
30
    private $dataTransformer;
31
32
    /**
33
     * The HTTP domain class.
34
     *
35
     * @var Http
36
     */
37
    private $http;
38
39
    /**
40
     * The authentication, it is not mandatory.
41
     *
42
     * @var Authentication|null
43
     */
44
    private $authentication;
45
46
    /**
47
     * Constructor.
48
     *
49
     * @param Http                          $http             The HTTP domain class
50
     * @param ResponseAnswerDataTransformer $dataTransformer  The answer data transformer
51
     * @param Authentication|null           $anAuthentication The authentication, it is not mandatory
52
     */
53
    public function __construct(
54
        Http $http,
55
        ResponseAnswerDataTransformer $dataTransformer,
56
        Authentication $anAuthentication = null
57
    ) {
58
        $this->http = $http;
59
        $this->dataTransformer = $dataTransformer;
60
        $this->authentication = $anAuthentication;
61
    }
62
63
    /**
64
     * Get answers identified by a set of ids.
65
     *
66
     * More info: http://api.stackexchange.com/docs/answers-by-ids
67
     *
68
     * @param AllAnswersCommand $command The command
69
     *
70
     * @return mixed
71
     */
72
    public function handle(AllAnswersCommand $command)
73
    {
74
        $parameters = $command->params();
75
        if ($this->authentication instanceof Authentication) {
76
            $parameters = array_merge($parameters, $this->authentication->toArray());
77
        }
78
79
        $response = $this->http->get($command->url(), $parameters);
80
        $this->dataTransformer->write($response);
81
82
        return $this->dataTransformer->read();
83
    }
84
}
85

src/BenatEspina/StackExchangeApiClient/Application/Service/Answer/AnswersOfIdsHandler.php 1 location

@@ 23-84 (lines=62) @@
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class AnswersOfIdsHandler
24
{
25
    /**
26
     * The data transformer.
27
     *
28
     * @var ResponseAnswerDataTransformer
29
     */
30
    private $dataTransformer;
31
32
    /**
33
     * The HTTP domain class.
34
     *
35
     * @var Http
36
     */
37
    private $http;
38
39
    /**
40
     * The authentication, it is not mandatory.
41
     *
42
     * @var Authentication|null
43
     */
44
    private $authentication;
45
46
    /**
47
     * Constructor.
48
     *
49
     * @param Http                          $http             The HTTP domain class
50
     * @param ResponseAnswerDataTransformer $dataTransformer  The answer data transformer
51
     * @param Authentication|null           $anAuthentication The authentication, it is not mandatory
52
     */
53
    public function __construct(
54
        Http $http,
55
        ResponseAnswerDataTransformer $dataTransformer,
56
        Authentication $anAuthentication = null
57
    ) {
58
        $this->http = $http;
59
        $this->dataTransformer = $dataTransformer;
60
        $this->authentication = $anAuthentication;
61
    }
62
63
    /**
64
     * Get answers identified by a set of ids.
65
     *
66
     * More info: http://api.stackexchange.com/docs/answers-by-ids
67
     *
68
     * @param AnswersOfIdsCommand $command The command
69
     *
70
     * @return mixed
71
     */
72
    public function handle(AnswersOfIdsCommand $command)
73
    {
74
        $parameters = $command->params();
75
        if ($this->authentication instanceof Authentication) {
76
            $parameters = array_merge($parameters, $this->authentication->toArray());
77
        }
78
79
        $response = $this->http->get($command->url(), $parameters);
80
        $this->dataTransformer->write($response);
81
82
        return $this->dataTransformer->read();
83
    }
84
}
85