Skip to content

Commit be69a4d

Browse files
committed
fix: PHPStan errors
1 parent be8e597 commit be69a4d

File tree

5 files changed

+22
-32
lines changed

5 files changed

+22
-32
lines changed

database/factories/FieldFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ class FieldFactory extends Factory
99
{
1010
protected $model = Field::class;
1111

12-
/**
13-
* Define the model's default state.
14-
*
15-
* @return array<string, mixed>
16-
*/
1712
public function definition(): array
1813
{
1914
return [

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ parameters:
1010
tmpDir: build/phpstan
1111
checkOctaneCompatibility: true
1212
checkModelProperties: true
13+
ignoreErrors:
14+
- '#Trait .* is used zero times and is not analysed#'
1315

src/Concerns/HasContentCleaning.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Backstage\Fields\Services\ContentCleaningService;
66

7+
/** @phpstan-ignore-next-line */
78
trait HasContentCleaning
89
{
910
/**

src/Concerns/HasFields.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Backstage\Fields\Models\Field;
66
use Illuminate\Database\Eloquent\Relations\MorphMany;
77

8+
/** @phpstan-ignore-next-line */
89
trait HasFields
910
{
1011
public string $valueColumn = 'values';

src/Concerns/HasSelectableValues.php

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
namespace Backstage\Fields\Concerns;
44

5+
use Illuminate\Support\Str;
6+
use Filament\Forms\Components\Select;
57
use Filament\Forms\Components\Hidden;
8+
use Filament\Schemas\Components\Grid;
9+
use Illuminate\Support\Facades\Schema;
610
use Filament\Forms\Components\Repeater;
7-
use Filament\Forms\Components\Select;
811
use Filament\Forms\Components\TextInput;
912
use Filament\Schemas\Components\Fieldset;
10-
use Filament\Schemas\Components\Grid;
13+
use Filament\Forms\Components\CheckboxList;
1114
use Filament\Schemas\Components\Utilities\Get;
1215
use Filament\Schemas\Components\Utilities\Set;
13-
use Illuminate\Support\Facades\Schema;
14-
use Illuminate\Support\Str;
1516

1617
trait HasSelectableValues
1718
{
@@ -83,24 +84,14 @@ protected static function ensureFieldConfig(mixed $field, string $type): bool
8384

8485
protected static function shouldHandleRelationshipOptions(mixed $field, string $type): bool
8586
{
86-
// Ensure $type is a string to prevent array key errors
87-
if (! is_string($type)) {
88-
return false;
89-
}
90-
91-
return isset($field->config[$type]) && $field->config[$type] !== null &&
87+
return isset($field->config[$type]) &&
9288
(is_string($field->config[$type]) && $field->config[$type] === 'relationship') ||
9389
(is_array($field->config[$type]) && in_array('relationship', $field->config[$type]));
9490
}
9591

9692
protected static function shouldHandleArrayOptions(mixed $field, string $type): bool
9793
{
98-
// Ensure $type is a string to prevent array key errors
99-
if (! is_string($type)) {
100-
return false;
101-
}
102-
103-
return isset($field->config[$type]) && $field->config[$type] !== null &&
94+
return isset($field->config[$type]) &&
10495
(is_string($field->config[$type]) && $field->config[$type] === 'array') ||
10596
(is_array($field->config[$type]) && in_array('array', $field->config[$type]));
10697
}
@@ -158,7 +149,7 @@ protected static function mergeRelationshipOptions(array $allOptions, array $rel
158149
}
159150

160151
// If both types are selected, group relationship options by resource
161-
if (isset($field->config[$type]) && $field->config[$type] !== null &&
152+
if (isset($field->config[$type]) &&
162153
(is_array($field->config[$type]) && in_array('array', $field->config[$type]))) {
163154
return array_merge($allOptions, $relationshipOptions);
164155
} else {
@@ -174,7 +165,7 @@ protected static function mergeArrayOptions(array $allOptions, mixed $field, str
174165
}
175166

176167
// If both types are selected, group array options
177-
if (isset($field->config[$type]) && $field->config[$type] !== null &&
168+
if (isset($field->config[$type]) &&
178169
(is_array($field->config[$type]) && in_array('relationship', $field->config[$type]))) {
179170
$allOptions[__('Custom Options')] = $field->config['options'];
180171
} else {
@@ -204,12 +195,12 @@ protected function selectableValuesFormFields(string $type, string $label, strin
204195
->schema([
205196
Grid::make(2)
206197
->schema([
207-
Backstage\Fields\Fields\CheckboxList::make("config.{$type}")
198+
CheckboxList::make("config.{$type}")
208199
->options([
209200
'array' => __('Array'),
210201
'relationship' => __('Relationship'),
211202
])
212-
->afterStateHydrated(function (Forms\Get $get, Forms\Set $set) use ($type) {
203+
->afterStateHydrated(function (Get $get, Set $set) use ($type) {
213204
$value = $get("config.{$type}");
214205

215206
// Set correct config value when creating records
@@ -222,11 +213,11 @@ protected function selectableValuesFormFields(string $type, string $label, strin
222213
->label(__('Options'))
223214
->columnSpanFull()
224215
->visible(
225-
fn (Forms\Get $get): bool => is_array($get("config.{$type}")) && in_array('array', $get("config.{$type}")) ||
216+
fn (Get $get): bool => is_array($get("config.{$type}")) && in_array('array', $get("config.{$type}")) ||
226217
$get("config.{$type}") === 'array'
227218
)
228219
->required(
229-
fn (Forms\Get $get): bool => is_array($get("config.{$type}")) && in_array('array', $get("config.{$type}")) ||
220+
fn (Get $get): bool => is_array($get("config.{$type}")) && in_array('array', $get("config.{$type}")) ||
230221
$get("config.{$type}") === 'array'
231222
),
232223
// Relationship options
@@ -277,10 +268,10 @@ protected function selectableValuesFormFields(string $type, string $label, strin
277268
})
278269
->noSearchResultsMessage(__('No types found'))
279270
->required(
280-
fn (Forms\Get $get): bool => is_array($get("../../config.{$type}")) && in_array('relationship', $get("../../config.{$type}")) ||
271+
fn (Get $get): bool => is_array($get("../../config.{$type}")) && in_array('relationship', $get("../../config.{$type}")) ||
281272
$get("../../config.{$type}") === 'relationship'
282273
),
283-
Forms\Components\Select::make('relationValue')
274+
Select::make('relationValue')
284275
->label(__('Column'))
285276
->helperText(__('The column to use as name for the options'))
286277
->options(fn (Get $get) => $get('relationValue_options') ?? [])
@@ -291,10 +282,10 @@ protected function selectableValuesFormFields(string $type, string $label, strin
291282
->default('ulid')
292283
->label(__('Key'))
293284
->required(
294-
fn (Forms\Get $get): bool => is_array($get("../../config.{$type}")) && in_array('relationship', $get("../../config.{$type}")) ||
285+
fn (Get $get): bool => is_array($get("../../config.{$type}")) && in_array('relationship', $get("../../config.{$type}")) ||
295286
$get("../../config.{$type}") === 'relationship'
296287
),
297-
Forms\Components\Repeater::make('relationValue_filters')
288+
Repeater::make('relationValue_filters')
298289
->label(__('Filters'))
299290
->visible(fn (Get $get): bool => ! empty($get('resource')))
300291
->schema([
@@ -347,7 +338,7 @@ protected function selectableValuesFormFields(string $type, string $label, strin
347338
]),
348339
])
349340
->visible(
350-
fn (Forms\Get $get): bool => is_array($get("config.{$type}")) && in_array('relationship', $get("config.{$type}")) ||
341+
fn (Get $get): bool => is_array($get("config.{$type}")) && in_array('relationship', $get("config.{$type}")) ||
351342
$get("config.{$type}") === 'relationship'
352343
)
353344
->columnSpanFull(),

0 commit comments

Comments
 (0)