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

conedevelopment / bazar / 20312410163

17 Dec 2025 05:58PM UTC coverage: 64.395% (+0.9%) from 63.48%
20312410163

push

github

web-flow
Merge pull request #235 from conedevelopment/coupons

Coupons & Discounts

204 of 260 new or added lines in 23 files covered. (78.46%)

8 existing lines in 1 file now uncovered.

1096 of 1702 relevant lines covered (64.39%)

18.27 hits per line

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

16.67
/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 value formatters.
17
     */
18
    protected static array $formatters = [];
19

20
    /**
21
     * Register a formatter to the given currency.
22
     */
23
    public static function formatCurrency(string $currency, Closure $callback): void
24
    {
25
        static::$formatters[$currency] = $callback;
×
26
    }
27

28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function casts(): array
32
    {
33
        return [
41✔
34
            'value' => 'float',
41✔
35
        ];
41✔
36
    }
37

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

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

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

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

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