BlogCategoriesTable::validationDefault()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 16
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 BlogCategoriesTable 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('blog_categories');
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('title');
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('Translate', [
25
            'fields' => ['title', 'description'],
26
            'translationTable' => 'BlogCategoriesI18n'
27
        ]);
28
29
        $this->hasMany('BlogArticles', [
30
            'foreignKey' => 'category_id',
31
            'dependent' => true
32
        ]);
33
    }
34
35
    /**
36
     * Default validation rules.
37
     *
38
     * @param \Cake\Validation\Validator $validator Instance of the validator.
39
     *
40
     * @return \Cake\Validation\Validator
41
     */
42
    public function validationDefault(Validator $validator)
43
    {
44
        $validator
45
            ->notEmpty('title', __("The title is required."))
46
            ->add('title', [
47
                'unique' => [
48
                    'rule' => 'validateUnique',
49
                    'provider' => 'table',
50
                    'message' => __("This title is already used.")
51
                ],
52
                'minLength' => [
53
                    'rule' => ['minLength', 3],
54
                    'message' => __("Please, {0} characters minimum for the title.", 3)
55
                ]
56
            ])
57
            ->add('description', [
58
                'maxLength' => [
59
                    'rule' => ['maxLength', 255],
60
                    'message' => __("Please, {0} characters maximum for the description.", 255)
61
                ]
62
            ]);
63
64
        return $validator;
65
    }
66
}
67