Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BC typehint #8180

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ final public function getPersistentParameters(): array
return $parameters;
}

final public function getPersistentParameter(string $name, mixed $default = null)
final public function getPersistentParameter(string $name, mixed $default = null): mixed
{
$parameters = $this->getPersistentParameters();

Expand Down
8 changes: 5 additions & 3 deletions src/Datagrid/DatagridMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function getAdmin(): AdminInterface
*
* @throws \LogicException
*
* @return $this
*
* @phpstan-param class-string|null $type
* @phpstan-param FieldDescriptionOptions $fieldDescriptionOptions
*/
Expand All @@ -62,7 +64,7 @@ public function add(
?string $type = null,
array $filterOptions = [],
array $fieldDescriptionOptions = []
): static {
): self {
if (
isset($fieldDescriptionOptions['role'])
&& \is_string($fieldDescriptionOptions['role'])
Expand Down Expand Up @@ -107,15 +109,15 @@ public function keys(): array
return array_keys($this->datagrid->getFilters());
}

public function remove(string $key): static
public function remove(string $key): self
{
$this->getAdmin()->removeFilterFieldDescription($key);
$this->datagrid->removeFilter($key);

return $this;
}

public function reorder(array $keys): static
public function reorder(array $keys): self
{
$this->datagrid->reorderFilters($keys);

Expand Down
12 changes: 8 additions & 4 deletions src/Datagrid/ListMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public function getAdmin(): AdminInterface
/**
* @param array<string, mixed> $fieldDescriptionOptions
*
* @return $this
*
* @phpstan-param FieldDescriptionOptions $fieldDescriptionOptions
*/
public function addIdentifier(string $name, ?string $type = null, array $fieldDescriptionOptions = []): static
public function addIdentifier(string $name, ?string $type = null, array $fieldDescriptionOptions = []): self
{
$fieldDescriptionOptions['identifier'] = true;

Expand All @@ -74,9 +76,11 @@ public function addIdentifier(string $name, ?string $type = null, array $fieldDe
*
* @throws \LogicException
*
* @return $this
*
* @phpstan-param FieldDescriptionOptions $fieldDescriptionOptions
*/
public function add(string $name, ?string $type = null, array $fieldDescriptionOptions = []): static
public function add(string $name, ?string $type = null, array $fieldDescriptionOptions = []): self
{
if (
isset($fieldDescriptionOptions['role'])
Expand Down Expand Up @@ -151,7 +155,7 @@ public function has(string $key): bool
return $this->list->has($key);
}

public function remove(string $key): static
public function remove(string $key): self
{
$this->getAdmin()->removeListFieldDescription($key);
$this->list->remove($key);
Expand All @@ -164,7 +168,7 @@ public function keys(): array
return array_keys($this->list->getElements());
}

public function reorder(array $keys): static
public function reorder(array $keys): self
{
$this->list->reorder($keys);

Expand Down
8 changes: 4 additions & 4 deletions src/Datagrid/ProxyQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ public function execute();
* @param array<array<string, mixed>> $parentAssociationMappings
* @param array<string, mixed> $fieldMapping
*
* @return static
* @return $this
*/
public function setSortBy(array $parentAssociationMappings, array $fieldMapping): self;

public function getSortBy(): ?string;

/**
* @return static
* @return $this
*/
public function setSortOrder(string $sortOrder): self;

public function getSortOrder(): ?string;

/**
* @return static
* @return $this
*/
public function setFirstResult(?int $firstResult): self;

public function getFirstResult(): ?int;

/**
* @return static
* @return $this
*/
public function setMaxResults(?int $maxResults): self;

Expand Down
15 changes: 5 additions & 10 deletions src/FieldDescription/BaseFieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ final public function getName(): string
return $this->name;
}

final public function getOption(string $name, mixed $default = null)
final public function getOption(string $name, mixed $default = null): mixed
{
return $this->options[$name] ?? $default;
}
Expand Down Expand Up @@ -324,15 +324,12 @@ final public function mergeOption(string $name, array $options = []): void
$this->options[$name] = array_merge($this->options[$name], $options);
}

final public function getMappingType()
final public function getMappingType(): int|string|null
{
return $this->mappingType;
}

/**
* @return string|false|null
*/
final public function getLabel()
final public function getLabel(): string|false|null
{
return $this->getOption('label');
}
Expand All @@ -352,7 +349,7 @@ final public function getSortParentAssociationMapping(): array
return $this->getOption('sort_parent_association_mappings');
}

final public function getTranslationDomain()
final public function getTranslationDomain(): string|false
{
return $this->getOption('translation_domain') ?? $this->getAdmin()->getTranslationDomain();
}
Expand Down Expand Up @@ -384,10 +381,8 @@ abstract protected function setParentAssociationMappings(array $parentAssociatio

/**
* @throws NoValueException
*
* @return mixed
*/
final protected function getFieldValue(?object $object, string $fieldName)
final protected function getFieldValue(?object $object, string $fieldName): mixed
{
if ($this->isVirtual() || null === $object) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final public function getFormName(): string
return str_replace('.', '__', $this->getName());
}

final public function getOption(string $name, mixed $default = null)
final public function getOption(string $name, mixed $default = null): mixed
{
if (\array_key_exists($name, $this->options)) {
return $this->options[$name];
Expand All @@ -96,7 +96,7 @@ final public function getFieldOptions(): array
return $this->getOption('field_options', []);
}

final public function getFieldOption(string $name, mixed $default = null)
final public function getFieldOption(string $name, mixed $default = null): mixed
{
if (isset($this->options['field_options'][$name]) && \is_array($this->options['field_options'])) {
return $this->options['field_options'][$name];
Expand All @@ -110,7 +110,7 @@ final public function setFieldOption(string $name, mixed $value): void
$this->options['field_options'][$name] = $value;
}

final public function getLabel()
final public function getLabel(): string|false|null
{
return $this->getOption('label');
}
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/Model/FilterData.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ public static function fromArray(array $data): self
return new self($type, \array_key_exists('value', $data), $data['value'] ?? null);
}

/**
* @return mixed
*/
public function getValue()
public function getValue(): mixed
{
if (!$this->hasValue) {
throw new \LogicException('The FilterData object does not have a value.');
Expand Down
4 changes: 1 addition & 3 deletions src/Form/Extension/Field/Type/FormTypeFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,8 @@ public function configureOptions(OptionsResolver $resolver): void
*
* return the value related to FieldDescription, if the associated object does no
* exists => a temporary one is created.
*
* @return mixed
*/
public function getValueFromFieldDescription(?object $object, FieldDescriptionInterface $fieldDescription)
public function getValueFromFieldDescription(?object $object, FieldDescriptionInterface $fieldDescription): mixed
{
@trigger_error(sprintf(
'The method "%s()" is deprecated since sonata-project/admin-bundle 4.3 and will be removed in 5.0.',
Expand Down
18 changes: 9 additions & 9 deletions src/Mapper/BaseGroupedMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class BaseGroupedMapper implements MapperInterface
*
* @throws \LogicException
*
* @return static
* @return $this
*/
final public function with(string $name, array $options = []): self
{
Expand Down Expand Up @@ -168,7 +168,7 @@ final public function with(string $name, array $options = []): self
/**
* Only nested add if the condition match true.
*
* @return static
* @return $this
*/
final public function ifTrue(bool $bool): self
{
Expand All @@ -180,7 +180,7 @@ final public function ifTrue(bool $bool): self
/**
* Only nested add if the condition match false.
*
* @return static
* @return $this
*/
final public function ifFalse(bool $bool): self
{
Expand All @@ -192,7 +192,7 @@ final public function ifFalse(bool $bool): self
/**
* @throws \LogicException
*
* @return static
* @return $this
*/
final public function ifEnd(): self
{
Expand All @@ -210,7 +210,7 @@ final public function ifEnd(): self
*
* @param array<string, mixed> $options
*
* @return static
* @return $this
*/
final public function tab(string $name, array $options = []): self
{
Expand All @@ -222,7 +222,7 @@ final public function tab(string $name, array $options = []): self
*
* @throws \LogicException
*
* @return static
* @return $this
*/
final public function end(): self
{
Expand Down Expand Up @@ -256,9 +256,9 @@ final public function hasOpenTab(): bool
* @param string $tab The tab the group belongs to, defaults to 'default'
* @param bool $deleteEmptyTab Whether or not the Tab should be deleted, when the deleted group leaves the tab empty after deletion
*
* @return static
* @return $this
*/
final public function removeGroup(string $group, string $tab = 'default', bool $deleteEmptyTab = false)
final public function removeGroup(string $group, string $tab = 'default', bool $deleteEmptyTab = false): self
{
$groups = $this->getGroups();

Expand Down Expand Up @@ -293,7 +293,7 @@ final public function removeGroup(string $group, string $tab = 'default', bool $
/**
* Removes a tab.
*
* @return static
* @return $this
*/
final public function removeTab(string $tab): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mapper/MapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function get(string $key);
public function has(string $key): bool;

/**
* @return static
* @return $this
*/
public function remove(string $key);

Expand All @@ -51,7 +51,7 @@ public function keys(): array;
/**
* @param string[] $keys
*
* @return static
* @return $this
*/
public function reorder(array $keys);
}
2 changes: 1 addition & 1 deletion src/Object/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getOptions(): array
return $this->options;
}

public function getOption($name, mixed $default = null)
public function getOption($name, mixed $default = null): mixed
{
return \array_key_exists($name, $this->options) ? $this->options[$name] : $default;
}
Expand Down
17 changes: 6 additions & 11 deletions src/Route/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function add(
array $schemes = [],
array $methods = [],
string $condition = ''
): RouteCollectionInterface {
): self {
$pattern = sprintf('%s/%s', $this->baseRoutePattern, $pattern ?? $name);
$code = $this->getCode($name);

Expand Down Expand Up @@ -84,7 +84,7 @@ public function getCode(string $name): string
return sprintf('%s.%s', $this->baseCodeRoute, $name);
}

public function addCollection(RouteCollectionInterface $collection): RouteCollectionInterface
public function addCollection(RouteCollectionInterface $collection): self
{
foreach ($collection->getElements() as $code => $element) {
$this->addElement($code, $element);
Expand Down Expand Up @@ -127,14 +127,14 @@ public function get(string $name): Route
throw new \InvalidArgumentException(sprintf('Element "%s" does not exist.', $name));
}

public function remove(string $name): RouteCollectionInterface
public function remove(string $name): self
{
unset($this->elements[$this->getCode($name)]);

return $this;
}

public function restore(string $name): RouteCollectionInterface
public function restore(string $name): self
{
if ($this->hasCached($name)) {
$code = $this->getCode($name);
Expand All @@ -146,12 +146,7 @@ public function restore(string $name): RouteCollectionInterface
throw new \InvalidArgumentException(sprintf('Element "%s" does not exist in cache.', $name));
}

/**
* @param string|string[] $routeList
*
* @return static
*/
public function clearExcept($routeList): RouteCollectionInterface
public function clearExcept($routeList): self
{
if (!\is_array($routeList)) {
$routeList = [$routeList];
Expand All @@ -172,7 +167,7 @@ public function clearExcept($routeList): RouteCollectionInterface
return $this;
}

public function clear(): RouteCollectionInterface
public function clear(): self
{
$this->elements = [];

Expand Down
Loading
Loading