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

DX: Reduce usage of PhpCsFixer\DocBlock\Line::__toString #4098

Closed
wants to merge 1 commit into from
Closed

DX: Reduce usage of PhpCsFixer\DocBlock\Line::__toString #4098

wants to merge 1 commit into from

Conversation

kubawerlos
Copy link
Contributor

No description provided.

@@ -42,6 +42,8 @@ public function __construct($content)
* Get the string representation of object.
*
* @return string
*
* @deprecated will be removed in 3.0, use getContent
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the method make a @trigger_error('...', E_USER_DEPRECATION) call?

Copy link
Contributor

Choose a reason for hiding this comment

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

risky, because a lot of IDE's call this method to show preview data when debugging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't @ make it transparent for IDEs?

Copy link
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

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

Please, provide reasoning why to deprecate this in first place.

@kubawerlos
Copy link
Contributor Author

Anyway, the magic is heavily used - in DocBlock and Annotation classes as well - should we get rid of all the __toString functions and replace:

implode('', $lines);

with:

implode(
    '',
    array_map(
        function (Line $line) {
            return $line->getContent();
        },
        $lines
    )
);

?

@kubawerlos
Copy link
Contributor Author

Please, provide reasoning why to deprecate this in first place.

@keradus not sure not now, initially was to simply avoid magic method.

@keradus keradus changed the title Deprecate PhpCsFixer\DocBlock\Line::__toString DX: Reduce usage of PhpCsFixer\DocBlock\Line::__toString Dec 28, 2018
@keradus
Copy link
Member

keradus commented Dec 28, 2018

  1. no reasoning is indicator to not pursuit the idea
  2. lack of @trigger_error is an issue, especially, as you noticed yourself, we reduce usage of that magic method, but not get rid of it
  3. I removed deprecation part of this PR and now, I will merge it as is - if we want to deprecate sth indeed, we need to have good reasoning for it, deprecation notification in place and stop using deprecated code in our codebase.

@keradus
Copy link
Member

keradus commented Dec 28, 2018

Already applied in #4088

@keradus keradus closed this Dec 28, 2018
@keradus keradus removed this from the 2.14.0 milestone Dec 28, 2018
@keradus
Copy link
Member

keradus commented Dec 28, 2018

note:
i'm not for using magic methods everywhere, but we may use them sometimes.

If you want to get rid of them, please deprecate them (with real deprecation notice) everywhere, in all PhpCsFixer\DocBlock\* and AllowedValueSubset (the __invoke)

@SpacePossum
Copy link
Contributor

  1. no reasoning is indicator to not pursuit the idea

I would like to note that using __toString() comes with some drawbacks which is why I never use it:
1 - finding "usages" is near impossible, because;
2 - it allows for implicit string casting of an object
3 - it is not a descriptive method name
4 - it is invalid to throw exceptions from the method, which makes it more limited than any regular method for no reason

Magic methods like __invoke and __isset have a far better defined role and definition and besides being magic have nothing in common with __toString.

I'm fine with not merging though as it might not be worth adding this BC break now :)

@kubawerlos
Copy link
Contributor Author

I forget to close it, I've checked and it would not be that easy to remove the magic methods.

@kubawerlos kubawerlos deleted the feature/deprecate-line-to-string branch December 28, 2018 14:29
@keradus
Copy link
Member

keradus commented Dec 28, 2018

not sure not now, initially was to simply avoid magic method.

no reasoning is indicator to not pursuit the idea

just saying that change for a change is not a reason, it has to have background

as said later, i'm not negative for such change, but it has to be applied fully

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

4 participants