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

luttje / filament-user-attributes / 16229874913

11 Jul 2025 09:14PM UTC coverage: 81.138% (+6.6%) from 74.489%
16229874913

push

github

luttje
Fix tests related to attribute configuring

2168 of 2672 relevant lines covered (81.14%)

33.15 hits per line

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

82.43
/src/Filament/Factories/NumberInputComponentFactory.php
1
<?php
2

3
namespace Luttje\FilamentUserAttributes\Filament\Factories;
4

5
use Filament\Forms\Components\Checkbox;
6
use Filament\Forms\Components\Field;
7
use Filament\Forms\Components\Select;
8
use Filament\Forms\Components\TextInput;
9
use Filament\Forms\Get;
10
use Filament\Forms\Set;
11
use Filament\Tables\Columns\Column;
12
use Luttje\FilamentUserAttributes\Filament\Tables\UserAttributeColumn;
13

14
class NumberInputComponentFactory extends BaseComponentFactory
15
{
16
    public const DEFAULT_MINIMUM = -999999;
17

18
    public const DEFAULT_MAXIMUM = 999999;
19

20
    public function makeColumn(array $userAttribute): Column
×
21
    {
22
        $customizations = $userAttribute['customizations'] ?? [];
×
23

24
        $column = UserAttributeColumn::make($userAttribute['name']);
×
25

26
        if (isset($customizations['is_currency'])) {
×
27
            $column->money(
×
28
                currency: $customizations['currency_format'] ?? 'EUR',
×
29
            );
×
30
        } else {
31
            $column->numeric(
×
32
                decimalPlaces: isset($customizations['decimal_places']) ? $customizations['decimal_places'] : 0
×
33
            );
×
34
        }
35

36
        return $this->setUpColumn($column, $userAttribute);
×
37
    }
38

39
    public function makeField(array $userAttribute): Field
4✔
40
    {
41
        $customizations = $userAttribute['customizations'] ?? [];
4✔
42

43
        $field = TextInput::make($userAttribute['name'])
4✔
44
            ->numeric()
4✔
45
            ->step(
4✔
46
                isset($customizations['decimal_places'])
4✔
47
                    ? (1 / (10 ** $customizations['decimal_places']))
4✔
48
                    : 1
4✔
49
            )
4✔
50
            ->minValue($customizations['minimum'] ?? static::DEFAULT_MINIMUM)
4✔
51
            ->maxValue($customizations['maximum'] ?? static::DEFAULT_MAXIMUM);
4✔
52

53
        return $this->setUpField($field, $userAttribute);
4✔
54
    }
55

56
    public function makeDefaultValue(array $userAttribute): mixed
4✔
57
    {
58
        return 0;
4✔
59
    }
60

61
    public function makeConfigurationSchema(): array
40✔
62
    {
63
        $allCurrencyData = require __DIR__ . '/../../Data/ISO4217.php';
40✔
64

65
        $popularCurrencyCodes = ['USD', 'EUR', 'GBP', 'JPY', 'CAD'];
40✔
66

67
        $popularCurrencies = [];
40✔
68
        $remainingCurrencies = [];
40✔
69

70
        foreach ($allCurrencyData as $code => $currency) {
40✔
71
            $label = $currency['name'] . ' (' . $currency['symbol'] . ')';
40✔
72

73
            if (in_array($code, $popularCurrencyCodes, true)) {
40✔
74
                $popularCurrencies[$code] = $label;
40✔
75
            } else {
76
                $remainingCurrencies[$code] = $label;
40✔
77
            }
78
        }
79

80
        asort($popularCurrencies);
40✔
81
        asort($remainingCurrencies);
40✔
82

83
        return [
40✔
84
            Checkbox::make('is_currency')
40✔
85
                ->label(ucfirst(__('filament-user-attributes::user-attributes.attributes.is_currency')))
40✔
86
                ->default(false)
40✔
87
                ->live()
40✔
88
                ->afterStateUpdated(function (Set $set, ?bool $state) {
40✔
89
                    if ($state) {
×
90
                        $set('currency_format', 'EUR');
×
91
                    }
92
                }),
40✔
93

94
            Select::make('currency_format')
40✔
95
                ->label(ucfirst(__('filament-user-attributes::user-attributes.attributes.currency_format')))
40✔
96
                ->options([
40✔
97
                    __('filament-user-attributes::user-attributes.attributes.currency_format_common') => $popularCurrencies,
40✔
98
                    __('filament-user-attributes::user-attributes.attributes.currency_format_other') => $remainingCurrencies
40✔
99
                ])
40✔
100
                ->default('EUR')
40✔
101
                ->visible(fn (Get $get) => $get('is_currency')),
40✔
102

103
            TextInput::make('decimal_places')
40✔
104
                ->numeric()
40✔
105
                ->label(ucfirst(__('filament-user-attributes::user-attributes.attributes.decimal_places')))
40✔
106
                ->step(1)
40✔
107
                ->required()
40✔
108
                ->default(0),
40✔
109

110
            TextInput::make('minimum')
40✔
111
                ->numeric()
40✔
112
                ->label(ucfirst(__('filament-user-attributes::user-attributes.attributes.minimum')))
40✔
113
                ->step(fn (Get $get) => $get('decimal_places') * 0.1)
40✔
114
                ->minValue(static::DEFAULT_MINIMUM)
40✔
115
                ->default(static::DEFAULT_MINIMUM),
40✔
116

117
            TextInput::make('maximum')
40✔
118
                ->numeric()
40✔
119
                ->label(ucfirst(__('filament-user-attributes::user-attributes.attributes.maximum')))
40✔
120
                ->step(fn (Get $get) => $get('decimal_places') * 0.1)
40✔
121
                ->maxValue(static::DEFAULT_MAXIMUM)
40✔
122
                ->default(static::DEFAULT_MAXIMUM),
40✔
123

124
            ...parent::makeConfigurationSchema(),
40✔
125
        ];
40✔
126
    }
127
}
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

© 2025 Coveralls, Inc