1. 30 Sep, 2022 2 commits
  2. 04 Sep, 2022 2 commits
  3. 29 Aug, 2022 2 commits
    • Juliette's avatar
      Merge pull request #340 from... · a7637509
      Juliette authored
      Merge pull request #340 from PHPCSStandards/controlstructures/getdeclarescopeopenclose-more-tests-and-handle-php-close-tag
      
      ControlStructures::getDeclareScopeOpenClose(): support closing the declare statement with PHP close tag
      a7637509
    • jrfnl's avatar
      ControlStructures::getDeclareScopeOpenClose(): support closing the declare... · dd5df13f
      jrfnl authored
      ControlStructures::getDeclareScopeOpenClose(): support closing the declare statement with PHP close tag
      
      ... and also add tests to confirm that "multi-directive" statements are handled correctly.
      dd5df13f
  4. 28 Aug, 2022 2 commits
  5. 27 Aug, 2022 6 commits
  6. 30 Jun, 2022 18 commits
    • Juliette's avatar
      Merge pull request #332 from PHPCSStandards/feature/new-internal-cache-classes-with-implementations · b65fbd47
      Juliette authored
      New (internal) Cache and NoFileCache classes + implement use of these
      b65fbd47
    • jrfnl's avatar
      GH Actions: run the tests twice - once with cache, once without · ecfef72f
      jrfnl authored
      Adjust the GH actions test workflows to run the complete test suite once with the cache turned on and once with the cache turned off.
      
      The test run with caching turned on will run the tests twice and only run the tests which don't need isolation.
      This should safeguard that the cache does not negatively influence sniff results.
      
      The code coverage job will (should) run with caching turned _off_ to prevent tests not reaching all code paths due to cached results from previous tests short-circuiting things.
      
      Note: the effect of caching on the test suite will be minimal as most tests will only execute a function once for a particular input/code snippet. Still good to safeguard/double-check though.
      ecfef72f
    • jrfnl's avatar
      Tests/bootstrap: allow for running the tests with/without caching · 7f6443b9
      jrfnl authored
      This commit sets up a mechanism in the test `bootstrap.php` file to turn the cache on/off depending on an environment variable, which can be set from within a `phpunit.xml` file or on the OS-level.
      
      This allows for running the tests both with caching turned on, as well as with caching turned off.
      
      By default, the tests will run with caching turned **off**.
      
      Being able to run the tests with both settings will allow for:
      * [Caching off] Making sure that all code paths can be reached (code coverage check). Caching being enabled could prevent some code paths from being tested.
      * [Caching on] Making sure that caching does not (negatively) impact the actual results of the functions.
      7f6443b9
    • jrfnl's avatar
      TextStrings::getStripEmbeds(): implement use of the new `NoFileCache` class · ca495418
      jrfnl authored
      Depending on the size of the text string, this function _could_ become pretty slow/performance intense, which is why I'm implementing caching for it.
      
      Includes a dedicated test to verify the cache is used and working.
      ca495418
    • jrfnl's avatar
      Arrays::isShortArray()/Lists::isShortList(): implement use of the new `Cache` class · 56e15f34
      jrfnl authored
      These are easily the most used functions as well as the slowest functions (when dealing with large arrays/lists).
      
      While this commit already implements the use of the new `Cache` class, further improvements are still needed and will be pulled in a follow-up PR.
      
      Note: code coverage for these functions _may_ go down a little due to the multiple exit points in the functions. I'm not concerned about that as that - again - will be addressed in the follow-up PR.
      
      Includes a dedicated test to verify the cache is used and working.
      56e15f34
    • jrfnl's avatar
      Lists::getAssignments(): implement use of the new `Cache` class · 87170bc4
      jrfnl authored
      While most list only involve a few assignment, for more complex and nested list structures, splitting the list into the individual assignments can tax performance, which is why I'm implementing caching for it.
      
      Includes a dedicated test to verify the cache is used and working.
      87170bc4
    • jrfnl's avatar
      Arrays::getDoubleArrowPtr(): implement use of the new `Cache` class · 4397a873
      jrfnl authored
      While this function will generally be _fast_ for array entries _with_ a double arrow, it will be _slow_ for array entries without a double arrow, especially if the contents of the array item contains a lot of tokens as the fact that the array item does not have a double arrow can only be determined when the end of the array item has been reached.
      With this in mind, I'm implementing caching for it.
      
      Includes some minor tweaks to the exit routes of the function to ensure that the cache will always be set.
      
      Includes a dedicated test to verify the cache is used and working.
      4397a873
    • jrfnl's avatar
      UseStatements::splitImportUseStatement(): implement use of the new `Cache` class · 4f301b94
      jrfnl authored
      Depending on whether or not group use or multi-use statements are used, this method can involve sufficient token walking to make caching relevant.
      Especially when keeping in mind that this function will likely be used a **_lot_** in the near future as part of the namespace resolution functionality, so retrieving the results via the cache instead of executing the same logic dozens of times for a file, seem prudent.
      
      Includes a dedicated test to verify the cache is used and working.
      4f301b94
    • jrfnl's avatar
      TextStrings::getEndOfCompleteTextString(): implement use of the new `Cache` class · e5e87488
      jrfnl authored
      This method finds the end of a potentially multi-line text string.
      While most text strings are short and even multi-line ones are often only a few lines, some can be thousands of lines long.
      With that in mind, I'm implementing caching for this method.
      
      I've considered also applying caching for the `TextStrings::getCompleteTextString()` method, but as - in the case of thousands of lines long text - that would take a huge chunk of memory, I've decided against it.
      Caching the "end token" of a multi-line text string should sufficiently improve performance.
      
      Includes a dedicated test to verify the cache is used and working.
      e5e87488
    • jrfnl's avatar
      PassedParameters::getParameters(): implement use of the new `Cache` class · a27c2f8b
      jrfnl authored
      While most function calls only involve a few parameters, splitting out an array into the individual array items can be very processing intense and will slow things down considerably when multiple sniffs each need the break down of the same array.
      
      With this in mind, I'm implementing caching for it.
      
      The saved cache can be quite large for calls to this function, at the same time, the trade off performance-wise is worth it in this case IMO.
      
      Note: as this function can be called with a `$limit`, we need to be able to distinguish between "limited" results and "full" results, but should also take advantage of available "full" results when a consecutive function call tries to retrieve a "limited" result.
      
      The implementation takes this into account, though the situation where a "limited" result was previously retrieved (and cached), and new "limited" call is made with a _lower_ limit currently does not take full advantage of the available cache. This is possibly an improvement which can still be made in the future.
      
      Includes a set of dedicated tests to verify the cache is used and working, including testing specifically how the cache is set and used when the `$limit` parameter has been passed.
      a27c2f8b
    • jrfnl's avatar
      Namespaces::findNamespacePtr(): implement use of the new `Cache` class · 4924df8b
      jrfnl authored
      This method searches up in a file to try and find an applicable namespace declaration.
      As non-scoped namespace declarations are often at the top of the file, this can involve a **_lot_** of token walking, which is why I'm implementing caching for it.
      
      Includes some minor tweaks to the exit routes of the function to ensure that the cache will always be set when the token passed is not in a scoped namespace declaration.
      
      Includes a dedicated test to verify the cache is used and working.
      4924df8b
    • jrfnl's avatar
      FunctionDeclarations::getArrowFunctionOpenClose(): implement use of the new `Cache` class · 88640db7
      jrfnl authored
      While arrow functions are generally only small snippets of code, as they don't always have a clear "end token", determining whether something is an arrow function and retrieving the relevant open/close tokens can be token-walking intensive, which is why I'm implementing caching for it.
      
      Note: the results will only be cached for the backported functionality. When using a more recent PHPCS version, the cache code will only be reached in the case of parse errors.
      
      Includes a dedicated test to verify the cache is used and working.
      88640db7
    • jrfnl's avatar
      ControlStructures::getDeclareScopeOpenClose(): implement use of the new `Cache` class · 5a5bce0a
      jrfnl authored
      As `declare` constructs using alternative syntax can be long, determining the scope opener/closer can involve a lot of token walking, which is why I'm implementing caching for it.
      
      Includes some minor tweaks to the exit routes of the function to ensure that the cache will always be set when the `T_DECLARE` token doesn't natively have a scope opener/closer assigned.
      
      Includes a dedicated test to verify the cache is used and working.
      5a5bce0a
    • jrfnl's avatar
      [NoFile]Cache: allow for disabling the cache in test situations · 76b8cb9f
      jrfnl authored
      Includes:
      * Additional tests to cover this change on the off-chance that someone will use this functionality in a non-test situation.
      * Making sure that the tests related to the `[NoFile]Cache` classes will always run with caching turned **on** as running the cache functionality tests without caching enabled is a little pointless (and would fail the tests).
      76b8cb9f
    • jrfnl's avatar
      :sparkles: New (internal) `Cache` and `NoFileCache` classes · 24da15ea
      jrfnl authored
      ... to allow for caching the results of processing intensive utility methods.
      
      The `Cache` class is intended to be used for utility functions which depend on the `$phpcsFile` object.
      The `NoFileCache` class is for file-independent functions.
      
      Use selectively and with care as the memory usage of PHPCS will increase when using these caches!
      
      Includes full set of tests to cover this new functionality.
      
      These new tests have been added to the `RunFirst` test suite to prevent the cache setting and clearing done in these tests from interfering with the rest of the tests.
      24da15ea
    • jrfnl's avatar
      Tests: add TypeProviderHelper class · 7cad4fd0
      jrfnl authored
      Based on a similar class I wrote for the Requests library.
      
      If/when that class get published as a package, this class should be removed in favour of the package.
      7cad4fd0
    • Juliette's avatar
      Merge pull request #334 from... · a0de510f
      Juliette authored
      Merge pull request #334 from PHPCSStandards/feature/tests-minor-tweaks-to-allow-for-repeat-test-runs
      
      Tests: minor tweaks to allow for running tests on repeat
      a0de510f
    • jrfnl's avatar
      Tests: minor tweaks to allow for running tests on repeat · 2b966c11
      jrfnl authored
      ... using the PHPUnit `--repeat` option.
      
      Note: this option was already available in PHPUnit 4.x, so can be safely used for this codebase.
      
      The changes made:
      * Prevent "constant already defined notices" on repeated test runs.
      * Prevent a file from not being tokenized on repeated test runs.
      
      Ref:
      * https://phpunit.readthedocs.io/en/9.5/textui.html
      2b966c11
  7. 29 Jun, 2022 6 commits
    • Juliette's avatar
      Merge pull request #333 from PHPCSStandards/feature/tests-use-param-names-in-dataproviders · 5cd4b044
      Juliette authored
      Tests: use parameter names in data provider test cases
      5cd4b044
    • jrfnl's avatar
      Tests: use parameter names in data provider test cases · 99a76f9a
      jrfnl authored
      ... when the data set array contains more than one item.
      
      This is done to lower the cognitive load when reading the tests.
      
      Includes:
      * Renaming a couple of parameters for more consistency.
      * Renaming data provider sub-array keys if they didn't match the parameter names of the test function.
      
      Note: this changeset excludes the `isShortArrayOrList` tests. Those tests will be addressed separately in the refactor of those methods.
      
      Hoping I've caught everything, but not claiming completeness.
      99a76f9a
    • Juliette's avatar
      Merge pull request #331 from PHPCSStandards/feature/various-code-coverage-fixes · cbcf363a
      Juliette authored
      QA/Tests: various code coverage tweaks
      cbcf363a
    • jrfnl's avatar
      Tests: add select `@codeCoverageIgnore` annotations · 2ed664c5
      jrfnl authored
      ... for code which is only in place as defensive coding, but shouldn't be reachable under normal circumstances.
      2ed664c5
    • jrfnl's avatar
      PHPUnit config: isolate a number of tests from the main test suite · 047929b5
      jrfnl authored
      The functions being tested in these three test classes all use function local `static` variables for optimization.
      
      Having the function local `static` variable will often prevent code coverage from being recorded correctly for the code as the code for setting the static will only be run when the function is first called, which may not be in the dedicated test for the function, so it makes code coverage recording highly dependant on the order in which tests are run.
      
      In these three cases, I do believe the function local `static` variable is justified (for the time being, benchmarking should be able to determine for sure at some point in the future).
      
      To still prevent missed lines in the code coverage reports, I'm moving the tests for these three functions into a separate test suite, which will run first.
      This should ensure the code which sets the static will be run first when the dedicated tests for these methods are run and should allow the correct registration of code coverage for this code.
      
      Mind: if at some point the `executionOrder` configuration would be added to the config/enabled, it needs to be verified how that behaves in combination with multiple test suites. But that's for later.
      
      Ref: https://github.com/sebastianbergmann/php-code-coverage/issues/913
      047929b5
    • jrfnl's avatar
      GH Actions/coverage: add extra (debug) step · d8263d2e
      jrfnl authored
      While the feedback shown in the `setup-php` step is awesome, it doesn't show the version of Xdebug used when running code coverage, while, in case of issues, the version number of Xdebug is crucial to know.
      
      This extra step allows for that information to always be available.
      
      I've only added the step to the code coverage job though as that's the only one for which the Xdebug version is relevant.
      d8263d2e
  8. 28 Jun, 2022 2 commits
    • Juliette's avatar
      Merge pull request #328 from... · 6b4a0e8a
      Juliette authored
      Merge pull request #328 from PHPCSStandards/passedparameters/hasparameters-account-for-parent-tokenization-change
      
      PassedParameters::hasParameters(): account for upstream tokenization change for `parent`
      6b4a0e8a
    • jrfnl's avatar
      PassedParameters::hasParameters(): account for upstream tokenization change for `parent` · 21059b54
      jrfnl authored
      Upstream PR squizlabs/PHP_CodeSniffer 3546, which is included in PHPCS 3.7.0, changed the tokenization of the `parent` keyword in `new parent()` from `T_STRING` to `T_PARENT`.
      
      This has consequences for the `PassedParameters::hasParameters()` method and associated methods:
      * The `Collections::parameterPassingTokens()` method will now need to include the `T_PARENT` token.
      * The underlying `Collections::functionCallTokens()` method should as well.
      * The `PassedParameters::hasParameters()` method now needs to allow for the `T_PARENT` token potentially being used as part of a `new parent()` function call.
      
      This commit fixes all that up.
      
      Includes additional unit tests to safeguard it all (and some more).
      21059b54