Passed
Push — master ( cc7747...d2190f )
by Mihail
10:36
created

FormSettings   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 63
loc 63
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A before() 12 12 4
A labels() 11 11 1
A rules() 8 8 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\Profile;
4
5
use Ffcms\Core\Arch\Model;
6
7
/**
8
 * Class FormSettings. Admin profile settings business logic
9
 * @package Apps\Model\Admin\Profile
10
 */
11 View Code Duplication
class FormSettings extends Model
0 ignored issues
show
Duplication introduced by
This class 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...
12
{
13
    public $guestView;
14
    public $wallPostOnPage;
15
    public $delayBetweenPost;
16
    public $rating;
17
    public $usersOnPage;
18
    public $ratingDelay;
19
20
    private $_configs;
21
22
    /**
23
     * Construct model with default values
24
     * @param array|null $configs
25
     */
26
    public function __construct(array $configs = null)
27
    {
28
        $this->_configs = $configs;
29
        parent::__construct();
30
    }
31
32
    public function before()
33
    {
34
        if ($this->_configs === null) {
35
            return;
36
        }
37
38
        foreach ($this->_configs as $property => $value) {
39
            if (property_exists($this, $property)) {
40
                $this->{$property} = $value;
41
            }
42
        }
43
    }
44
45
    /**
46
     * Form display labels
47
     * @return array
48
     */
49
    public function labels()
50
    {
51
        return [
52
            'guestView' => __('Guest view'),
53
            'wallPostOnPage' => __('Post on page'),
54
            'delayBetweenPost' => __('Post delay'),
55
            'rating' => __('Rating'),
56
            'usersOnPage' => __('User per page'),
57
            'ratingDelay' => __('Rating delay')
58
        ];
59
    }
60
61
    /**
62
     * Validation rules
63
     * @return array
64
     */
65
    public function rules()
66
    {
67
        return [
68
            [['guestView', 'wallPostOnPage', 'delayBetweenPost', 'rating', 'usersOnPage', 'ratingDelay'], 'required'],
69
            [['guestView', 'wallPostOnPage', 'delayBetweenPost', 'rating', 'usersOnPage', 'ratingDelay'], 'int'],
70
            [['guestView', 'rating'], 'in', ['0', '1']]
71
        ];
72
    }
73
}