Text   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 26.42 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 14
loc 53
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setKeysForSaveQuery() 14 14 3
A getKeyValueForSaveQuery() 0 8 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
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Text\Models\Eloquent;
12
13
use Illuminate\Database\Eloquent\Builder;
14
use Longman\Platfourm\Database\Eloquent\ActionLog\ActionLogTrait;
15
use Longman\Platfourm\Database\Eloquent\Model;
16
17
class Text extends Model
18
{
19
    use ActionLogTrait;
20
    /**
21
     * The attributes that are mass assignable.
22
     *
23
     * @var array
24
     */
25
    protected $fillable = ['key', 'lang', 'value', 'scope'];
26
27
    public $incrementing = false;
28
29
    protected $primaryKey = ['key', 'lang', 'scope'];
30
31
    protected $searchableFields = ['key', 'value'];
32
33
    protected $sortableFields = ['key', 'value'];
34
35
    /**
36
     * Set the keys for a save update query.
37
     *
38
     * @param  \Illuminate\Database\Eloquent\Builder $query
39
     * @return \Illuminate\Database\Eloquent\Builder
40
     */
41 View Code Duplication
    protected function setKeysForSaveQuery(Builder $query)
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
        $key = $this->getKeyName();
44
45
        if (is_array($key)) {
46
            foreach ($key as $k) {
47
                $query->where($k, '=', $this->getKeyValueForSaveQuery($k));
48
            }
49
        } else {
50
            $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery());
51
        }
52
53
        return $query;
54
    }
55
56
    /**
57
     * Get the primary key value for a save query.
58
     *
59
     * @return mixed
60
     */
61
    protected function getKeyValueForSaveQuery($key)
62
    {
63
        if (isset($this->original[$key])) {
64
            return $this->original[$key];
65
        }
66
67
        return $this->getAttribute($key);
68
    }
69
}
70