Completed
Push — master ( 67fdac...838896 )
by giu
38s
created

UsersTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 29.31 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 17
loc 58
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 10 1
A validationDefault() 17 17 1
A buildRules() 0 6 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
namespace App\Model\Table;
3
4
use Cake\ORM\Query;
5
use Cake\ORM\RulesChecker;
6
use Cake\ORM\Table;
7
use Cake\Validation\Validator;
8
9
/**
10
 * Users Model
11
 *
12
 * @method \App\Model\Entity\User get($primaryKey, $options = [])
13
 * @method \App\Model\Entity\User newEntity($data = null, array $options = [])
14
 * @method \App\Model\Entity\User[] newEntities(array $data, array $options = [])
15
 * @method \App\Model\Entity\User|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
16
 * @method \App\Model\Entity\User patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
17
 * @method \App\Model\Entity\User[] patchEntities($entities, array $data, array $options = [])
18
 * @method \App\Model\Entity\User findOrCreate($search, callable $callback = null, $options = [])
19
 *
20
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
21
 */
22
class UsersTable extends Table
23
{
24
25
    /**
26
     * Initialize method
27
     *
28
     * @param array $config The configuration for the Table.
29
     * @return void
30
     */
31 4
    public function initialize(array $config)
32
    {
33 4
        parent::initialize($config);
34
35 4
        $this->table('users');
36 4
        $this->displayField('id');
37 4
        $this->primaryKey('id');
38
39 4
        $this->addBehavior('Timestamp');
40 4
    }
41
42
    /**
43
     * Default validation rules.
44
     *
45
     * @param \Cake\Validation\Validator $validator Validator instance.
46
     * @return \Cake\Validation\Validator
47
     */
48 2 View Code Duplication
    public function validationDefault(Validator $validator)
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...
49
    {
50
        $validator
51 2
            ->integer('id')
52 2
            ->allowEmpty('id', 'create');
53
54
        $validator
55 2
            ->email('email')
56 2
            ->requirePresence('email', 'create')
57 2
            ->notEmpty('email');
58
59
        $validator
60 2
            ->requirePresence('password', 'create')
61 2
            ->notEmpty('password');
62
63 2
        return $validator;
64
    }
65
66
    /**
67
     * Returns a rules checker object that will be used for validating
68
     * application integrity.
69
     *
70
     * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
71
     * @return \Cake\ORM\RulesChecker
72
     */
73 2
    public function buildRules(RulesChecker $rules)
74
    {
75 2
        $rules->add($rules->isUnique(['email']));
76
77 2
        return $rules;
78
    }
79
}
80