Skip to content

Conversation

@verfriemelt-dot-org
Copy link
Contributor

this should fix phpstan/phpstan#8442
seems to be a simple fix, not sure if i done everything correct.

Copy link
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

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

the snippet from phpstan/phpstan#8442 should be added to this PR as a NodeScopeResolverTest including proper assertType calls

@verfriemelt-dot-org
Copy link
Contributor Author

i will look into this! 👍

@verfriemelt-dot-org verfriemelt-dot-org force-pushed the bugfix/8442-wrong-return-type branch 2 times, most recently from 7b4b767 to 2095c78 Compare December 12, 2022 09:36
@verfriemelt-dot-org verfriemelt-dot-org force-pushed the bugfix/8442-wrong-return-type branch from 45062c1 to 330a2f5 Compare December 12, 2022 17:18
@verfriemelt-dot-org verfriemelt-dot-org force-pushed the bugfix/8442-wrong-return-type branch from b00058d to 56c47c2 Compare December 14, 2022 07:14
@staabm
Copy link
Contributor

staabm commented Dec 14, 2022

Would be great if you could adjust other similar existing extensions which also miss the getConstantStrings() handling, after this one was merged

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Also - you have some random spaces in there that I don't like but CS isn't picking up them as errors. Please get rid of them.

Like: if ( count or $strings[0 ].

Copy link
Member

Choose a reason for hiding this comment

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

This code will crash if someone has DateInterval::createFromDateString() without an argument in their code.

Copy link
Contributor Author

@verfriemelt-dot-org verfriemelt-dot-org Dec 15, 2022

Choose a reason for hiding this comment

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

true, fixed that. but it leaves me wondering, what to return when this case is found?

		$arguments = $methodCall->getArgs();

		if (!isset($arguments[0])) {
			return null;
		}

i opted for the default type but running code like this with warnings supressed does not execute at all. so what would be the correct thing to do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i opted for this:

	assertType('DateInterval|false',DateInterval::createFromDateString());
	assertType('DateInterval|false',DateInterval::createFromDateString(new stdClass()));

@verfriemelt-dot-org
Copy link
Contributor Author

Also - you have some random spaces in there that I don't like but CS isn't picking up them as errors. Please get rid of them.

Like: if ( count or $strings[0 ].

intresting, make cs-fix will not clean this up 🤔 i fixed them by hand :)

@verfriemelt-dot-org verfriemelt-dot-org force-pushed the bugfix/8442-wrong-return-type branch from 5d52f9d to 295a93d Compare December 17, 2022 21:56
@ondrejmirtes ondrejmirtes merged commit 97efd4d into phpstan:1.9.x Dec 30, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@verfriemelt-dot-org verfriemelt-dot-org deleted the bugfix/8442-wrong-return-type branch December 30, 2022 23:08
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.

wrong return type for DateIntervall::createFromDateString()

4 participants