Skip to content
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

Allow EntityGenerator to create PHP7 compliant methods #5569

Closed
wants to merge 6 commits into from
Closed

Allow EntityGenerator to create PHP7 compliant methods #5569

wants to merge 6 commits into from

Conversation

jdecool
Copy link

@jdecool jdecool commented Dec 20, 2015

PHP files are in weak type-checking mode. Since PHP 7, strict type-checking mode is used for function calls and return statements in the the file.

This PR add support for generate class with are strict_types compliant.

@Majkl578
Copy link
Contributor

How is strict mode related to return/parameter types? Those are two totally separate things.

@jdecool
Copy link
Author

jdecool commented Dec 20, 2015

This PR covers methods return strict mode and scalar type hinting.

@@ -1380,15 +1432,26 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type,
$methodTypeHint = '\\' . $typeHint . ' ';
}

$methodReturnType = null;
if ($this->strictTypes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for not being specific - meant to add a comment to this line. This seems you are mixing two things.
By strict types, we refer to declare(strict_types=<value>), but absence of this declaration does not imply absence of return types. It's perfectly ok to have return types but no strict declaration (thus having weak types).

Copy link
Author

Choose a reason for hiding this comment

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

I understand.

Is it ok if I add a specific option for 'strict_types' and another one for return types and scalar type hinting ?

Or only an option for return types and forget strict_types mode declaration.

Copy link

Choose a reason for hiding this comment

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

+1 for two options, one for strict types and another one for return types/scalar type hint

@jdecool jdecool changed the title Allow EntityGenerator to create PHP7 strict_types compliant method Allow EntityGenerator to create PHP7 compliant methods Dec 21, 2015
@jdecool
Copy link
Author

jdecool commented Dec 21, 2015

I just pushed 2 commits to create 2 options $strictTypes and $generateMethodsTypeHinting.

@ferodss
Copy link

ferodss commented Dec 22, 2015

This way seems better, I'm not ok of assuming the return types but it's not a problem 👍

@yokomizor
Copy link

👍

1 similar comment
@ghost
Copy link

ghost commented Jan 5, 2016

👍

*/
public function setStrictTypes($bool)
{
if ($bool && version_compare(PHP_VERSION, '7.0.0', '<')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any use-cases where people might need to generate the source from a different machine (possibly with a different PHP version) than where they plan to use it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, of course, developers often use diferent versions... :)

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @DHager: this block isn't needed.

@jdecool
Copy link
Author

jdecool commented Feb 27, 2016

I just push code improvement with your feedbacks.

@binarious
Copy link

What's the state of this PR? Is anything missing? Do you need help, @jdecool?

@jdecool
Copy link
Author

jdecool commented Sep 6, 2017

I need to add some PHP 7.1 features and rebase the branch (to fix conflicts).

I unfortunately remove the fork in my account.
So I will submit a new PR.

I'll make it this week.

@Ocramius
Copy link
Member

Ocramius commented Sep 6, 2017

@jdecool you can fetch this branch by adding fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to your .git/config file

@Ocramius
Copy link
Member

Ocramius commented Sep 6, 2017

or also just git fetch origin/pr/*

@jdecool
Copy link
Author

jdecool commented Sep 6, 2017

Thanks @Ocramius

I will update this PR quickly

@jdecool
Copy link
Author

jdecool commented Sep 6, 2017

I just retrieve this PR in a new fork and rebase the branch.
But I can update this PR.

@Ocramius Do you know if it's possible ? Or do I need to create a new PR ?

@jdecool
Copy link
Author

jdecool commented Sep 17, 2017

I would like to finish my work on this PR.

But does somebody know how can I push my "new fork" which is based on this PR without recreate a new PR ?

@Majkl578
Copy link
Contributor

@jdecool I'm afraid you can't, when you deleted your old fork, GitHub lost reference to it. :/ You'll have to create new PR unfortunately.

@jdecool
Copy link
Author

jdecool commented Sep 17, 2017

Ok @Majkl578 Thanks for your answer.

I will recreate a new PR tomorrow.

Thanks.

@jdecool
Copy link
Author

jdecool commented Nov 20, 2017

Because I can't work on this PR anymore due to the deletion of the initial fork, I've recreate a new PR #6832.

Sorry for the duplicate.

@jdecool jdecool closed this Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants