Completed
Push — master ( 6f92e6...cbba0d )
by Fèvre
9s
created

PollsAnswersTable::buildRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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
 * PollsAnswers Model
11
 *
12
 * @property \Cake\ORM\Association\BelongsTo $Polls
13
 */
14
class PollsAnswersTable extends Table
15
{
16
17
    /**
18
     * Initialize method
19
     *
20
     * @param array $config The configuration for the Table.
21
     *
22
     * @return void
23
     */
24 View Code Duplication
    public function initialize(array $config)
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...
25
    {
26
        parent::initialize($config);
27
28
        $this->table('polls_answers');
29
        $this->displayField('id');
30
        $this->primaryKey('id');
31
32
        $this->addBehavior('Timestamp');
33
34
        $this->belongsTo('Polls', [
35
            'foreignKey' => 'poll_id'
36
        ]);
37
    }
38
39
    /**
40
     * Default validation rules.
41
     *
42
     * @param \Cake\Validation\Validator $validator Validator instance.
43
     *
44
     * @return \Cake\Validation\Validator
45
     */
46
    public function validationDefault(Validator $validator)
47
    {
48
        $validator
49
            ->integer('id')
50
            ->allowEmpty('id', 'create');
51
52
        $validator
53
            ->requirePresence('response', 'create')
54
            ->notEmpty('response');
55
56
        $validator
57
            ->integer('user_count')
58
            ->requirePresence('user_count', 'create')
59
            ->notEmpty('user_count');
60
61
        return $validator;
62
    }
63
64
    /**
65
     * Returns a rules checker object that will be used for validating
66
     * application integrity.
67
     *
68
     * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
69
     *
70
     * @return \Cake\ORM\RulesChecker
71
     */
72
    public function buildRules(RulesChecker $rules)
73
    {
74
        $rules->add($rules->existsIn(['poll_id'], 'Polls'));
75
76
        return $rules;
77
    }
78
}
79