Field::references()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Fabrica\Models\Code;
4
5
use Finder\Models\Reference;
6
use Pedreiro\Models\Base;
7
8
class Field extends Base
9
{
10
    protected $organizationPerspective = false;
11
12
    protected $table = 'code_fields';
13
    
14
    public $incrementing = false;
15
    protected $casts = [
16
        'code' => 'string',
17
    ];
18
    protected $primaryKey = 'code';
19
    protected $keyType = 'string';
20
21
    /**
22
     * The attributes that are mass assignable.
23
     *
24
     * @var array
25
     */
26
    protected $fillable = [
27
        'name',
28
        'code',
29
    ];
30
    
31
    public $formFields = [
32
        ['name' => 'name', 'label' => 'Nome', 'type' => 'text'],
33
        ['name' => 'code', 'label' => 'Código', 'type' => 'text'],
34
        // ['name' => 'body', 'label' => 'Enter your content here', 'type' => 'textarea'],
35
        // ['name' => 'publish_on', 'label' => 'Publish Date', 'type' => 'date'],
36
        // ['name' => 'published', 'label' => 'Published', 'type' => 'checkbox'],
37
        // ['name' => 'category_id', 'label' => 'Category', 'type' => 'select', 'relationship' => 'category'],
38
        // ['name' => 'tags', 'label' => 'Tags', 'type' => 'select_multiple', 'relationship' => 'tags'],
39
    ];
40
41
    public $indexFields = [
42
        'code',
43
        'name',
44
        // 'category_id',
45
        // 'published'
46
    ];
47
48
    public $validationRules = [
49
        'name'       => 'required|max:255',
50
        'code'        => 'required|max:100',
51
        // 'body'        => 'required',
52
        // 'publish_on'  => 'date',
53
        // 'published'   => 'boolean',
54
        // 'category_id' => 'required|int',
55
    ];
56
57
    public $validationMessages = [
58
        'name.required' => "O nome é obrigatório"
59
    ];
60
61
    public $validationAttributes = [
62
        'name' => 'Nome do Campo'
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
        $field =  self::firstOrCreate(
90
            [
91
                'name' => $field->name,
92
                'code' => $field->key
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