Passed
Push — dev5a ( a81ef3...276986 )
by Ron
07:39
created

CustomerContactPhones::getReadableAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class CustomerContactPhones extends Model
8
{
9
    protected $fillable = ['cont_id', 'phone_type_id', 'phone_number', 'extension'];
10
    protected $appends  = ['type_icon', 'type_name', 'readable'];
11
    protected $hidden   = ['created_at', 'updated_at'];
12
13 2
    public function getTypeIconAttribute()
14
    {
15 2
        return PhoneNumberTypes::find($this->phone_type_id)->icon_class;
16
    }
17
18 4
    public function getTypeNameAttribute()
19
    {
20 4
        return PhoneNumberTypes::find($this->phone_type_id)->description;
21
    }
22
23 4
    public function getReadableAttribute()
24
    {
25 4
        return preg_replace('~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '($1) $2-$3', $this->phone_number);
26
    }
27
28
    public function PhoneNumberTypes()
29
    {
30
        return $this->hasOne('App\PhoneNumberTypes', 'phone_type_id', 'phone_type_id');
31
    }
32
}
33