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

conedevelopment / bazar / 20213722262

14 Dec 2025 08:30PM UTC coverage: 63.031% (-0.4%) from 63.48%
20213722262

Pull #235

github

web-flow
Merge 03c6b2b10 into 090ff8496
Pull Request #235: Coupons & Discounts

0 of 3 new or added lines in 2 files covered. (0.0%)

53 existing lines in 11 files now uncovered.

965 of 1531 relevant lines covered (63.03%)

15.16 hits per line

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

61.9
/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\Attribute;
12
use Illuminate\Database\Eloquent\Factories\HasFactory;
13
use Illuminate\Database\Eloquent\Model;
14
use Illuminate\Database\Eloquent\Relations\MorphTo;
15

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

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

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

53
    /**
54
     * The attributes that should be cast to native types.
55
     *
56
     * @var array<string, string>
57
     */
58
    protected $casts = [
59
        'custom' => 'json',
60
        'default' => 'bool',
61
    ];
62

63
    /**
64
     * The attributes that are mass assignable.
65
     *
66
     * @var list<string>
67
     */
68
    protected $fillable = [
69
        'address_secondary',
70
        'address',
71
        'alias',
72
        'city',
73
        'company',
74
        'country',
75
        'custom',
76
        'default',
77
        'email',
78
        'first_name',
79
        'last_name',
80
        'phone',
81
        'postcode',
82
        'state',
83
        'tax_id',
84
    ];
85

86
    /**
87
     * The table associated with the model.
88
     *
89
     * @var string
90
     */
91
    protected $table = 'bazar_addresses';
92

93
    /**
94
     * The address validator callback.
95
     */
96
    protected static ?Closure $validator = null;
97

98
    /**
99
     * Get the proxied interface.
100
     */
101
    public static function getProxiedInterface(): string
102
    {
103
        return Contract::class;
1✔
104
    }
105

106
    /**
107
     * Create a new factory instance for the model.
108
     */
109
    protected static function newFactory(): AddressFactory
110
    {
111
        return AddressFactory::new();
15✔
112
    }
113

114
    /**
115
     * Set the address validator callback.
116
     */
117
    public static function validateUsing(Closure $callback): void
118
    {
UNCOV
119
        static::$validator = $callback;
×
120
    }
121

122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function getMorphClass(): string
126
    {
127
        return static::getProxiedClass();
×
128
    }
129

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

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

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

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

174
            return (isset($data['company'], $data['tax_id']) || isset($data['first_name'], $data['last_name']))
×
UNCOV
175
                && isset($data['address'], $data['city'], $data['country'], $data['postcode'], $data['email']);
×
176
        };
×
177

178
        return call_user_func_array($callback, [$this]);
×
179
    }
180
}
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