Passed
Push — develop ( 6dcea6...5ae9a6 )
by Septianata
16:24
created

Attribute::getWhatsappPhoneUrlAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Models\Concerns\Customer;
4
5
use Illuminate\Support\Facades\Storage;
6
use Illuminate\Support\Str;
7
8
/**
9
 * @property string $telegram_chat_id
10
 * @property string $username
11
 * @property string $fullname
12
 * @property \App\Enum\Gender $gender
13
 * @property string $email
14
 * @property string $phone_country
15
 * @property \Propaganistas\LaravelPhone\PhoneNumber $phone
16
 * @property string $whatsapp_phone_country
17
 * @property \Propaganistas\LaravelPhone\PhoneNumber $whatsapp_phone
18
 * @property string|null $account_number
19
 * @property string|null $identitycard_number
20
 * @property string|null $identitycard_image
21
 * @property float|null $location_latitude
22
 * @property float|null $location_longitude
23
 * @property-read string|null $google_map_url
24
 * @property-read string $whatsapp_phone_url
25
 * @property-read string $gravatar_image
26
 * @property-read string $telegram_chat_id_censored
27
 *
28
 * @see \App\Models\Customer
29
 */
30
trait Attribute
31
{
32
    /**
33
     * Return "identitycard_image" attribute value.
34
     *
35
     * @param  mixed  $value
36
     * @return string|null
37
     */
38 2
    public function getIdentitycardImageAttribute($value): ?string
39
    {
40 2
        if (is_null($value)) {
41 1
            return null;
42
        }
43
44 1
        return Storage::url(static::IDENTITYCARD_IMAGE_PATH . '/' . $value);
0 ignored issues
show
Bug introduced by
The constant App\Models\Concerns\Cust...IDENTITYCARD_IMAGE_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45
    }
46
47
    /**
48
     * Return "google_map_url" attribute value.
49
     *
50
     * @return string|null
51
     */
52 1
    public function getGoogleMapUrlAttribute(): ?string
53
    {
54 1
        if (!is_null($this->location_latitude) && !is_null($this->location_longitude)) {
55 1
            return google_map_url($this->location_latitude, $this->location_longitude);
56
        }
57
58
        return null;
59
    }
60
61
    /**
62
     * Return "whatsapp_phone_url" attribute value.
63
     *
64
     * @return string
65
     */
66
    public function getWhatsappPhoneUrlAttribute(): string
67
    {
68
        return 'https://wa.me/' . Str::replaceFirst('+', '', $this->whatsapp_phone->formatE164());
69
    }
70
71
    /**
72
     * Return "gravatar_image" attribute value.
73
     *
74
     * @return string
75
     */
76
    public function getGravatarImageAttribute(): string
77
    {
78
        return gravatar_image($this->email);
79
    }
80
81
    /**
82
     * Return "telegram_chat_id_censored" attribute value.
83
     *
84
     * @return string
85
     */
86
    public function getTelegramChatIdCensoredAttribute(): string
87
    {
88
        return substr_replace($this->telegram_chat_id, '****', -4);
0 ignored issues
show
Bug Best Practice introduced by
The expression return substr_replace($t...am_chat_id, '****', -4) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
89
    }
90
}
91