Passed
Push — master ( 68443e...939347 )
by Mihail
04:31
created

FormUpdate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 26.56 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 17
loc 64
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A before() 0 6 1
A labels() 8 8 1
A rules() 9 9 1
A make() 0 7 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
3
namespace Apps\Model\Admin\Feedback;
4
5
use Ffcms\Core\App;
6
use Ffcms\Core\Arch\Model;
7
8
class FormUpdate extends Model
9
{
10
    public $name;
11
    public $email;
12
    public $message;
13
14
    private $_record;
15
16
    /**
17
     * FormUpdate constructor. Pass active record inside the model.
18
     * @param $record
19
     */
20
    public function __construct($record)
21
    {
22
        $this->_record = $record;
23
        parent::__construct();
24
    }
25
26
    /**
27
     * Set model properties from active record data
28
     */
29
    public function before()
30
    {
31
        $this->name = $this->_record->name;
32
        $this->email = $this->_record->email;
33
        $this->message = $this->_record->message;
34
    }
35
36
    /**
37
    * Labels to display edit form
38
    */
39 View Code Duplication
    public function labels()
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...
40
    {
41
        return [
42
            'name' => __('Name'),
43
            'email' => __('Email'),
44
            'message' => __('Message'),
45
        ];
46
    }
47
48
    /**
49
    * Rules to validate changes
50
    */
51 View Code Duplication
    public function rules()
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...
52
    {
53
        return [
54
            [['name', 'email', 'message'], 'required'],
55
            ['name', 'length_min', '2'],
56
            ['message', 'length_min', 10],
57
            ['email', 'email']
58
        ];
59
    }
60
61
    /**
62
     * Save data to database
63
     */
64
    public function make()
65
    {
66
        $this->_record->name = App::$Security->strip_tags($this->name);
67
        $this->_record->email = App::$Security->strip_tags($this->email);
68
        $this->_record->message = App::$Security->strip_tags($this->message);
69
        $this->_record->save();
70
    }
71
}