• 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

62.5
/src/Fields/Price.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Fields;
6

7
use Cone\Bazar\Bazar;
8
use Cone\Bazar\Enums\Currency;
9
use Cone\Root\Fields\Meta;
10
use Cone\Root\Fields\Number;
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Http\Request;
13

14
class Price extends Meta
15
{
16
    /**
17
     * The price currency.
18
     */
19
    protected Currency $currency;
20

21
    /**
22
     * Create a new price field instance.
23
     */
24
    public function __construct(string $label, ?Currency $currency = null)
101✔
25
    {
26
        $this->currency = $currency ?: Bazar::getCurrency();
101✔
27

28
        parent::__construct($label, sprintf('price_%s', $this->currency->key()));
101✔
29

30
        $this->aggregateResolver = null;
101✔
31

32
        $this->as(Number::class, function (Number $field): void {
101✔
33
            $field->min(0)
101✔
34
                ->format(function (Request $request, Model $model, mixed $value): ?string {
101✔
35
                    return match (true) {
36
                        is_null($value) => null,
×
37
                        default => $this->currency->format((float) ($value ?? 0)),
×
38
                    };
39
                })
101✔
40
                ->suffix($this->currency->value);
101✔
41
        });
101✔
42
    }
43

44
    /**
45
     * Set the currency attribute.
46
     */
47
    public function currency(Currency $value): static
×
48
    {
49
        $this->currency = $value;
×
50

51
        $this->modelAttribute = sprintf('price_%s', $value->key());
×
52

53
        return $this;
×
54
    }
55
}
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