Completed
Push — v3 ( d12fea...862d0b )
by Beñat
03:42
created

AnswersOfIdsHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A handle() 12 12 2

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
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2014-2016 Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace BenatEspina\StackExchangeApiClient\Application\Service\Answer;
13
14
use BenatEspina\StackExchangeApiClient\Application\DataTransformer\ResponseAnswerDataTransformer;
15
use BenatEspina\StackExchangeApiClient\Domain\Model\Authentication;
16
use BenatEspina\StackExchangeApiClient\Domain\Model\Http;
17
18
/**
19
 * Answers of ids command handler.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23 View Code Duplication
class AnswersOfIdsHandler
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...
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