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

Add scalar typehints/return types #23262

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 2 commits into from
Sep 3, 2017
Merged

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Jun 22, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no (final, already breaks if doc not respected)
Deprecations? no
Tests pass? yes
Fixed tickets #23242 (comment)
License MIT
Doc PR n/a

@@ -65,7 +65,7 @@ public function load($path, ...$paths)
*
* @param array $values An array of env variables
Copy link
Contributor

Choose a reason for hiding this comment

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

phpdoc maybe also requires update

Copy link
Member Author

@chalasr chalasr Jun 22, 2017

Choose a reason for hiding this comment

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

in fact the type should be array, no need for supporting Traversable. fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

imo it would be better to have iterable

Copy link
Contributor

Choose a reason for hiding this comment

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

If PHP7.1, then iterable is a solution. But it depends, If you really want an array, it's not the same as requiring an iterable. For example, if you need to count the content, you can't rely on Traversable. So it really depends on the situation

@chalasr chalasr force-pushed the dotenv4-typehints branch from 54b8f7b to 779c38c Compare June 22, 2017 10:47
@@ -45,7 +45,7 @@
* @throws FormatException when a file has a syntax error
* @throws PathException when a file does not exist or is not readable
*/
public function load($path, ...$paths)
public function load($path, string ...$paths): void
Copy link
Contributor

Choose a reason for hiding this comment

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

why not string on the required argument ?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -65,7 +65,7 @@ public function load($path, ...$paths)
*
* @param array $values An array of env variables
Copy link
Contributor

Choose a reason for hiding this comment

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

imo it would be better to have iterable

@chalasr chalasr force-pushed the dotenv4-typehints branch from 779c38c to 9cac16d Compare June 22, 2017 22:33
@@ -88,7 +88,7 @@ public function populate($values)
*
* @throws FormatException when a file has a syntax error
*/
public function parse($data, $path = '.env')
public function parse(string $data, string $path = '.env')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add the return type here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@chalasr chalasr force-pushed the dotenv4-typehints branch from 9cac16d to 115928f Compare June 23, 2017 12:29
@fabpot
Copy link
Member

fabpot commented Jun 23, 2017

What about other similar cases in the code base. I don't see why we should make the change here and not for similar use cases.

@stof
Copy link
Member

stof commented Jun 23, 2017

@fabpot this component is easy to change, because everything is final.

For other components, we could start using them in constructors, but mostly nothing else (returns types could be added later, once we have PHP 7.2 as min requirement)

@chalasr chalasr force-pushed the dotenv4-typehints branch from 4fe13fd to b2c916f Compare June 23, 2017 16:29
@chalasr
Copy link
Member Author

chalasr commented Jun 23, 2017

@fabpot @stof I found a few cases where making the change is as easy (final, no contract, no parent). See b2c916f.

@xabbuh
Copy link
Member

xabbuh commented Jun 26, 2017

Internal class and methods could be easy to update to (see https://github.com/symfony/symfony/compare/master...xabbuh:yaml-scalar-type-hints?expand=1 for how this could look like in the Yaml component).

@fabpot
Copy link
Member

fabpot commented Jul 3, 2017

I like @xabbuh changes. @chalasr Do you have time to make those changes across the board when possible without BC breaks.

@chalasr chalasr changed the title [Dotenv] Add scalar typehints/return types Add scalar typehints/return types Jul 3, 2017
@nicolas-grekas nicolas-grekas added this to the 4.0 milestone Jul 3, 2017
@chalasr
Copy link
Member Author

chalasr commented Jul 3, 2017

Sure.
Status: needs work

@xabbuh
Copy link
Member

xabbuh commented Jul 3, 2017

private methods could be candidates too

@chalasr chalasr force-pushed the dotenv4-typehints branch 7 times, most recently from 5717ecb to d2b8d38 Compare July 8, 2017 14:44
@@ -178,9 +178,8 @@ private function doParse($value, $flags)
$context = 'mapping';

// force correct settings
Inline::parse(null, $flags, $this->refs);
Inline::initialize($flags, $this->getRealCurrentLineNb());
Copy link
Contributor

Choose a reason for hiding this comment

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

getRealCurrentLineNb is also marked as internal. Why not add return type there?

@Tobion
Copy link
Contributor

Tobion commented Aug 5, 2017

👍 To do this.

@mnapoli
Copy link
Contributor

mnapoli commented Aug 5, 2017

As it is now there are still a lot of useful comments (in the phpdoc) that are removed in this PR, it might be better to preserve all comments that bring additional information?

@chalasr
Copy link
Member Author

chalasr commented Aug 6, 2017

@mnapoli I tried to remove comments only where naming+typehints are clear enough. For instance, FirewallConfig methods returning ?string were documented as @return string|null The firewall's xxx if configured, null otherwise. The class name says that these values are parsed configuration, the return type says it can be null. Wouldn't the comment be redundant? I think so.

There are not that much removed comments actually, would you mind commenting on the ones that should be kept to you?

Copy link
Contributor

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

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

@chalasr OK I've reviewed the diff and "a lot" was probably exaggerated sorry ^^

The FirewallConfig class was the main problem I had, but it seems it's obvious that everything is a service ID there so maybe all those docblocks are not so useful indeed. In the end when you ignore that class there are just a few spots that I've noted as questions (also the @throws that were removed might be worth preserving).

@@ -128,16 +121,7 @@ private function parseSelectorList(TokenStream $stream)
return $selectors;
}

/**
* Parses next selector or combined node.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment might be useful? (I don't know the class so might be wrong)

The same applies to the other methods of that class, but if it's expected that all methods parse the "next […]" then feel free to ignore my comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, applies to all methods

*
* @return Extension\ExtensionInterface
*
* @throws ExpressionErrorException
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the @throws be kept?

*
* @return XPathExpr
*
* @throws ExpressionErrorException
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here?

*
* @return XPathExpr
*
* @throws ExpressionErrorException
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here?

Copy link
Member Author

Choose a reason for hiding this comment

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

@throws annotations re-added

@@ -33,6 +33,18 @@ class Inline
private static $objectForMap = false;
private static $constantSupport = false;

public static function initialize(int $flags, int $parsedLineNumber = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this new method intended?

Copy link
Member

Choose a reason for hiding this comment

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

The idea was to not have to accept null values in Inline::parse(). But I have moved it to its own PR: #24060

$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
}

return sprintf('{ %s }', implode(', ', $output));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this code change intended in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

ping @xabbuh

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this part is handling the dumping of objects as YAML mappings and thus allows us to type hint the $value argument in dumpArray() with array.

@chalasr chalasr force-pushed the dotenv4-typehints branch from 97c227c to 9e46910 Compare August 7, 2017 08:15
@xabbuh xabbuh force-pushed the dotenv4-typehints branch 3 times, most recently from fa7c35b to a7e1656 Compare August 29, 2017 20:48
xabbuh added a commit that referenced this pull request Aug 30, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[Yaml] mark some classes as final

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Making these classes final unlocks more scalar type hint possibilities on top of the changes proposed in #23262.

Commits
-------

330c6bf [Yaml] mark some classes as final
@xabbuh xabbuh force-pushed the dotenv4-typehints branch from a7e1656 to a9401a1 Compare August 31, 2017 09:38
@chalasr chalasr force-pushed the dotenv4-typehints branch from a9401a1 to e02137b Compare August 31, 2017 20:46
@chalasr
Copy link
Member Author

chalasr commented Aug 31, 2017

Updated by @xabbuh next to #24028 to add some more typehints, his changes look good to me.
PR ready.

@fabpot
Copy link
Member

fabpot commented Sep 3, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 7b1715b into symfony:master Sep 3, 2017
fabpot added a commit that referenced this pull request Sep 3, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

Add scalar typehints/return types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (final, already breaks if doc not respected)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23242 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

7b1715b [Yaml] use scalar type hints where possible
6ce70e4 Add scalar typehints/return types on final/internal/private code
@chalasr chalasr deleted the dotenv4-typehints branch September 3, 2017 16:18
fabpot added a commit that referenced this pull request Sep 6, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[Yaml] add inline parser context initializer

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23262 (comment)
| License       | MIT
| Doc PR        |

Calling the parser to initialize some internal context does not look
like a good idea. Additionally, this change allows to not accept null
values in `Inline::parse()` in 3.4 anymore.

Commits
-------

1be23c2 [Yaml] add inline parser context initializer
@fabpot fabpot mentioned this pull request Oct 19, 2017
fabpot added a commit that referenced this pull request Oct 26, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

[Intl] Allow passing null as a locale fallback

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

[`Null` is passed in `update-data.php`](https://github.com/symfony/symfony/blob/e2b4a35a720b85173d15055d0554f86602d43593/src/Symfony/Component/Intl/Resources/bin/update-data.php#L209) to prevent falling back to English locale during icu data import. It's been always possible, but since it hasn't been documented in the docblock it was missed while merging #23262.

Commits
-------

e2b4a35 [Intl] Allow passing null as a locale fallback
@derrabus derrabus mentioned this pull request Jun 25, 2019
57 tasks
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.

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