Passed
Push — develop ( d32912...6dcea6 )
by Septianata
05:48
created

Attribute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 8
c 1
b 0
f 0
dl 0
loc 39
ccs 7
cts 10
cp 0.7
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentitycardImageAttribute() 0 7 2
A getWhatsappPhoneUrlAttribute() 0 3 1
A getGoogleMapUrlAttribute() 0 7 3
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