ConversationsTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 95
Duplicated Lines 44.21 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 42
loc 95
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B initialize() 0 29 1
A validationCreate() 21 21 1
A validationEdit() 21 21 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\Table;
5
use Cake\Validation\Validator;
6
7
class ConversationsTable extends Table
8
{
9
10
    /**
11
     * Initialize method
12
     *
13
     * @param array $config The configuration for the Table.
14
     * @return void
15
     */
16
    public function initialize(array $config)
17
    {
18
        $this->table('conversations');
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...
19
        $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...
20
        $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...
21
22
        $this->addBehavior('Timestamp');
23
24
        $this->belongsTo('Users', [
25
            'foreignKey' => 'user_id'
26
        ]);
27
        $this->belongsTo('LastMessage', [
28
            'className' => 'ConversationsMessages',
29
            'foreignKey' => 'last_message_id'
30
        ]);
31
        $this->belongsTo('LastMessageUser', [
32
            'className' => 'Users',
33
            'foreignKey' => 'last_message_user_id'
34
        ]);
35
        $this->hasMany('ConversationsMessages', [
36
            'foreignKey' => 'conversation_id',
37
            'dependent' => true
38
        ]);
39
        $this->hasMany('ConversationsUsers', [
40
            'className' => 'ConversationsUsers',
41
            'foreignKey' => 'conversation_id',
42
            'dependent' => true
43
        ]);
44
    }
45
46
    /**
47
     * Create validation rules.
48
     *
49
     * @param \Cake\Validation\Validator $validator Validator instance.
50
     * @return \Cake\Validation\Validator
51
     */
52 View Code Duplication
    public function validationCreate(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...
53
    {
54
        $validator
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Validation\Validator::provider() has been deprecated with message: 3.4.0 Use setProvider()/getProvider() 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...
55
            ->provider('purifier', 'App\Model\Validation\PurifierValidator')
56
            ->notEmpty('title', __d('conversations', 'You must specify a title for your conversation.'))
57
            ->add('title', 'minLength', [
58
                'rule' => ['minLength', 5],
59
                'message' => __d('conversations', 'Your title must contain at least {0} characters.', 5)
60
            ])
61
62
            ->notEmpty('message', __d('conversations', 'You must specify a message for your conversation.'))
63
            ->add('message', [
64
                'purifierMinLength' => [
65
                    'rule' => ['purifierMinLength', 5],
66
                    'provider' => 'purifier',
67
                    'message' => __d('conversations', 'Your message must contain at least {0} characters.', 5)
68
                ]
69
            ]);
70
71
        return $validator;
72
    }
73
74
    /**
75
     * Edit validation rules.
76
     *
77
     * @param \Cake\Validation\Validator $validator Validator instance.
78
     * @return \Cake\Validation\Validator
79
     */
80 View Code Duplication
    public function validationEdit(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...
81
    {
82
        $validator
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Validation\Validator::provider() has been deprecated with message: 3.4.0 Use setProvider()/getProvider() 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...
83
            ->provider('purifier', 'App\Model\Validation\PurifierValidator')
84
            ->notEmpty('title', __d('conversations', 'You must specify a title for your conversation.'))
85
            ->add('title', 'minLength', [
86
                'rule' => ['minLength', 5],
87
                'message' => __d('conversations', 'Your title must contain at least {0} characters.', 5)
88
            ])
89
90
            ->notEmpty('message', __d('conversations', 'You must specify a message for your conversation.'))
91
            ->add('message', [
92
                'purifierMinLength' => [
93
                    'rule' => ['purifierMinLength', 5],
94
                    'provider' => 'purifier',
95
                    'message' => __d('conversations', 'Your message must contain at least {0} characters.', 5)
96
                ]
97
            ]);
98
99
        return $validator;
100
    }
101
}
102