GroupsTable::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 19
loc 19
rs 9.4285
cc 1
eloc 12
nc 1
nop 1
1
<?php
2
namespace App\Model\Table;
3
4
use Cake\ORM\Table;
5
use Cake\Validation\Validator;
6
7
class GroupsTable extends Table
8
{
9
10
    /**
11
     * Initialize method.
12
     *
13
     * @param array $config The configuration for the Table.
14
     *
15
     * @return void
16
     */
17 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...
18
    {
19
        $this->table('groups');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::table() has been deprecated with message: 3.4.0 Use setTable()/getTable() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
20
        $this->displayField('name');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::displayField() has been deprecated with message: 3.4.0 Use setDisplayField()/getDisplayField() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
21
        $this->primaryKey('id');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::primaryKey() has been deprecated with message: 3.4.0 Use setPrimaryKey()/getPrimaryKey() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
22
23
        $this->addBehavior('Timestamp');
24
        $this->addBehavior('Acl.Acl', [
25
            'type' => 'requester'
26
        ]);
27
        $this->addBehavior('Translate', [
28
            'fields' => ['name'],
29
            'translationTable' => 'GroupsI18n'
30
        ]);
31
32
        $this->hasMany('Users', [
33
            'foreignKey' => 'group_id'
34
        ]);
35
    }
36
37
    /**
38
     * Default validation rules.
39
     *
40
     * @param \Cake\Validation\Validator $validator The Validator instance.
41
     *
42
     * @return \Cake\Validation\Validator
43
     */
44
    public function validationDefault(Validator $validator)
45
    {
46
        $validator
47
            ->notEmpty('name', __("You must set a name."))
48
            ->add('name', 'minLength', [
49
                'rule' => ['minLength', 3],
50
                'message' => __("The name can not be less than {0} characters.", 3)
51
            ]);
52
53
        return $validator;
54
    }
55
}
56