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

[Parameter] Deprecate names starting or ending with a colon #6880

Closed

Conversation

fancyweb
Copy link

@fancyweb fancyweb commented Dec 12, 2017

As requested by @Majkl578 in #5996

I wasn't able to make a test as I don't know how to test a deprecation message without the @expectedDeprecation annotation of the Symfony PHPUnit Bridge ^^

@Ocramius
Copy link
Member

Requires a test case

@fancyweb
Copy link
Author

@Ocramius As I said in my comment I need help for this test.

@coudenysj
Copy link
Contributor

@fancyweb Just construct the class with a faulty string, and watch what happens.

By default, PHPUnit will install an error handler that converts the following errors to exceptions: https://phpunit.de/manual/current/en/appendixes.configuration.html

@fancyweb
Copy link
Author

I tried that and it was just marked as a risky test since there was no assertion. No exception was thrown.

@coudenysj
Copy link
Contributor

Probably because you use the @ operator, I'll try to checkout your branch and have a look.

@Majkl578
Copy link
Contributor

Please wait until #6869 is merged (after 2.6 is released), it will add the infrastructure for testing deprecations.

@lcobucci
Copy link
Member

Just missing the test so I'll keep on 2.7.0 and we can easily test it with things added in #7901

@lcobucci
Copy link
Member

@fancyweb thanks, I've updated things to add the test. I'm just struggling on explaining the value of this deprecation in UPGRADING.md. I'll move this 2.8.0 so we have enough time to discuss this 👍

@lcobucci lcobucci modified the milestones: 2.7.0, 2.8.0 Nov 16, 2019
@SenseException
Copy link
Member

Thanks for adding the tests.

I'm just struggling on explaining the value of this deprecation in UPGRADING.md

Maybe describe it as a clear information about how a parameter has to look like and being less ambiguous?

@lcobucci
Copy link
Member

lcobucci commented Nov 20, 2019

@SenseException focusing on the ambiguity is a good idea. I guess what made me hesitate too was doing the check using regex. We could do the trim and then compare with the original value, sending the deprecation notice when they are different.

@@ -67,6 +69,10 @@ class Parameter
*/
public function __construct($name, $value, $type = null)
{
if (preg_match('/^:|:$/', $name)) {
@trigger_error('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

Let's add the package name and use some linebreaks:

Suggested change
@trigger_error('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0', E_USER_DEPRECATED);
@trigger_error(
'Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0',
E_USER_DEPRECATED
);

*/
public function deprecationMustBeTriggeredWhenUsingColonInParameterNames() : void
{
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0');

Copy link
Member

Choose a reason for hiding this comment

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

It should be 2.8 too :)

$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
new Parameter(':user_name', 'Testing');

$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0');

$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
new Parameter('user_name:', 'Testing');

$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0');
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0');

@@ -67,6 +69,10 @@ class Parameter
*/
public function __construct($name, $value, $type = null)
{
if (preg_match('/^:|:$/', $name)) {
Copy link
Member

Choose a reason for hiding this comment

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

As @lcobucci wrote:

We could do the trim and then compare with the original value, sending the deprecation notice when they are different.

@lcobucci lcobucci changed the base branch from 2.7 to 2.8.x November 29, 2019 10:31
@beberlei beberlei modified the milestones: 2.8.0, 2.8.1, 2.8.2 Dec 4, 2020
@beberlei beberlei removed this from the 2.8.2 milestone Dec 13, 2020
@derrabus derrabus changed the base branch from 2.8.x to 2.13.x May 11, 2022 10:01
@derrabus
Copy link
Member

Can we pick this up for 2.13?

@fancyweb fancyweb closed this Oct 19, 2023
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.

None yet

9 participants