Completed
Push — master ( 068be6...30e4bf )
by Ricardo
01:13
created

Account::passwords()   A

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 Telefonica\Models\Digital;
4
5
use Pedreiro\Models\Base;
6
use Muleta\Traits\Models\ComplexRelationamentTrait;
7
use Integrations\Models\Integration;
8
use Telefonica\Models\Actors\Business;
9
10
class Account extends Base
11
{
12
    // use ComplexRelationamentTrait;
13
    
14
    // protected static $COMPLEX_RELATIONAMENT_MODELS = [
15
    //     \App\Models\Photo::class,
16
    //     \App\Models\Video::class
17
    // ];
18
19
    /**
20
     * The attributes that are mass assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = [
25
        'username',
26
        'password',
27
        'email',
28
        'customize_url',
29
        'status',
30
        'integration_id',
31
        'obs',
32
    ];
33
34
    protected $mappingProperties = array(
35
        'username' => [
36
            'type' => 'string',
37
            "analyzer" => "standard",
38
        ],
39
        'password' => [
40
            'type' => 'string',
41
            "analyzer" => "standard",
42
        ],
43
        'email' => [
44
            'type' => 'string',
45
            "analyzer" => "standard",
46
        ],
47
        'customize_url' => [
48
            'type' => 'string',
49
            "analyzer" => "standard",
50
        ],
51
        'integration_id' => [
52
            'type' => 'string',
53
            "analyzer" => "standard",
54
        ],
55
    );
56
    public $formFields = [
57
        [
58
            'name' => 'username',
59
            'label' => 'username',
60
            'type' => 'text'
61
        ],
62
        [
63
            'name' => 'password',
64
            'label' => 'password',
65
            'type' => 'text'
66
        ],
67
        [
68
            'name' => 'email',
69
            'label' => 'email',
70
            'type' => 'text'
71
        ],
72
        [
73
            'name' => 'customize_url',
74
            'label' => 'customize_url',
75
            'type' => 'text'
76
        ],
77
        // ['name' => 'init', 'label' => 'Inicio', 'type' => 'date'],
78
        // ['name' => 'end', 'label' => 'End', 'type' => 'date'],
79
        // [
80
        //     'name' => 'status',
81
        //     'label' => 'Status',
82
        //     'type' => 'checkbox'
83
        // ],
84
        [
85
            'name' => 'obs',
86
            'label' => 'Observations',
87
            'type' => 'textarea'
88
        ],
89
        ['name' => 'integration_id', 'label' => 'Integração', 'type' => 'select', 'relationship' => 'integration'],
90
        // ['name' => 'tags', 'label' => 'Tags', 'type' => 'select_multiple', 'relationship' => 'tags'],
91
    ];
92
93
    public $indexFields = [
94
        'username',
95
        'description',
96
        'password',
97
        'email',
98
        'customize_url',
99
        'integration_id',
100
        'obs'
101
    ];
102
    
103
    public function getUser()
104
    {
105
        return $this->username;
106
        return $this->email; // @todo
0 ignored issues
show
Unused Code introduced by
return $this->email; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
107
    }
108
109
    public function getPassword()
110
    {
111
        return $this->password;
112
    }
113
114
115
    /**
116
     * Get all of the business that are assigned this tag.
117
     */
118
    public function business()
119
    {
120
        return $this->businesses();
121
    }
122
123
    /**
124
     * Get all of the businesses that are assigned this item.
125
     */
126
    public function businesses()
127
    {
128
        return $this->morphedByMany(\Illuminate\Support\Facades\Config::get('sitec-tools.models.business', \Telefonica\Models\Actors\Business::class), 'accountable');
129
    }
130
131
    /**
132
     * Get all of the users that are assigned this tag.
133
     */
134
    public function users()
135
    {
136
        return $this->morphedByMany(\Illuminate\Support\Facades\Config::get('sitec.core.models.user', \App\Models\User::class), 'accountable');
137
    }
138
139
    /**
140
     * Get all of the persons that are assigned this tag.
141
     */
142
    public function persons()
143
    {
144
        return $this->morphedByMany(\Illuminate\Support\Facades\Config::get('sitec.core.models.person', \Telefonica\Models\Actors\Person::class), 'accountable');
145
    }
146
147
    /**
148
     * Relation for the user that created this entity.
149
     *
150
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
151
     */
152
    public function integration()
153
    {
154
        return $this->belongsTo(Integration::class);
155
    }
156
157
158
    public function save(array $options = [])
159
    {
160
        // If no author has been assigned, assign the current user's id as the author of the post
161
        if (!$this->username || empty($this->username)) {
162
            $this->username = $this->email;
163
        }
164
165
        parent::save();
166
    }
167
168
    /**
169
     * Get all of the passwords that are assigned this tag.
170
     */
171
    public function passwords()
172
    {
173
        return $this->morphToMany(Password::class, 'passwordable');
174
    }
175
176
    public static function boot()
177
    {
178
        parent::boot();
179
180
        self::created(
181
            function ($model) {
182
                $pass = Password::firstOrCreate([
183
                    'value' => $model->password,
184
                ]);
185
                $model->passwords()->attach($pass);
186
            }
187
        );
188
189
    }
190
}
191