Passed
Push — master ( 6221c1...b56763 )
by Mihail
05:30
created

FormSettings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 3
A labels() 0 7 1
A rules() 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\Search;
4
5
use Ffcms\Core\Arch\Model;
6
7
/**
8
 * Class FormSettings. Model to transfer and validate input data & attributes for search admin configs.
9
 * @package Apps\Model\Admin\Search
10
 */
11
class FormSettings extends Model
12
{
13
    public $itemPerApp;
14
    public $minLength;
15
16
    /**
17
     * Construct model with default values
18
     * @param array $configs
19
     */
20 View Code Duplication
    public function __construct(array $configs)
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...
21
    {
22
        foreach ($configs as $property => $value) {
23
            if (property_exists($this, $property)) {
24
                $this->$property = $value;
25
            }
26
        }
27
28
        parent::__construct();
29
    }
30
31
    /**
32
    * Labels for admin settings form
33
    */
34
    public function labels()
35
    {
36
        return [
37
            'itemPerApp' => __('Search count'),
38
            'minLength' => __('Min length')
39
        ];
40
    }
41
42
    /**
43
    * Validation rules
44
    */
45
    public function rules()
46
    {
47
        return [
48
            [['itemPerApp', 'minLength'], 'required'],
49
            [['itemPerApp', 'minLength'], 'int']
50
        ];
51
    }
52
}