Completed
Push — master ( 716e15...7881d6 )
by Cheren
02:20
created

User   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 32.26 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _getActivationUrl() 10 10 1
A _getSetupPasswordUrl() 10 10 1
A _setPassword() 0 8 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
 * CakeCMS Community
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Community
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Community".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Community\Model\Entity;
17
18
use Cake\Routing\Router;
19
use Cake\I18n\FrozenTime;
20
use Core\ORM\Entity\Entity;
21
use Cake\Auth\DefaultPasswordHasher;
22
23
/**
24
 * Class User
25
 *
26
 * @package Community\Model\Entity
27
 *
28
 * @property int        $id
29
 * @property int        $group_id
30
 * @property Group      $group
31
 * @property string     $login
32
 * @property string     $name
33
 * @property string     $slug
34
 * @property string     $email
35
 * @property string     $password
36
 * @property string     $token
37
 * @property bool       $status
38
 * @property FrozenTime $last_login
39
 * @property FrozenTime $last_action
40
 * @property FrozenTime $modified
41
 * @property FrozenTime $created
42
 * @property string     activation_url  Virtual field.
43
 */
44
class User extends Entity
45
{
46
47
    /**
48
     * List of computed or virtual fields that **should** be included in JSON or array
49
     * representations of this Entity. If a field is present in both _hidden and _virtual
50
     * the field will **not** be in the array/json versions of the entity.
51
     *
52
     * @var array
53
     */
54
    protected $_virtual = [
55
        'activation_url',
56
        'setup_password_url'
57
    ];
58
59
    /**
60
     * Set virtual field activation_url.
61
     *
62
     * @return  string
63
     */
64 View Code Duplication
    protected function _getActivationUrl()
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...
65
    {
66
        return Router::url([
67
            'controller' => 'Users',
68
            'action'     => 'activate',
69
            'plugin'     => 'Community',
70
            $this->id,
71
            $this->token
72
        ], true);
73
    }
74
75
    /**
76
     * set virtual field setup_password_url
77
     *
78
     * @return string
79
     */
80 View Code Duplication
    protected function _getSetupPasswordUrl()
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...
81
    {
82
        return Router::url([
83
            'controller' => 'Users',
84
            'plugin'     => 'Community',
85
            'action'     => 'setupPassword',
86
            $this->id,
87
            $this->token
88
        ], true);
89
    }
90
91
    /**
92
     * Setup password.
93
     *
94
     * @param   string $password    User password for create hashed.
95
     * @return  null|string
96
     */
97
    protected function _setPassword($password)
98
    {
99
        if ($password !== null) {
100
            return (new DefaultPasswordHasher())->hash($password);
101
        }
102
103
        return null;
104
    }
105
}
106