Skip to content

Initial (minimal) implementation of PHPCSUtils#979

Merged
wimg merged 45 commits intodevelopfrom
feature/use-phpcsutils
Mar 26, 2020
Merged

Initial (minimal) implementation of PHPCSUtils#979
wimg merged 45 commits intodevelopfrom
feature/use-phpcsutils

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 26, 2020

This adds PHPCSUtils as a dependency for PHPCompatibility.

PHPCSUtils functions as an external standard for PHPCS, but doesn't have any sniffs. Instead it offers a wide-range of utility methods for PHPCS sniff developers to use. A number of these utility methods are inspired by and/or originally created for PHPCompatibility and have been moved.

All features in PHPCSUtils are cross-version compatible with PHP 5.4 - latest release and PHPCS 2.6.0 - latest release.

For more information about PHPCSUtils:


Now, as for this PR:

For every utility method in PHPCompatibility which has been moved to and/or moved & improved in PHPCSUtils, this PR does the following:

  • Deprecate the PHPCompatibility native utility function/class and start using the PHPCSUtils version under the hood in the PHPCompatibility native utility function.
  • Switch over all function calls within the sniffs to each of these functions to the PHPCSUtils version.
  • After that: remove the (deprecated) PHPCompatibility native utility function/class, as well as any directly associated unit tests.

I have verified at each of these stages that the build still passes.

Additionally, this PR switches over the remaining unit tests for utility functions in PHPCompatibility to the PHPCSUtils\TestUtils\UtilityMethodTestCase which significantly reduces the run time of the tests.

See the individual commits/commit messages for more detailed information.

Note: the current implementation is based on PHPCSUtils 1.0.0-alpha2. Additional removals can be expected once alpha-3 has been released.


What this PR does NOT do (but what should still be done before the next release):

  • Implement use of the new utility methods in PHPCSUtils which were already in PHPCompatibility. Separate PRs for all relevant sniffs will be send in for that once this PR has been merged.
  • Update the README and CONTRIBUTING information.
    Again, this will be addressed in a separate PR.
    Note: this change will not impact users installing PHPCompatibility via Composer. In that case, everything will still work as expected. The install instructions for users installing PHPCompatibility via a git clone or as a stand-alone project will change.

jrfnl and others added 30 commits March 26, 2020 19:46
For now, until PHPCSUtils 1.0.0 is tagged, we'll allow installation of alpha/beta/RC tags from PHPCSUtils.

This also changes the minimum PHPCS 3 requirement from `3.0.2` to `3.1.0`.

Includes:
* Removing DealerDirect Composer plugin suggestion.
    This dependency will now automatically be installed via PHPCSUtils.
* Removing the `post-install/update-cmd` scripts.
    The DealerDirect Composer plugin will now automatically take care of that.
* Try and find & load the PHPCSUtils `autoload.php` file.

Note: not removing the PHPUnit class alias setting for the `TestCase` class yet. While PHPCSUtils provided this as well, we also need it for test files which are independent of PHPCSUtils, so we should not rely on PHPCSUtils for this indiscriminately.
As everything here is now contained within PHPCSUtils, including updated and/or improved versions of some of these.
These will be removed in a later commit. Doing this staged will allow for easier testing during the transition.
All of the methods contained herein are now provided via PHPCSUtils and all code has been switched over to use the PHPCSUtils versions of the methods instead.
jrfnl added 15 commits March 26, 2020 19:50
…version

This change is slightly more involved than the others, so committing separately to allow for easier review.
…stCase base class

This should give significantly faster results.

For a test run on my local machine, these are the results:
* Command: `phpunit --group utilityFunctions`
* Run with the previous commit checked-out: 2.57 min
* Run with this commit checked-out: 7.07 _seconds_.

A requirement for the `UtilityMethodTestCase::getTargetToken()` helper method is that the test markers in test case files for utility methods start with `/* test` - to allow to distinguish between test marker comments and comments which are part of the actual test case -.

To this end, the test markers in the remaining utility method test case files have been renamed.
wimg
wimg previously approved these changes Mar 26, 2020
@wimg wimg dismissed their stale review March 26, 2020 22:20

stupid mistake

@wimg wimg merged commit 350f228 into develop Mar 26, 2020
@wimg wimg deleted the feature/use-phpcsutils branch March 26, 2020 22:34
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.

2 participants