Completed
Push — master ( 9f3e69...d66716 )
by Nekrasov
01:38
created

EloquentModel::setAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
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