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 more typehints #8101

Closed
Closed
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, $default = null)
final public function getPersistentParameter(string $name, $default = null): mixed
{
$parameters = $this->getPersistentParameters();

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, $default = null)
final public function getOption(string $name, $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, $default = null)
final public function getFieldOption(string $name, $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, $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
jordisala1991 marked this conversation as resolved.
Show resolved Hide resolved
*/
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
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, $default = null)
public function getOption($name, $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): static
jordisala1991 marked this conversation as resolved.
Show resolved Hide resolved
{
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
4 changes: 2 additions & 2 deletions src/Security/Handler/AclSecurityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function deleteAcl(ObjectIdentityInterface $objectIdentity): void
$this->aclProvider->deleteAcl($objectIdentity);
}

public function findClassAceIndexByRole(MutableAclInterface $acl, string $role)
public function findClassAceIndexByRole(MutableAclInterface $acl, string $role): int|false
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
{
foreach ($acl->getClassAces() as $index => $entry) {
$securityIdentity = $entry->getSecurityIdentity();
Expand All @@ -268,7 +268,7 @@ public function findClassAceIndexByRole(MutableAclInterface $acl, string $role)
return false;
}

public function findClassAceIndexByUsername(MutableAclInterface $acl, string $username)
public function findClassAceIndexByUsername(MutableAclInterface $acl, string $username): int|false
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
{
foreach ($acl->getClassAces() as $index => $entry) {
$securityIdentity = $entry->getSecurityIdentity();
Expand Down
5 changes: 1 addition & 4 deletions src/SonataConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ public function getLogo(): string
return $this->logo;
}

/**
* @return mixed
*/
public function getOption(string $name, mixed $default = null)
public function getOption(string $name, mixed $default = null): mixed
{
return $this->options[$name] ?? $default;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Twig/Extension/RenderElementExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ public function renderViewElementCompare(
* @deprecated since sonata-project/admin-bundle version 4.7 use RenderElementRuntime::renderRelationElement() instead
*
* @throws \RuntimeException
*
* @return mixed
*/
public function renderRelationElement(mixed $element, FieldDescriptionInterface $fieldDescription)
public function renderRelationElement(mixed $element, FieldDescriptionInterface $fieldDescription): mixed
{
@trigger_error(sprintf(
'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.'
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Extension/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
/**
* @return TwigFilter[]
*/
public function getFilters()
public function getFilters(): array
{
return [
new TwigFilter(
Expand Down
4 changes: 1 addition & 3 deletions src/Twig/RenderElementRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ public function renderViewElementCompare(

/**
* @throws \RuntimeException
*
* @return mixed
*/
public function renderRelationElement(mixed $element, FieldDescriptionInterface $fieldDescription)
public function renderRelationElement(mixed $element, FieldDescriptionInterface $fieldDescription): mixed
{
if (!\is_object($element)) {
return $element;
Expand Down
2 changes: 0 additions & 2 deletions src/Util/AdminObjectAclManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ private function buildForm(AdminObjectAclData $data, FormBuilderInterface $formB

/**
* Gets a user or a role security identity.
*
* @return RoleSecurityIdentity|UserSecurityIdentity
*/
private function getSecurityIdentity(string|UserInterface $aclValue): SecurityIdentityInterface
{
Expand Down
11 changes: 11 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,19 @@ protected function configureContainer(ContainerBuilder $containerBuilder, Loader
],
'http_method_override' => false,
'session' => [
'cookie_secure' => 'auto',
'cookie_samesite' => 'lax',
'save_path' => null,
'storage_factory_id' => 'session.storage.factory.mock_file',
],
'validation' => [
'email_validation_mode' => 'html5',
],
'php_errors' => [
'log' => true,
],
// Not present on all Symfony versions, since 6.3, need to add it conditionally
// 'handle_all_throwables' => true,
]);

$securityConfig = [
Expand Down
2 changes: 1 addition & 1 deletion tests/App/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
final class ProxyQuery implements ProxyQueryInterface
{
public function execute()
public function execute(): iterable
{
throw new \BadMethodCallException('Not implemented.');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/App/FieldDescription/FieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function isIdentifier(): bool
return false;
}

public function getValue(object $object)
public function getValue(object $object): mixed
{
return $this->getFieldValue($object, $this->fieldName);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/App/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function addIdentifiersToQuery(string $class, ProxyQueryInterface $query,
{
}

public function getLockVersion(object $object)
public function getLockVersion(object $object): mixed
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/App/Model/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface RepositoryInterface
/**
* @return T|null
*/
public function byId(string $id);
public function byId(string $id): ?EntityInterface;

/**
* @return array<T>
Expand Down
4 changes: 1 addition & 3 deletions tests/Datagrid/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,8 @@ public function testGetPreviousPage(): void

/**
* @param mixed[] $args
*
* @return mixed
*/
protected function callMethod(object $obj, string $name, array $args = [])
protected function callMethod(object $obj, string $name, array $args = []): mixed
{
$class = new \ReflectionClass($obj);
$method = $class->getMethod($name);
Expand Down
Loading