Completed
Pull Request — master (#1)
by Tobias
03:18
created

Statement   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 26.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 12
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A next() 12 12 1
A answer() 0 13 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 Happyr\ApiClient\Api;
4
5
use Happyr\ApiClient\Assert;
6
use Psr\Http\Message\ResponseInterface;
7
use Happyr\ApiClient\Model\Statement\Statement as StatementModel;
8
9
/**
10
 * @author Tobias Nyholm <[email protected]>
11
 */
12
final class Statement extends HttpApi
13
{
14
    /**
15
     * @param $user
16
     * @param array $patterns
17
     * @param array $params   valid keys are limit and locale
18
     *
19
     * @return StatementModel|ResponseInterface
20
     */
21 View Code Duplication
    public function next($user, array $patterns, array $params)
0 ignored issues
show
Duplication introduced by
This method 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...
22
    {
23
        Assert::stringNotEmpty($user);
24
        Assert::notEmpty($patterns);
25
26
        $params['user'] = $user;
27
        $params['pattern'] = implode(',', $patterns);
28
29
        $response = $this->httpGet('/api/pattern/next-statement', $params);
30
31
        return $this->hydrateResponse($response, StatementModel::class);
32
    }
33
34
    /**
35
     * @param $user
36
     * @param array $patterns
37
     * @param $statement
38
     * @param $answer
39
     * @param array $params valid keys are locale
40
     *
41
     * @return StatementModel|ResponseInterface
42
     */
43
    public function answer($user, array $patterns, $statement, $answer, array $params)
44
    {
45
        Assert::stringNotEmpty($user);
46
        Assert::notEmpty($patterns);
47
48
        $params['user'] = $user;
49
        $params['pattern'] = implode(',', $patterns);
50
        $params['answer'] = $answer;
51
52
        $response = $this->httpGet(sprintf('/api/pattern/%s', $statement), $params);
53
54
        return $this->hydrateResponse($response, StatementModel::class);
55
    }
56
}
57