-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Conversation
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
54b8f7b
to
779c38c
Compare
@@ -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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
779c38c
to
9cac16d
Compare
@@ -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') |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
9cac16d
to
115928f
Compare
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. |
@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) |
4fe13fd
to
b2c916f
Compare
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). |
Sure. |
private methods could be candidates too |
5717ecb
to
d2b8d38
Compare
@@ -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()); |
There was a problem hiding this comment.
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?
👍 To do this. |
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? |
@mnapoli I tried to remove comments only where naming+typehints are clear enough. For instance, There are not that much removed comments actually, would you mind commenting on the ones that should be kept to you? |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @xabbuh
There was a problem hiding this comment.
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
.
97c227c
to
9e46910
Compare
fa7c35b
to
a7e1656
Compare
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
a7e1656
to
a9401a1
Compare
a9401a1
to
e02137b
Compare
e02137b
to
7b1715b
Compare
Thank you @chalasr. |
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
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
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