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

UsersTable::validationDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 1
crap 1
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