EloquentModel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 31.75 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttribute() 8 8 2
A setAttribute() 12 12 2

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 Arrilot\BitrixModels\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class EloquentModel extends Model
8
{
9
    /**
10
     * The primary key for the model.
11
     *
12
     * @var string
13
     */
14
    protected $primaryKey = 'ID';
15
16
    /**
17
     * The name of the "created at" column.
18
     *
19
     * @var string
20
     */
21
    const CREATED_AT = 'UF_CREATED_AT';
22
23
    /**
24
     * The name of the "updated at" column.
25
     *
26
     * @var string
27
     */
28
    const UPDATED_AT = 'UF_UPDATED_AT';
29
30
    /**
31
     * @var array
32
     */
33
    public $multipleHighloadBlockFields = [];
34
35
    /**
36
     * Get an attribute from the model.
37
     *
38
     * @param  string  $key
39
     * @return mixed
40
     */
41 View Code Duplication
    public function getAttribute($key)
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...
42
    {
43
        if (in_array($key, $this->multipleHighloadBlockFields)) {
44
            return unserialize($this->attributes[$key]);
45
        }
46
47
        return parent::getAttribute($key);
48
    }
49
50
    /**
51
     * Set a given attribute on the model.
52
     *
53
     * @param  string  $key
54
     * @param  mixed  $value
55
     * @return $this
56
     */
57 View Code Duplication
    public function setAttribute($key, $value)
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...
58
    {
59
        if (in_array($key, $this->multipleHighloadBlockFields)) {
60
            $this->attributes[$key] = serialize($value);
61
62
            return $this;
63
        }
64
65
        parent::setAttribute($key, $value);
66
67
        return $this;
68
    }
69
}
70