UserTokenVerificationResult   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 109
Duplicated Lines 10.09 %

Importance

Changes 0
Metric Value
wmc 11
dl 11
loc 109
c 0
b 0
f 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setSub() 0 7 2
A getSub() 0 3 1
A setDeviceId() 0 7 2
A setExp() 0 3 1
A getExp() 0 3 1
A getScope() 0 3 1
A getDeviceId() 0 3 1
A __construct() 10 10 1
A setScope() 0 3 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 JincorTech\AuthClient;
4
5
use InvalidArgumentException;
6
use JincorTech\AuthClient\Abstracts\VerificationResult;
7
8
/**
9
 * Class UserTokenVerificationResult.
10
 */
11
class UserTokenVerificationResult extends VerificationResult
12
{
13
    /**
14
     * @var string
15
     */
16
    private $scope;
17
18
    /**
19
     * @var string
20
     */
21
    private $deviceId;
22
23
    /**
24
     * @var string
25
     */
26
    private $sub;
27
28
    /**
29
     * @var int
30
     */
31
    private $exp;
32
33
    /**
34
     * UserTokenVerificationResult constructor.
35
     *
36
     * @param array $params
37
     */
38 View Code Duplication
    public function __construct(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...
39
    {
40
        parent::__construct($params);
41
42
        $this->validateParams($params, ['deviceId', 'sub', 'exp']);
43
44
        $this->setDeviceId($params['deviceId']);
45
        $this->setSub($params['sub']);
46
        $this->setExp($params['exp']);
0 ignored issues
show
Bug introduced by
It seems like $params['exp'] can also be of type string; however, parameter $exp of JincorTech\AuthClient\Us...icationResult::setExp() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $this->setExp(/** @scrutinizer ignore-type */ $params['exp']);
Loading history...
47
        $this->setScope($params['scope'] ?? '');
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getScope(): string
54
    {
55
        return $this->scope;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getDeviceId(): string
62
    {
63
        return $this->deviceId;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getSub(): string
70
    {
71
        return $this->sub;
72
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function getExp(): int
78
    {
79
        return $this->exp;
80
    }
81
82
    /**
83
     * @param string $scope
84
     */
85
    private function setScope(string $scope)
86
    {
87
        $this->scope = $scope;
88
    }
89
90
    /**
91
     * @param string $deviceId
92
     */
93
    private function setDeviceId(string $deviceId)
94
    {
95
        if (empty($deviceId)) {
96
            throw new InvalidArgumentException('DeviceId value can not be empty');
97
        }
98
99
        $this->deviceId = $deviceId;
100
    }
101
102
    /**
103
     * @param string $sub
104
     */
105
    private function setSub(string $sub)
106
    {
107
        if (empty($sub)) {
108
            throw new InvalidArgumentException('Sub value can not be empty');
109
        }
110
111
        $this->sub = $sub;
112
    }
113
114
    /**
115
     * @param int $exp
116
     */
117
    private function setExp(int $exp)
118
    {
119
        $this->exp = $exp;
120
    }
121
}
122