Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Add type-hints #32271

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

Closed
wants to merge 1 commit into from

Conversation

julien57
Copy link

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #32179
License MIT
Doc PR

First commit to add type-hints to HttpFoundation

@@ -48,11 +48,11 @@ public function __construct(array $items)
*
* @return self
*/
public static function fromString($headerValue)
public static function fromString(string $headerValue)
Copy link
Member

Choose a reason for hiding this comment

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

@param can be removed from multiple docblocks.

src/Symfony/Component/HttpFoundation/Cookie.php Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
@nicolas-grekas nicolas-grekas added this to the 5.0 milestone Jun 30, 2019
@nicolas-grekas
Copy link
Member

@julien57ok to finish this one?

@xabbuh xabbuh force-pushed the httpfoundation-type-hints branch 2 times, most recently from 79fa925 to 36486a3 Compare July 26, 2019 19:36
@nicolas-grekas nicolas-grekas force-pushed the httpfoundation-type-hints branch from 36486a3 to e5c000b Compare August 8, 2019 17:54
@nicolas-grekas
Copy link
Member

I just push-forced on this PR, review welcome.

@nicolas-grekas nicolas-grekas force-pushed the httpfoundation-type-hints branch from 72eaa88 to 2181739 Compare August 8, 2019 18:25
}

$this->content = (string) $content;
$this->content = $content;
Copy link
Contributor

Choose a reason for hiding this comment

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

since $content is nullable, $this->content can also be null. this might break for people expecting string in getContent. so I guess we need to cast null to ''

Copy link
Contributor

Choose a reason for hiding this comment

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

there is actually a failing test due to this: https://travis-ci.org/symfony/symfony/jobs/569486612

@@ -209,11 +209,10 @@ public function __construct($content = '', int $status = 200, array $headers = [
*
* @param mixed $content The response content, see setContent()
Copy link
Contributor

Choose a reason for hiding this comment

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

outdated mixed param

{
if (null !== $content && !\is_string($content) && !is_numeric($content) && !\is_callable([$content, '__toString'])) {
throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', \gettype($content)));
Copy link
Contributor

Choose a reason for hiding this comment

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

fully agree as the casting should be done in user-land when they need strict types compatibility.

@@ -1586,8 +1553,6 @@ public function getPreferredFormat(?string $default = 'html'): ?string
/**
* Returns the preferred language.
*
* @param array $locales An array of ordered available locales
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should document this as @param string[] $locales. otherwise the return type would also not work.

* @return string|null The format (null if not found)
*/
public function getFormat($mimeType)
public function getFormat(?string $mimeType)
Copy link
Contributor

Choose a reason for hiding this comment

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

making this nullable seems strange. I don't see the use-case for this.

* @return $this
*
* @throws \InvalidArgumentException
*/
public function setTargetUrl($url)
public function setTargetUrl(string $url)
{
if ('' === ($url ?? '')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the code suggests $url can be null, but it's not nullable at the moment.

* @return \DateTime|null The parsed DateTime or the default value if the header does not exist
*
* @throws \RuntimeException When the HTTP header is not parseable
*/
public function getDate($key, \DateTime $default = null)
public function getDate(string $key, \DateTime $default = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably change \DateTime to \DateTimeInterface and adjust the return phpdoc as well. but that could be a separate PR.

* @return $this
*/
public function setAttribute($name, $value)
public function setAttribute(string $name, string $value)
Copy link
Contributor

Choose a reason for hiding this comment

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

there is still a (string) $value cast left in the implementation

@nicolas-grekas
Copy link
Member

Continued in #33088, thanks @julien57

nicolas-grekas added a commit that referenced this pull request Aug 11, 2019
This PR was merged into the 5.0-dev branch.

Discussion
----------

[HttpFoundation] Add type-hints

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32179
| License       | MIT

replace #32271

Commits
-------

ead419b add type-hints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.