• 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

53.33
/src/Models/Price.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Models;
6

7
use Closure;
8
use Cone\Bazar\Bazar;
9
use Cone\Root\Models\Meta;
10
use Illuminate\Database\Eloquent\Casts\Attribute;
11
use Illuminate\Support\Str;
12

13
class Price extends Meta
14
{
15
    /**
16
     * The attributes that should be cast to native types.
17
     *
18
     * @var array<string, string>
19
     */
20
    protected $casts = [
21
        'value' => 'float',
22
    ];
23

24
    /**
25
     * The value formatters.
26
     */
27
    protected static array $formatters = [];
28

29
    /**
30
     * Register a formatter to the given currency.
31
     */
32
    public static function formatCurrency(string $currency, Closure $callback): void
33
    {
34
        static::$formatters[$currency] = $callback;
×
35
    }
36

37
    /**
38
     * Get the currency attribute.
39
     *
40
     * @return \Illuminate\Database\Eloquent\Casts\Attribute<string, never>
41
     */
42
    protected function currency(): Attribute
43
    {
44
        return new Attribute(
1✔
45
            get: static function (mixed $value, array $attributes): string {
1✔
UNCOV
46
                return Str::before(str_replace('price_', '', $attributes['key']), '_');
×
47
            }
1✔
48
        );
1✔
49
    }
50

51
    /**
52
     * Get the currency symbol attribute.
53
     *
54
     * @return \Illuminate\Database\Eloquent\Casts\Attribute<string, never>
55
     */
56
    protected function symbol(): Attribute
57
    {
58
        return new Attribute(
1✔
59
            get: static function (mixed $value, array $attributes): string {
1✔
UNCOV
60
                return Bazar::getCurrencies()[$attributes['currency']] ?? $attributes['currency'];
×
61
            }
1✔
62
        );
1✔
63
    }
64

65
    /**
66
     * Format the price.
67
     */
68
    public function format(): string
69
    {
UNCOV
70
        $currency = $this->currency;
×
71

UNCOV
72
        if (isset(static::$formatters[$currency])) {
×
73
            return call_user_func_array(static::$formatters[$this->currency], [$this->value, $this->symbol, $currency]);
×
74
        }
75

UNCOV
76
        return sprintf('%s %s', number_format($this->value, 2, '.', ' '), $this->symbol);
×
77
    }
78
}
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