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

FormUpdate::labels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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
}