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

[POC] Add PHP 7.1 typehints + remove unused doc for @param and @return, #24930

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 7 commits into from
Closed

Conversation

TomasVotruba
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
License MIT

Follow up to #24722

@nicolas-grekas Let me know how this works for you.

@TomasVotruba
Copy link
Contributor Author

TomasVotruba commented Nov 12, 2017

Not sure how error on PHP 7.2 is related to this: https://travis-ci.org/symfony/symfony/jobs/300794715#L2491

Other 2 builds are passing

Any ideas?

@TomasVotruba TomasVotruba changed the title remove unused doc for @param and @return Add PHP 7.1 typehints + remove unused doc for @param and @return, Nov 12, 2017
@TomasVotruba
Copy link
Contributor Author

TomasVotruba commented Nov 12, 2017

Last few commits are mostly experimental to show what can be automated by coding standard tools when set up propperly.

Let me know what you prefer.

@@ -167,7 +167,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
/**
* Register all the collected mapping information with the object manager by registering the appropriate mapping drivers.
*
* @param ContainerBuilder $container A ContainerBuilder instance
* @param ContainerBuilder $container A ContainerBuilder instance
Copy link
Member

Choose a reason for hiding this comment

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

this one can be completely removed in fact :)

Copy link
Contributor Author

@TomasVotruba TomasVotruba Nov 12, 2017

Choose a reason for hiding this comment

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

Let's automate it :)

Remove all messages in format:

A "type" instance

What do you think?

@@ -79,7 +79,6 @@ public function getListeners(string $event = null): array
/**
* Checks whether an event has any registered listeners.
*
* @param string $event
Copy link
Member

Choose a reason for hiding this comment

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

this commit is interesting and related rule could be always enabled
but of course it should not build on the previous commits, which are BC breaking changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, just add Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDocBlockFixer

@@ -46,7 +46,7 @@ public function __construct(ContainerInterface $container)
*
* @return bool
*/
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
public function dispatchEvent(string $eventName, EventArgs $eventArgs = null)
Copy link
Member

Choose a reason for hiding this comment

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

this is interesting, unfortunately we won't be able to enable this rule, as this we must keep BC and we'll still maintain 5.5 code for some years to come (3.4 being merged into master)

Copy link
Contributor Author

@TomasVotruba TomasVotruba Nov 12, 2017

Choose a reason for hiding this comment

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

I see, this is resolved by external Sniff, but I can make it ignore this file.

@@ -44,7 +44,7 @@ public function isOptional()
/**
* {@inheritdoc}
*/
public function warmUp($cacheDir)
public function warmUp($cacheDir): void
Copy link
Member

Choose a reason for hiding this comment

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

I personally don't like "void": very low value (we don't add @return void for the same reason IMHO)
BC breaking change of course
and only my POV, so up for discussion of course :)

Copy link
Contributor

@ro0NL ro0NL Nov 12, 2017

Choose a reason for hiding this comment

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

in general 👍 for void; we imply mixed otherwise. So in terms of closing the gates, and to follow @stof 's comment, i agree with;

we should indeed add types whenever we can

so we can safely assume no type means mixed. But im not sure https://wiki.php.net/rfc/mixed-typehint changes our game.

Also <phhp7.2 we should keep @param/return object, as those can be replaced with typehints in 7.2 and we dont wanna imply mixed either.

Copy link

Choose a reason for hiding this comment

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

The "void" return type will help PHP to execute code faster. PHP 7.2 will have better code optimizer. Any type hint will reduce the amount of time to execute code since no need to detect type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Source? As far as I know, type hinting in PHP has negative performance impact. The aspect I personally don't like about void return type hint is that it will prevent subclasses from making fluent interfaces. Other than that, sure, it makes code more clear.

Choose a reason for hiding this comment

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

@@ -44,7 +44,7 @@ public function __construct(ManagerRegistry $registry)
/**
* Adds the stack logger for a connection.
*
* @param string $name
* @param string $name
Copy link
Member

Choose a reason for hiding this comment

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

php-cs-fixer already has a similar rule, isn't it?

@@ -45,7 +45,6 @@ public function __construct(ManagerRegistry $registry)
* Adds the stack logger for a connection.
*
* @param string $name
* @param DebugStack $logger
Copy link
Member

Choose a reason for hiding this comment

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

I like this rule :)

@nicolas-grekas
Copy link
Member

Some random comments added on a commit per commit basis.
Interesting work thank you!
Would be awesome if this could be merged into php-cs-fixer at some point!

@TomasVotruba
Copy link
Contributor Author

TomasVotruba commented Nov 12, 2017

Some random comments added on a commit per commit basis.

Thank you. I'll integrate them to the tool if possible.

Would be awesome if this could be merged into php-cs-fixer at some point!

@nicolas-grekas Well, anyone can port these two classes. But it requires PHP_CodeSniffer and like 20 related classes, so it makes sense me to not reinvent the wheel and use directly EasyCodingStandard.



Interesting work thank you!

I'll prepare smaller PRs, maybe per package?

@TomasVotruba TomasVotruba changed the title Add PHP 7.1 typehints + remove unused doc for @param and @return, [POC] Add PHP 7.1 typehints + remove unused doc for @param and @return, Nov 12, 2017
@nicolas-grekas
Copy link
Member

@TomasVotruba not per package, we always prefer per-topic and repo-wide;

@nicolas-grekas
Copy link
Member

Closing because this was a poc.

@TomasVotruba TomasVotruba deleted the cs-docs branch November 19, 2017 19:10
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.

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