• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

conedevelopment / bazar / 20694116184

04 Jan 2026 02:08PM UTC coverage: 68.615% (+4.5%) from 64.117%
20694116184

push

github

iamgergo
version

1679 of 2447 relevant lines covered (68.61%)

25.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/src/Models/Address.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Models;
6

7
use Closure;
8
use Cone\Bazar\Database\Factories\AddressFactory;
9
use Cone\Bazar\Interfaces\Models\Address as Contract;
10
use Cone\Root\Traits\InteractsWithProxy;
11
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
12
use Illuminate\Database\Eloquent\Casts\Attribute;
13
use Illuminate\Database\Eloquent\Factories\HasFactory;
14
use Illuminate\Database\Eloquent\Model;
15
use Illuminate\Database\Eloquent\Relations\MorphTo;
16

17
class Address extends Model implements Contract
18
{
19
    use HasFactory;
20
    use InteractsWithProxy;
21

22
    /**
23
     * The accessors to append to the model's array form.
24
     *
25
     * @var list<string>
26
     */
27
    protected $appends = [
28
        'name',
29
    ];
30

31
    /**
32
     * The attributes that should have default values.
33
     *
34
     * @var array<string, mixed>
35
     */
36
    protected $attributes = [
37
        'address_secondary' => null,
38
        'address' => null,
39
        'alias' => null,
40
        'city' => null,
41
        'company' => null,
42
        'country' => null,
43
        'custom' => '[]',
44
        'default' => false,
45
        'email' => null,
46
        'first_name' => null,
47
        'last_name' => null,
48
        'phone' => null,
49
        'postcode' => null,
50
        'state' => null,
51
        'tax_id' => null,
52
    ];
53

54
    /**
55
     * The attributes that are mass assignable.
56
     *
57
     * @var list<string>
58
     */
59
    protected $fillable = [
60
        'address_secondary',
61
        'address',
62
        'alias',
63
        'city',
64
        'company',
65
        'country',
66
        'custom',
67
        'default',
68
        'email',
69
        'first_name',
70
        'last_name',
71
        'phone',
72
        'postcode',
73
        'state',
74
        'tax_id',
75
    ];
76

77
    /**
78
     * The table associated with the model.
79
     *
80
     * @var string
81
     */
82
    protected $table = 'bazar_addresses';
83

84
    /**
85
     * The address validator callback.
86
     */
87
    protected static ?Closure $validator = null;
88

89
    /**
90
     * Get the proxied interface.
91
     */
92
    public static function getProxiedInterface(): string
1✔
93
    {
94
        return Contract::class;
1✔
95
    }
96

97
    /**
98
     * Create a new factory instance for the model.
99
     */
100
    protected static function newFactory(): AddressFactory
29✔
101
    {
102
        return AddressFactory::new();
29✔
103
    }
104

105
    /**
106
     * Set the address validator callback.
107
     */
108
    public static function validateUsing(Closure $callback): void
×
109
    {
110
        static::$validator = $callback;
×
111
    }
112

113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function getMorphClass(): string
×
117
    {
118
        return static::getProxiedClass();
×
119
    }
120

121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function casts(): array
30✔
125
    {
126
        return [
30✔
127
            'custom' => AsArrayObject::class,
30✔
128
            'default' => 'bool',
30✔
129
        ];
30✔
130
    }
131

132
    /**
133
     * Get the addressable model for the address.
134
     */
135
    public function addressable(): MorphTo
5✔
136
    {
137
        return $this->morphTo();
5✔
138
    }
139

140
    /**
141
     * Get the alias attribute.
142
     *
143
     * @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
144
     */
145
    protected function alias(): Attribute
15✔
146
    {
147
        return new Attribute(
15✔
148
            get: function (?string $value): ?string {
15✔
149
                return $this->exists ? ($value ?: $this->name) : $value;
15✔
150
            }
15✔
151
        );
15✔
152
    }
153

154
    /**
155
     * Get the name attribute.
156
     *
157
     * @return \Illuminate\Database\Eloquent\Casts\Attribute<string, never>
158
     */
159
    protected function name(): Attribute
16✔
160
    {
161
        return new Attribute(
16✔
162
            get: function (mixed $value, array $attributes): string {
16✔
163
                return trim(sprintf('%s %s', $attributes['first_name'], $attributes['last_name']));
16✔
164
            }
16✔
165
        );
16✔
166
    }
167

168
    /**
169
     * Validate the address.
170
     */
171
    public function validate(): bool
1✔
172
    {
173
        $callback = static::$validator ?: static function (Address $address): bool {
1✔
174
            $data = $address->toArray();
1✔
175

176
            return (isset($data['company'], $data['tax_id']) || isset($data['first_name'], $data['last_name']))
1✔
177
                && isset($data['address'], $data['city'], $data['country'], $data['postcode'], $data['email']);
1✔
178
        };
1✔
179

180
        return call_user_func_array($callback, [$this]);
1✔
181
    }
182
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc