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

NoUnsetOnPropertyFixer breaks on function call as key in array class-property #3843

Closed
dmvdbrugge opened this issue Jun 28, 2018 · 8 comments
Labels

Comments

@dmvdbrugge
Copy link
Contributor

The PHP version you are using ($ php -v):

PHP 7.1.18 (cli) (built: May 25 2018 19:18:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.18, Copyright (c) 1999-2018, by Zend Technologies

PHP CS Fixer version you are using ($ php-cs-fixer -V):

PHP CS Fixer 2.12.1 Long Journey by Fabien Potencier and Dariusz Ruminski

The command you use to run PHP CS Fixer:

vendor/bin/php-cs-fixer fix --rules=no_unset_on_property filename.php

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
unset($this->profile->getSettings()[Settings::RANDOM_SETTING]);
  • with unexpected changes applied when running PHP CS Fixer:
    Linting error after fixing

  • with the changes you expected instead:
    None, it shouldn't have changed it.

The getSettings() call returns a magic subclass of ArrayObject, however the fixer thinks it's a property. I know it's ugly syntax but it's used all over the place because $this->profile->settings was changed to protected, and all occurrences were replaced with the getter (because lazy loading).

@keradus
Copy link
Member

keradus commented Jun 28, 2018

@SpacePossum , can you take a look ?

@SpacePossum
Copy link
Contributor

I might but let me ping the author of the fixer as well @BackEndTea ;)

@BackEndTea
Copy link
Contributor

I'll take a look either later today or tomorrow

@BackEndTea
Copy link
Contributor

I created a test case for

unset($this->profile->getSettings()[Settings::RANDOM_SETTING]);

But it does not get changed by the fixer. Is there any other place in the file that uses an unset which might cause thsi bug?

@dmvdbrugge
Copy link
Contributor Author

Before reporting the issue I tried disabling this fixer, and there is no problem. Re-enabling the fixer and commenting out this line, and again no problem.

It might conflict with other fixers or its surrounding code, which I will be able to test again tomorrow.

@dmvdbrugge
Copy link
Contributor Author

So yeah... different line now, don't know if inconsistent or just my bad 😨
Validated with -vvv --diff --using-cache=no in addition to the original command

It changes

unset($this->property[array_search(\Types::TYPE_RANDOM, $this->property)]);

To

unset($this->property[array_search(\Types::TYPE_RANDOM); $this->property)] = null;

@dmvdbrugge dmvdbrugge changed the title NoUnsetOnPropertyFixer breaks on method calls NoUnsetOnPropertyFixer breaks on function call as key in array class-property Jul 2, 2018
@BackEndTea
Copy link
Contributor

Ah i think i know what causes that,and how to fix it

@BackEndTea
Copy link
Contributor

Sorry for the delay on this, but i haven't had much time to work on it, and i'm kinda unsure on how to fix it atm.

So if someone wants to take a look, feel free to do so.

keradus added a commit that referenced this issue Dec 30, 2018
This PR was squashed before being merged into the 2.12 branch (closes #4022).

Discussion
----------

NoUnsetOnPropertyFixer - refactor and bugfixes

Replaces #4020
Fix #3843

Commits
-------

e43137a NoUnsetOnPropertyFixer - refactor and bugfixes
@keradus keradus closed this as completed Dec 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants