diff --git a/src/Admin/BaseFieldDescription.php b/src/Admin/BaseFieldDescription.php index 53be393f2f..0a3a0f7568 100644 --- a/src/Admin/BaseFieldDescription.php +++ b/src/Admin/BaseFieldDescription.php @@ -63,6 +63,8 @@ * * @author Thomas Rabaix * + * @psalm-import-type FieldDescriptionOptions from FieldDescriptionInterface + * * @method void setFieldMapping(array $fieldMapping) * @method void setAssociationMapping(array $associationMapping) * @method void setParentAssociationMappings(array $parentAssociationMappings) @@ -141,6 +143,9 @@ abstract class BaseFieldDescription implements FieldDescriptionInterface /** * NEXT_MAJOR: Remove the null default value for $name and restrict param type to `string`. + * + * @psalm-param FieldDescriptionOptions $options + * @phpstan-param array $options */ public function __construct( ?string $name = null, diff --git a/src/Admin/FieldDescriptionInterface.php b/src/Admin/FieldDescriptionInterface.php index 7b8a46d9d8..0474f6b707 100644 --- a/src/Admin/FieldDescriptionInterface.php +++ b/src/Admin/FieldDescriptionInterface.php @@ -14,10 +14,46 @@ namespace Sonata\AdminBundle\Admin; use Sonata\AdminBundle\Exception\NoValueException; +use Symfony\Component\Form\DataTransformerInterface; +use Symfony\Component\PropertyAccess\PropertyPathInterface; /** * @author Thomas Rabaix * + * @psalm-type FieldDescriptionOptions = array{ + * accessor?: string|callable|PropertyPathInterface, + * actions?: array, + * admin_code?: string, + * associated_property?: string, + * block_name?: string, + * catalogue?: string, + * data_transformer?: DataTransformerInterface, + * edit?: string, + * editable?: bool, + * field_name?: string, + * field_options?: array, + * field_type?: string, + * header_class?: string, + * identifier?: bool, + * inline?: string, + * label?: bool|string|null, + * link_parameters?: array, + * multiple?: bool, + * placeholder?: string, + * required?: bool, + * role?: string|string[], + * route?: array, + * safe?: bool, + * sort_field_mapping?: array, + * sort_parent_association_mappings?: array, + * sortable?: bool, + * template?: string, + * timezone?: string|\DateTimeZone, + * translation_domain?: string, + * type?: string, + * virtual_field?: bool + * } + * * @method string|null getTargetModel() * @method bool hasAdmin() * @method bool hasParent() @@ -105,6 +141,9 @@ public function setOption($name, $value); * - template. * * Then the value are copied across to the related property value + * + * @psalm-param FieldDescriptionOptions $options + * @phpstan-param array $options */ public function setOptions(array $options); @@ -112,6 +151,9 @@ public function setOptions(array $options); * Returns options. * * @return array options + * + * @psalm-return FieldDescriptionOptions + * @phpstan-return array */ public function getOptions(); diff --git a/src/FieldDescription/FieldDescriptionFactoryInterface.php b/src/FieldDescription/FieldDescriptionFactoryInterface.php index e76f8292d0..28be299bb4 100644 --- a/src/FieldDescription/FieldDescriptionFactoryInterface.php +++ b/src/FieldDescription/FieldDescriptionFactoryInterface.php @@ -15,10 +15,15 @@ use Sonata\AdminBundle\Admin\FieldDescriptionInterface; +/** + * @psalm-import-type FieldDescriptionOptions from FieldDescriptionInterface + */ interface FieldDescriptionFactoryInterface { /** * @phpstan-param class-string $class + * @psalm-param FieldDescriptionOptions $options + * @phpstan-param array $options */ public function create(string $class, string $name, array $options = []): FieldDescriptionInterface; }