FieldValue   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 126
Duplicated Lines 32.54 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 41
loc 126
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerFieldForProject() 41 41 4
A references() 0 4 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 Fabrica\Models\Code;
4
5
use Finder\Models\Reference;
6
use Pedreiro\Models\Base;
7
8
class FieldValue extends Base
9
{
10
    protected $organizationPerspective = false;
11
12
    protected $table = 'code_issue_fields';
13
14
    /**
15
     * The attributes that are mass assignable.
16
     *
17
     * @var array
18
     */
19
    protected $fillable = [
20
        'value',
21
        'code_field_code',
22
        'code_issue_id'
23
    ];
24
    
25
    public $formFields = [
26
        [
27
            'name' => 'value',
28
            'label' => 'value',
29
            'type' => 'text'
30
        ],
31
        [
32
            'name' => 'code_field_code',
33
            'label' => 'Field',
34
            'type' => 'select',
35
            'relationship' => 'field'
36
        ],
37
        [
38
            'name' => 'code_issue_id',
39
            'label' => 'Issue',
40
            'type' => 'select',
41
            'relationship' => 'issue'
42
        ],
43
    ];
44
45
    public $indexFields = [
46
        'value',
47
        'code_field_code',
48
        'code_issue_id'
49
    ];
50
51
    public $validationRules = [
52
        'value'       => 'required',
53
        'code_field_code'   => 'required',
54
        'code_issue_id' => 'required|int',
55
    ];
56
57
    public $validationMessages = [
58
        'value.required' => "Valor é obrigatório."
59
    ];
60
61
    public $validationAttributes = [
62
        'value' => 'Value'
63
    ];
64
    /**
65
     * 63 => JiraRestApi\Field\Field^ {#472
66
     * +id: "customfield_10033"
67
     * +name: "Porque essa funcionalidade deve ser desenvolvida ?"
68
     * +description: null
69
     * +type: null
70
     * +custom: true
71
     * +orderable: true
72
     * +navigable: true
73
     * +searchable: true
74
     * +searcherKey: null
75
     * +clauseNames: array:2 [
76
     *   0 => "cf[10033]"
77
     *   1 => "Porque essa funcionalidade deve ser desenvolvida ?"
78
     * ]
79
     * +schema: {#792
80
     *   +"type": "string"
81
     *   +"custom": "com.atlassian.jira.plugin.system.customfieldtypes:textarea"
82
     *   +"customId": 10033
83
     * }
84
     * +"key": "customfield_10033"
85
     * }
86
     */
87 View Code Duplication
    public static function registerFieldForProject($field, $projectUrl = false)
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...
88
    {
89
        // dd($field);
90
        $field =  self::firstOrCreate(
91
            [
92
            'name' => $field->name
93
            ]
94
        );
95
96
        if ($projectUrl) {
97
            if (!$reference = Reference::where(
98
                [
99
                'code' => $projectUrl
100
                ]
101
            )->first()
102
            ) {
103
                $reference = Reference::create(
104
                    [
105
                    'code' => $projectUrl,
106
                    'name' => $projectUrl,
107
                    ]
108
                );
109
            }
110
            if (!$field->references()->where('reference_id', $reference->id)->first()) {
111
                $field->references()->save(
112
                    $reference,
113
                    [
114
                        'identify' => $field->id,
115
                    ]
116
                );
117
            }
118
        }
119
        return $field;
120
121
        // foreach($comments as $comment) {
122
        //     var_dump($comment);
123
        //     Coment::firstOrCreate([
124
        //         'name' => $comment->name
125
        //     ]);
126
        // }
127
    }
128
    
129
    public function references()
130
    {
131
        return $this->morphToMany(Reference::class, 'referenceable');
132
    }
133
}
134