Passed
Push — develop ( d32912...6dcea6 )
by Septianata
05:48
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
 *
26
 * @see \App\Models\Customer
27
 */
28
trait Attribute
29
{
30
    /**
31
     * Return "identitycard_image" attribute value.
32
     *
33
     * @param  mixed  $value
34
     * @return string|null
35
     */
36 2
    public function getIdentitycardImageAttribute($value): ?string
37
    {
38 2
        if (is_null($value)) {
39 1
            return null;
40
        }
41
42 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...
43
    }
44
45
    /**
46
     * Return "google_map_url" attribute value.
47
     *
48
     * @return string|null
49
     */
50 1
    public function getGoogleMapUrlAttribute(): ?string
51
    {
52 1
        if (!is_null($this->location_latitude) && !is_null($this->location_longitude)) {
53 1
            return google_map_url($this->location_latitude, $this->location_longitude);
54
        }
55
56
        return null;
57
    }
58
59
    /**
60
     * Return "whatsapp_phone_url" attribute value.
61
     *
62
     * @return string
63
     */
64
    public function getWhatsappPhoneUrlAttribute(): string
65
    {
66
        return 'https://wa.me/' . Str::replaceFirst('+', '', $this->whatsapp_phone->formatE164());
67
    }
68
}
69