Skip to content

Commit

Permalink
Add FieldDescriptionOptions psalm type
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Mar 7, 2021
1 parent df4d99e commit c1db7b6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Admin/BaseFieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
*
* @author Thomas Rabaix <[email protected]>
*
* @psalm-import-type FieldDescriptionOptions from FieldDescriptionInterface
*
* @method void setFieldMapping(array $fieldMapping)
* @method void setAssociationMapping(array $associationMapping)
* @method void setParentAssociationMappings(array $parentAssociationMappings)
Expand Down Expand Up @@ -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<string, mixed> $options
*/
public function __construct(
?string $name = null,
Expand Down
42 changes: 42 additions & 0 deletions src/Admin/FieldDescriptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*
* @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()
Expand Down Expand Up @@ -105,13 +141,19 @@ public function setOption($name, $value);
* - template.
*
* Then the value are copied across to the related property value
*
* @psalm-param FieldDescriptionOptions $options
* @phpstan-param array<string, mixed> $options
*/
public function setOptions(array $options);

/**
* Returns options.
*
* @return array<string, mixed> options
*
* @psalm-return FieldDescriptionOptions
* @phpstan-return array<string, mixed>
*/
public function getOptions();

Expand Down
5 changes: 5 additions & 0 deletions src/FieldDescription/FieldDescriptionFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $options
*/
public function create(string $class, string $name, array $options = []): FieldDescriptionInterface;
}

0 comments on commit c1db7b6

Please sign in to comment.