UserRegistrationResult   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 11.49 %

Importance

Changes 0
Metric Value
wmc 9
dl 10
loc 87
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getTenant() 0 3 1
A setScope() 0 3 1
A getScope() 0 3 1
A setSub() 0 7 2
A setTenant() 0 7 2
A getSub() 0 3 1
A __construct() 9 9 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\RegistrationResult;
7
8
/**
9
 * Class UserRegistrationResult.
10
 */
11
class UserRegistrationResult extends RegistrationResult
12
{
13
    /**
14
     * @var string
15
     */
16
    private $tenant;
17
18
    /**
19
     * @var string
20
     */
21
    private $scope;
22
23
    /**
24
     * @var string
25
     */
26
    private $sub;
27
28
    /**
29
     * UserRegistrationResult constructor.
30
     *
31
     * @param array $params
32
     */
33 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...
34
    {
35
        parent::__construct($params);
36
37
        $this->validateParams($params, ['tenant', 'sub']);
38
39
        $this->setTenant($params['tenant']);
40
        $this->setSub($params['sub']);
41
        $this->setScope($params['scope'] ?? '');
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getTenant(): string
48
    {
49
        return $this->tenant;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getScope(): string
56
    {
57
        return $this->scope;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getSub(): string
64
    {
65
        return $this->sub;
66
    }
67
68
    /**
69
     * @param string $tenant
70
     */
71
    private function setTenant(string $tenant)
72
    {
73
        if (empty($tenant)) {
74
            throw new InvalidArgumentException('Tenant value can not be empty');
75
        }
76
77
        $this->tenant = $tenant;
78
    }
79
80
    /**
81
     * @param string $scope
82
     */
83
    private function setScope(string $scope)
84
    {
85
        $this->scope = $scope;
86
    }
87
88
    /**
89
     * @param string $sub
90
     */
91
    private function setSub(string $sub)
92
    {
93
        if (empty($sub)) {
94
            throw new InvalidArgumentException('Sub value can not be empty');
95
        }
96
97
        $this->sub = $sub;
98
    }
99
}
100