10000 [PHPDoc] Fix some union type cases by fancyweb · Pull Request #40728 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PHPDoc] Fix some union type cases #40728

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

Merged
merged 1 commit into from
Apr 8, 2021
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.
10000 Loading
Diff view
Diff view
[PHPDoc] Fix some union type cases
  • Loading branch information
fancyweb committed Apr 7, 2021
commit dd1481642bfc34965e17d5e70e7fcc1bfcd2bfb4
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function getAccessDecisionLog()
/**
* Returns the configuration of the current firewall context.
*
* @return array|Data
* @return array|Data|null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->data['firewall'] = null; line 194

*/
public function getFirewall()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function getHeaders()
* @param string $header The header name
* @param bool $first Whether to return the first value or all header values
*
* @return string|array The first header value if $first is true, an array of values otherwise
* @return string|array|null The first header value if $first is true, an array of values otherwise
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return $first ? null : []; line 141

*/
public function getHeader($header, $first = true)
{
Expand Down
10 changes: 0 additions & 10 deletions src/Symfony/Component/Console/Descriptor/Descriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,26 @@ protected function write($content, $decorated = false)

/**
* Describes an InputArgument instance.
*
* @return string|mixed
*/
abstract protected function describeInputArgument(InputArgument $argument, array $options = []);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never return anything in the implementations and the class is @internal.


/**
* Describes an InputOption instance.
*
* @return string|mixed
*/
abstract protected function describeInputOption(InputOption $option, array $options = []);

/**
* Describes an InputDefinition instance.
*
* @return string|mixed
*/
abstract protected function describeInputDefinition(InputDefinition $definition, array $options = []);

/**
* Describes a Command instance.
*
* @return string|mixed
*/
abstract protected function describeCommand(Command $command, array $options = []);

/**
* Describes an Application instance.
*
* @return string|mixed
*/
abstract protected function describeApplication(Application $application, array $options = []);
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private function formatDefaultValue($default): string
}

/**
* @param (Command|string)[] $commands
* @param array<Command|string> $commands
Copy link
Contributor Author
@fancyweb fancyweb Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about this notation, I think array<Foo|string> is widespread in SCA tools. I plan to support this notation in the DebugClassLoader. Note that here it does not matter on a @param but some @return use it and I changed them all for consitency.

*/
private function getColumnWidth(array $commands): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function disableStty()
/**
* Asks the question to the user.
*
* @return bool|mixed|string|null
* @return mixed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed includes everything in PHP 8. Using mixed|somethingElse as a return type is a fatal error.
Obviously, we are going to handle the case in the DebugClassLoader when a PHPDoc is "wrong".
But in our own codebase, we should be strict and clean about it, WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should be strict and clean. But could be be more specific?

mixed is the same as string|int|float|bool|null|array|object|callable|resource.

I know that Question::$default has mixed, but that is also wrong.

Is it reasonable to do anything else than bool|string|null|int|float?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not look at the code here. mixed is probably wrong indeed, that's another fix to do.

*
* @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function validate($form, Constraint $formConstraint)
/**
* Returns the validation groups of the given form.
*
* @return string|GroupSequence|(string|GroupSequence)[] The validation groups
* @return string|GroupSequence|array<string|GroupSequence> The validation groups
*/
private function getValidationGroups(FormInterface $form)
{
Expand Down Expand Up @@ -241,9 +241,9 @@ private function getValidationGroups(FormInterface $form)
/**
* Post-processes the validation groups option for a given form.
*
* @param string|GroupSequence|(string|GroupSequence)[]|callable $groups The validation groups
* @param string|GroupSequence|array<string|GroupSequence>|callable $groups The validation groups
*
* @return GroupSequence|(string|GroupSequence)[] The validation groups
* @return GroupSequence|array<string|GroupSequence> The validation groups
*/
private static function resolveValidationGroups($groups, FormInterface $form)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/HeaderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function hasCacheControlDirective($key)
*
* @param string $key The directive name
*
* @return mixed|null The directive value if defined, null otherwise
* @return mixed The directive value if defined, null otherwise
*/
public function getCacheControlDirective($key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class EnvelopeListener implements EventSubscriberInterface
private $recipients;

/**
* @param Address|string $sender
* @param (Address|string)[] $recipients
* @param Address|string $sender
* @param array<Address|string> $recipients
*/
public function __construct($sender = null, array $recipients = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function getReceiverName(): string
}

/**
* @return mixed|null
* @return mixed
*/
protected function getMessageId(Envelope $envelope)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function create($address): self
}

/**
* @param (Address|string)[] $addresses
* @param array<Address|string> $addresses
*
* @return Address[]
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Header/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getMaxLineLength(): int
}

/**
* @param (Address|string)[] $addresses
* @param array<Address|string> $addresses
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class FormDataPart extends AbstractMultipartPart
private $fields = [];

/**
* @param (string|array|DataPart)[] $fields
* @param array<string|array|DataPart> $fields
*/
public function __construct(array $fields = [])
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Process/Process.php
F438
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Process implements \IteratorAggregate
* @param array $command The command to run and its arguments listed as separate entries
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
* @param mixed $input The input as stream resource, scalar or \Traversable, or null for no input
* @param int|float|null $timeout The timeout in seconds or null to disable
*
* @throws LogicException When proc_open is not installed
Expand Down Expand Up @@ -183,7 +183,7 @@ public function __construct($command, string $cwd = null, array $env = null, $in
* @param string $command The command line to pass to the shell of the OS
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
* @param mixed $input The input as stream resource, scalar or \Traversable, or null for no input
* @param int|float|null $timeout The timeout in seconds or null to disable
*
* @return static
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private function parseDefaultsConfig(\DOMElement $element, string $path)
/**
* Recursively parses the value of a "default" element.
*
* @return array|bool|float|int|string The parsed value
* @return array|bool|float|int|string|null The parsed value
*
* @throws \InvalidArgumentException when the XML is invalid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface UserInterface
* and populated in any number of different ways when the user object
* is created.
*
* @return (Role|string)[] The user roles
* @return array<Role|string> The user roles
*/
public function getRoles();

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Serializer/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
private $normalizerCache = [];

/**
* @param (NormalizerInterface|DenormalizerInterface)[] $normalizers
* @param (EncoderInterface|DecoderInterface)[] $encoders
* @param array<NormalizerInterface|DenormalizerInterface> $normalizers
* @param array<EncoderInterface|DecoderInterface> $encoders
*/
public function __construct(array $normalizers = [], array $encoders = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function atPath($path);
* If no constraint is passed, the constraint
* {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
*
* @param mixed $value The value to validate
* @param Constraint|Constraint[] $constraints The constraint(s) to validate against
* @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
* @param mixed $value The value to validate
* @param Constraint|Constraint[] $constraints The constraint(s) to validate against
* @param string|GroupSequence|array<string|GroupSequence>|null $groups The validation groups to validate. If none is given, "Default" is assumed
*
* @return $this
*/
Expand All @@ -52,9 +52,9 @@ public function validate($value, $constraints = null, $groups = null);
* Validates a property of an object against the constraints specified
* for this property.
*
* @param object $object The object
* @param string $propertyName The name of the validated property
* @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
* @param object $object The object
* @param string $propertyName The name of the validated property
* @param string|GroupSequence|array<string|GroupSequence>|null $groups The validation groups to validate. If none is given, "Default" is assumed
*
* @return $this
*/
Expand All @@ -64,10 +64,10 @@ public function validateProperty($object, $propertyName, $groups = null);
* Validates a value against the constraints specified for an object's
* property.
*
* @param object|string $objectOrClass The object or its class name
* @param string $propertyName The name of the property
* @param mixed $value The value to validate against the property's constraints
* @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
* @param object|string $objectOrClass The object or its class name
* @param string $propertyName The name of the property
* @param mixed $value The value to validate against the property's constraints
* @param string|GroupSequence|array<string|GroupSequence>|null $groups The validation groups to validate. If none is given, "Default" is assumed
*
* @return $this
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ public function getViolations()
/**
* Normalizes the given group or list of groups to an array.
*
* @param string|GroupSequence|(string|GroupSequence)[] $groups The groups to normalize
* @param string|GroupSequence|array<string|GroupSequence> $groups The groups to normalize
*
* @return (string|GroupSequence)[] A group array
* @return array<string|GroupSequence> A group array
*/
protected function normalizeGroups($groups)
{
Expand Down
20 changes: 10 additions & 10 deletions src/Symfony/Component/Validator/Validator/ValidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ interface ValidatorInterface extends MetadataFactoryInterface
* If no constraint is passed, the constraint
* {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
*
* @param mixed $value The value to validate
* @param Constraint|Constraint[] $constraints The constraint(s) to validate against
* @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
* @param mixed $value The value to validate
* @param Constraint|Constraint[] $constraints The constraint(s) to validate against
* @param string|GroupSequence|array<string|GroupSequence>|null $groups The validation groups to validate. If none is given, "Default" is assumed
*
* @return ConstraintViolationListInterface A list of constraint violations
* If the list is empty, validation
Expand All @@ -44,9 +44,9 @@ public function validate($value, $constraints = null, $groups = null);
* Validates a property of an object against the constraints specified
* for this property.
*
* @param object $object The object
* @param string $propertyName The name of the validated property
* @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
* @param object $object The object
* @param string $propertyName The name of the validated property
* @param string|GroupSequence|array<string|GroupSequence>|null $groups The validation groups to validate. If none is given, "Default" is assumed
*
* @return ConstraintViolationListInterface A list of constraint violations
* If the list is empty, validation
Expand All @@ -58,10 +58,10 @@ public function validateProperty($object, $propertyName, $groups = null);
* Validates a value against the constraints specified for an object's
* property.
*
* @param object|string $objectOrClass The object or its class name
* @param string $propertyName The name of the property
* @param mixed $value The value to validate against the property's constraints
* @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
* @param object|string $objectOrClass The object or its class name
* @param string $propertyName The name of the property
* @param mixed $value The value to validate against the property's constraints
* @param string|GroupSequence|array<string|GroupSequence>|null $groups The validation groups to validate. If none is given, "Default" is assumed
*
* @return ConstraintViolationListInterface A list of constraint violations
* If the list is empty, validation
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Contracts/HttpClient/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public function cancel(): void;
* - response_headers (array) - an array modelled after the special $http_response_header variable
* - start_time (float) - the time when the request was sent or 0.0 when it's pending
* - url (string) - the last effective URL of the request
* - user_data (mixed|null) - the value of the "user_data" request option, null if not set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep all mixed|null when null is documented with a special behavior

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. but null is included in mixed. I dont think mixed|null make sense. However, I would be very happy to see a more specific definition. Im sure this mixed will not include any callable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yes, callable is a very valid type here - this is really mixed.
mixed contains null, but here we're not describing types for the engine, but types for humans, and documenting that null means something special is valuable I believe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using just mixed is fine for me. The null case is documented in the description anyway.

* - user_data (mixed) - the value of the "user_data" request option, null if not set
*
* When the "capture_peer_cert_chain" option is true, the "peer_certificate_chain"
* attribute SHOULD list the peer certificates as an array of OpenSSL X.509 resources.
*
* Other info SHOULD be named after curl_getinfo()'s associative return value.
*
* @return array|mixed|null An array of all available info, or one of them when $type is
* provided, or null when an unsupported type is requested
* @return array|mixed An array of all available info, or one of them when $type is
* provided, or null when an unsupported type is requested
*/
public function getInfo(string $type = null);
}
0