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

FormSettings   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 53
loc 53
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() 11 11 4
A labels() 7 7 1
A rules() 7 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 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 $itemPerApp;
14
    public $minLength;
15
16
    private $_configs;
17
18
    /**
19
     * ForumSettings constructor. Construct model with default values
20
     * @param array|null $configs
21
     */
22
    public function __construct(array $configs = null)
23
    {
24
        $this->_configs = $configs;
25
        parent::__construct();
26
    }
27
28
    public function before()
29
    {
30
        if ($this->_configs === null) {
31
            return;
32
        }
33
        foreach ($this->_configs as $property => $value) {
34
            if (property_exists($this, $property)) {
35
                $this->$property = $value;
36
            }
37
        }
38
    }
39
40
    /**
41
     * Labels for admin settings form
42
     * @return array
43
     */
44
    public function labels()
45
    {
46
        return [
47
            'itemPerApp' => __('Search count'),
48
            'minLength' => __('Min length')
49
        ];
50
    }
51
52
    /**
53
     * Validation rules
54
     * @return @array
0 ignored issues
show
Documentation introduced by
The doc-type @array could not be parsed: Unknown type name "@array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
55
     */
56
    public function rules()
57
    {
58
        return [
59
            [['itemPerApp', 'minLength'], 'required'],
60
            [['itemPerApp', 'minLength'], 'int']
61
        ];
62
    }
63
}