Passed
Pull Request — master (#11)
by Pavel
07:39
created

RichJsonRpcRequest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 13.64 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 9
loc 66
ccs 14
cts 22
cp 0.6364
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isNotification() 0 4 1
A __construct() 0 5 2
A getAttributes() 0 4 1
A jsonSerialize() 9 9 1
A getVersion() 0 4 1
A getMethod() 0 4 1
A getParameters() 0 4 1
A getId() 0 4 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 Bankiru\Api\JsonRpc\Specification;
4
5
use Bankiru\Api\JsonRpc\BankiruJsonRpcServerBundle;
6
use Bankiru\Api\Rpc\RpcRequestInterface;
7
use ScayTrase\Api\JsonRpc\JsonRpcRequestInterface;
8
use Symfony\Component\HttpFoundation\ParameterBag;
9
10
final class RichJsonRpcRequest implements RpcRequestInterface, JsonRpcRequestInterface
11
{
12
    /** @var  JsonRpcRequestInterface */
13
    private $request;
14
    /** @var  ParameterBag */
15
    private $attributes;
16
17
    /**
18
     * RichJsonRpcRequest constructor.
19
     *
20
     * @param JsonRpcRequestInterface $request
21
     * @param ParameterBag            $attributes
22
     */
23 13
    public function __construct(JsonRpcRequestInterface $request, ParameterBag $attributes = null)
24
    {
25 13
        $this->request    = $request;
26 13
        $this->attributes = $attributes ?: new ParameterBag();
27 13
    }
28
29
    /** {@inheritdoc} */
30 13
    public function isNotification()
31
    {
32 13
        return $this->request->isNotification();
33
    }
34
35
    /** {@inheritdoc} */
36 13
    public function getAttributes()
37
    {
38 13
        return $this->attributes;
39
    }
40
41
    /** {@inheritdoc} */
42 View Code Duplication
    public function jsonSerialize()
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...
43
    {
44
        return [
45
            self::VERSION_FIELD    => $this->getVersion(),
46
            self::METHOD_FIELD     => $this->getMethod(),
47
            self::PARAMETERS_FIELD => $this->getParameters(),
48
            self::ID_FIELD         => $this->getId(),
49
        ];
50
    }
51
52
    /** {@inheritdoc} */
53
    public function getVersion()
54
    {
55
        return BankiruJsonRpcServerBundle::JSONRPC_VERSION;
56
    }
57
58
    /** {@inheritdoc} */
59 13
    public function getMethod()
60
    {
61 13
        return $this->request->getMethod();
62
    }
63
64
    /** {@inheritdoc} */
65 6
    public function getParameters()
66
    {
67 6
        return $this->request->getParameters();
68
    }
69
70
    /** {@inheritdoc} */
71 13
    public function getId()
72
    {
73 13
        return $this->request->getId();
74
    }
75
}
76