Skip to content

Commit 3fe5348

Browse files
fix: phpstan errors (#17)
1 parent 71fa399 commit 3fe5348

File tree

7 files changed

+33
-6
lines changed

7 files changed

+33
-6
lines changed

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ parameters:
1212
ignoreErrors:
1313
-
1414
identifier: missingType.iterableValue
15+
-
16+
identifier: property.defaultValue
17+
-
18+
identifier: trait.unused
1519

src/Abstracts/BaseBlock.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function getUrlForFile(array | string | null $path = null): ?strin
4848
return static::generatedStorageUrl($path);
4949
}
5050

51-
if (is_array($path) && count($path) > 0) {
51+
if (count($path) > 0) {
5252
$filePath = array_values($path)[0];
5353
if (is_string($filePath)) {
5454
return static::generatedStorageUrl($filePath);
@@ -98,4 +98,11 @@ public static function getBlockLabel(array $state, ?int $index = null): mixed
9898

9999
return static::getBlockName() . ' - ' . ($index + 1);
100100
}
101+
102+
public static function getBaseBlockSchema(?object $record = null): array
103+
{
104+
return [
105+
// schema
106+
];
107+
}
101108
}

src/Commands/CreatePageBuilderPluginBlockCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function handle(): int
120120
);
121121
}
122122

123-
if ($isGlobal && isset($isFirstGlobalBlock) && $isFirstGlobalBlock) {
123+
if ($isGlobal && $isFirstGlobalBlock) {
124124
$this->info('To manage global blocks in Filament, add the GlobalBlocksPlugin to your panel:');
125125
}
126126

src/Components/Forms/RadioButtonImage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function getFormattedOptions(): array
7676
$options = collect($options);
7777

7878
return $options->flatMap(function ($categoryOptions, $category) {
79+
// @phpstan-ignore-next-line
7980
return collect($categoryOptions)->mapWithKeys(function ($option, $key) use ($category) {
8081
return [
8182
$key => [

src/Models/GlobalBlockConfig.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Support\Facades\File;
8+
use Redberry\PageBuilderPlugin\Abstracts\BaseBlock;
89
use ReflectionClass;
910

11+
/**
12+
* @property string $id
13+
* @property string $name
14+
* @property class-string<BaseBlock> $class_name
15+
* @property array $configuration
16+
*/
1017
class GlobalBlockConfig extends Model
1118
{
1219
use HasFactory;

src/Resources/GlobalBlockConfigResource.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Redberry\PageBuilderPlugin\Resources;
44

55
use Filament\Forms;
6+
use Filament\Forms\Components\Field;
67
use Filament\Forms\Form;
78
use Filament\Resources\Resource;
89
use Filament\Tables;
@@ -49,6 +50,8 @@ public static function form(Form $form): Form
4950
}
5051

5152
foreach ($schema as $field) {
53+
/** @var Field $field */
54+
$field = $field;
5255
if (method_exists($field, 'getName')) {
5356
$fieldName = $field->getName();
5457
$configValue = $record->getConfigValue($fieldName);

src/Resources/GlobalBlockConfigResource/Pages/EditGlobalBlock.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Filament\Actions;
66
use Filament\Resources\Pages\EditRecord;
7+
use Redberry\PageBuilderPlugin\Models\GlobalBlockConfig;
78
use Redberry\PageBuilderPlugin\Resources\GlobalBlockConfigResource;
89

910
class EditGlobalBlock extends EditRecord
@@ -26,9 +27,11 @@ protected function getHeaderActions(): array
2627

2728
protected function mutateFormDataBeforeFill(array $data): array
2829
{
29-
$blockClass = $this->record->class_name;
30+
/** @var GlobalBlockConfig $record */
31+
$record = $this->record;
32+
$blockClass = $record->class_name;
3033

31-
if (class_exists($blockClass) && $this->record->configuration) {
34+
if (class_exists($blockClass) && $record->configuration) {
3235
try {
3336
if (method_exists($blockClass, 'getBaseBlockSchema')) {
3437
$schema = $blockClass::getBaseBlockSchema();
@@ -39,7 +42,7 @@ protected function mutateFormDataBeforeFill(array $data): array
3942
foreach ($schema as $field) {
4043
if (method_exists($field, 'getName')) {
4144
$fieldName = $field->getName();
42-
$configValue = $this->record->getConfigValue($fieldName);
45+
$configValue = $record->getConfigValue($fieldName);
4346
if ($configValue !== null) {
4447
$data[$fieldName] = $configValue;
4548
}
@@ -55,7 +58,9 @@ protected function mutateFormDataBeforeFill(array $data): array
5558
protected function mutateFormDataBeforeSave(array $data): array
5659
{
5760
$configuration = [];
58-
$blockClass = $this->record->class_name;
61+
/** @var GlobalBlockConfig $record */
62+
$record = $this->record;
63+
$blockClass = $record->class_name;
5964

6065
if (class_exists($blockClass)) {
6166
try {

0 commit comments

Comments
 (0)