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

PollsAnswersTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 21.54 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 14
loc 65
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 14 14 1
A validationDefault() 0 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
 * 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