Skip to content

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 11, 2025

Release checklist

General

  • Verify, and if necessary, update the version constraints for dependencies in the composer.json - various PRs.
  • Verify that any new functions have type declarations whenever possible.
  • Add changelog for the release - PR Changelog for PHPCSUtils 1.1.0 #682
    ✏️ Remember to add a release link at the bottom!

Release

  • Merge this PR
  • Make sure all CI builds are green.
  • Tag and create a release (careful, GH defaults to develop!) & copy & paste the changelog to it.
    ✏️ Don't forget to copy the link collection from the bottom of the changelog!
  • Make sure all CI builds are green.
  • Verify that the website regenerated correctly.
  • Close the milestone
  • Open a new milestone for the next release
  • If any open PRs/issues which were milestoned for this release did not make it into the release, update their milestone.
  • Fast-forward develop to be equal to stable

Publicize

  • Tweet about the release.
  • Inform the primary dependants of this repo (PHPCSExtra, WordPressCS, PHPCompatibility and VariableAnalysis) about the release.

jrfnl and others added 30 commits May 20, 2024 15:58
... containing the ternary operator tokens.
…perators-collection

Tokens\Collections: add new ternaryOperators() token array
The PHP_CodeSniffer native `Config` class contains a number of static properties.
As the value of these static properties will be retained between instantiations of the class, config values set in one test can influence the results for another test, which makes tests unstable.

This commit introduces a test "double" of the `Config` class which prevents this from happening.
In _most_ cases, tests should be using this class instead of the "normal" Config, with the exception of select tests for the PHPCS Config class itself.

Includes tests covering the new class.
…\ConfigDouble` class

Start using the new `ConfigDouble` class in the `UtilityMethodTestCase` class.

Note: this includes deprecating the `UtilityMethodTestCase::setStaticConfigProperty()` method, which was introduced, but not publicized, in PHPCSUtils 1.0.9 in favour of handling the same in the `ConfigDouble` class.
…e-utility-class

✨ New `PHPCSUtils\TestUtils\ConfigDouble` class
This abstracts the parsing of a file out from the `setUpTestFile()` method, without changing the functionality.

Having the parsing of a file as a separate method allows for tests to parse a secondary test case file for use in a test.

As the new method doesn't create any functional changes, it is already covered by existing tests.
…ethod

UtilityMethodTestCase: new `parseFile()` method
This new class initially contains the following methods:
* `hasByteOrderMark(File $phpcsFile): string|false` to determine whether a file starts with a byte order mark and if so, which type of byte order mark.
* `hasSheBang(File $phpcsFile): bool` to determine whether a file starts with a shebang line.

Includes tests.
This exception extends the PHPCS native `RuntimeException` to allow pre-existing PHPCSUtils code to switch to this exception without causing a breaking change.

This exception is also not `final` to allow more specific exceptions to extend from it. This is, again, deliberate, to allow pre-existing PHPCSUtils code to switch to more specific child-exceptions without causing a breaking change.

Includes changing the `InvalidTokenArray` exception to extend this new exception.
New exception to flag an invalid argument type passed to a method using a standardized message.

This exception extends the PHPCSUtils native `RuntimeException` to allow pre-existing PHPCSUtils code to switch to this exception without causing a breaking change.

If, by the time a 2.0 release happens, usage of this exception has not been replaced with PHP native type declarations yet, it should be considered to switch the parent class for the exception to the PHP native `TypeError` class (PHP 7.0+), which this exception largely emulates.

Includes perfunctory test for the exception.
New exception to flag arguments using the correct type, but where the value doesn't comply with predefined restrictions, like an empty string being passed, when only a non-empty string is accepted or a negative integer being passed when a positive integer is expected.

The exception ensures these issues are flagged with a more consistent message format using a standardized message prefix.

This exception extends the PHPCSUtils native `RuntimeException` to allow pre-existing PHPCSUtils code to switch to this exception without causing a breaking change.

By rights, this exception should extend the PHP native `ValueError` class, but unfortunately, that class is not available until PHP 8.0 (and not extending the `RuntimeException` would be a breaking change).

By the time a 2.0 release happens, it should be considered to switch the parent class for the exception to the PHP native `ValueError` (PHP 8.0+) if the minimum supported PHP version allows for it.

Includes perfunctory test for the exception.
New exception to flag a passed stack pointer which doesn't exist in the $phpcsFile.

This exception extends the PHPCSUtils native `RuntimeException` to allow pre-existing PHPCSUtils code to switch to this exception without causing a breaking change, though extending the PHPCSUtils `ValueError` class would also have been an option.

By rights, this exception should probably extend the PHP native `OutOfBoundsException` class, but not extending the `RuntimeException` would be a breaking change.

By the time a 2.0 release happens, it should be considered to switch the parent class for the exception to the PHP native `OutOfBoundsException`.

Includes perfunctory test for the exception.
New exception to flag a passed stack pointer argument, which does not comply with the token type requirements of the receiving method.

This exception extends the PHPCSUtils native `RuntimeException` to allow pre-existing PHPCSUtils code to switch to this exception without causing a breaking change, though extending the PHPCSUtils `ValueError` class would also have been an option.

By rights, this exception should probably extend the PHP native `InvalidArgumentException` class, but not extending the `RuntimeException` would be a breaking change.

By the time a 2.0 release happens, it should be considered to switch the parent class for the exception to the PHP native `InvalidArgumentException`.

Includes perfunctory test for the exception.
New exception to flag an error in the program logic.

The exception ensures these issues are flagged with a more consistent message format using a standardized message prefix.

This exception extends the PHPCS native `RuntimeException` to allow pre-existing PHPCSUtils code to switch to this exception without causing a breaking change.

By rights, this exception should extend the PHP native `LogicException` class, but not extending the `RuntimeException` would be a breaking change.

By the time a 2.0 release happens, it should be considered to switch the parent class for the exception to the PHP native `LogicException`.

Includes perfunctory test for the exception.
New exception to flag missing, conditionally required, parameters.

The exception ensures these issues are flagged with a more consistent message format using a standardized message prefix.

This exception extends the PHPCS native `RuntimeException` to allow pre-existing PHPCSUtils code to switch to this exception without causing a breaking change.

By rights, this exception should extend the PHP native `ArgumentCountError` class, but not extending the `RuntimeException` would be a breaking change.

By the time a 2.0 release happens, it should be considered to switch the parent class for the exception to the PHP native `ArgumentCountError`.

Includes perfunctory test for the exception.
…exceptions

✨ Introduce 7 new exceptions
This implements the use of the new exceptions introduced in 598 in all the right places in PHPCSUtils.

Notes:
* The `BCFile` class is explicitly exempt from this change as the methods in that class emulate the PHPCS native methods, which means they should also throw the PHPCS native exception.
* Includes switching a number of test class from the `UtilityMethodTestCase` parent class to the `PolyfilledTestCase` parent class - which is basically the `UtilityMethodTestCase` + the PHPUnit Polyfills -. This allows for expecting the exceptions without having to jump through hoops for PHPUnit cross-version support.
* Includes adding select extra tests where needed.
This changes the exceptions being caught in various `catch` statements to more specific ones.

This means that errors which should always have been thrown, will now throw and only the potentially expected (and acceptable) exceptions will now be caught.

Note:
* For the `Namespaces::getDeclaredName()` method, the `catch` has not been changed (other than switching from the PHPCS native `RuntimeException` to the PHPCSUtils one).
    The reason for this is that the method is explicitly documented as returning `false` for non-existent tokens.
    While this behaviour is not in line with other methods in PHPCSUtils, changing the behaviour could be seen as a breaking change, so should be done in a major release.

Includes test for where the behaviour of the functions is now different.
…ew-exceptions

Start using the new exceptions
Add more defensive coding against incorrect stack pointers being passed.

It is common to pass the result of a call to `File::findPrevious()` or `File::findNext()` to functions expecting a stack pointer, but these `File` functions can return `false`, which would be juggled to `0` when used in the typical `isset($tokens[$stackPtr])` checks.
This would then lead to that check passing, while the value should have been rejected, as the method may now try to act on a completely different token than intended (and more defensive coding should have been added to the originating sniff).

Adding a preliminary check to make sure the received parameter is an integer prevents this problem and should surface any such bugs in sniffs using the updated PHPCSUtils methods.

Includes tests.
…e-coding-typeerrors

Add more defensive coding / improve type checking
…date-phpcs-version

GetVersionTest: update for release of PHPCS 3.10.0
…date-phpcs-version

GetVersionTest: update for release of PHPCS 3.10.1
This commit adds a new set of utility methods to the `ObjectDeclarations` class:
* `getDeclaredConstants(File $phpcsFile, int $stackPtr): array`
* `getDeclaredEnumCases(File $phpcsFile, int $stackPtr): array`
* `getDeclaredProperties(File $phpcsFile, int $stackPtr): array`
* `getDeclaredMethods(File $phpcsFile, int $stackPtr): array`
* (`private`) `analyzeOOStructure(File $phpcsFile, int $stackPtr): array`

These methods allow for retrieving an array with the names of all constants, enum cases, properties and methods as the keys and the stack pointer to the relevant `T_CONST`, `T_ENUM_CASE`, `T_VARIABLE` or `T_FUNCTION` token as the value.

As these methods all used the same `analyzeOOStructure()` method under the hood and the results of that method are cached, the method are highly optimized for performance.

If a sniff needs to search for a named constant/enum case/property/method in an OO structure, in most cases, these methods should be the recommended way for finding the declaration, instead of the sniff attempting to do this itself.

Includes extensive unit tests.
…tmethods-utility

✨ New ObjectDeclarations::getDeclared*() utility methods
... with some utility functions for handling file paths.

The class initially contains the following utility methods:
* `getName(File $phpcsFile): string` - Retrieve the normalized file name for the current file.
* `isStdin(File $phpcsFile): bool` - Check whether the current file under scan comes from STDIN.
* `normalizeAbsolutePath(string $path): string` - Normalize an absolute path to forward slashes and to include a trailing slash for directories.
* `normalizeDirectorySeparators(string $path): string` - Normalize all directory separators to be a forward slash.
* `trailingSlashIt(string $path): string` - Ensure that a directory path ends on a trailing slash.
* `startsWith(string $haystack, string $needle): bool` - Check whether one file/directory path starts with another path.

Includes unit tests.
jrfnl and others added 20 commits June 4, 2025 22:02
`T_USE` tokens used for closure use statements are parentheses owners as of PHPCS 4.0.0.

This commit updated the `Parentheses::getOwner()` method to treat closure `T_USE` tokens as parentheses owners, PHPCS cross-version.

Includes additional unit tests for this case.

Refs:
* PHPCSStandards/PHP_CodeSniffer 1013
* squizlabs/PHP_CodeSniffer 2593
* squizlabs/PHP_CodeSniffer 3104
…esis owner

This change was already previously handled in PHPCSUtils. This commit just syncs in the new tests as introduced upstream.

Ref: PHPCSStandards/PHP_CodeSniffer 1013
…or warning + PHP 8.4 interface properties

As of PHPCS 4.0, the `File::getMemberProperties()` method:
* ... will handle properties in interfaces to support PHP 8.4, in which this is now allowed.
* ... will no longer throw a parse error warning.

This commit makes the necessary updates in PHPCSUtils for the same:
* Adds `T_INTERFACE` to the `Collections::ooPropertyScopes()` for PHP 8.4 properties in interfaces support.
* Updates the test expectations for the `Scopes::isOOProperty()` method to allow for PHP 8.4 properties in interfaces.
* Updates the `BCFile::getMemberProperties()` polyfill to mirror the PHPCS 4.0 version of the method.
* Updates various tests for both the `BCFile::getMemberProperties()` and the `Variables::getMemberProperties()` methods to be in line with the changes.

Ref: PHPCSStandards/PHP_CodeSniffer 991
…kens for non-named structures

The `[BC]File::getDeclarationName()` method - for historic reasons - accepted the `T_CLOSURE` and `T_ANON_CLASS` tokens, even though these structures will never have a name, and returned `null` for those tokens.

This commit changes the `BCFile::getDeclarationName()` method to no longer accept those tokens and throw an exception if they are passed to the method instead.

As a secondary change, when the name of a valid structure cannot be determined, the method will now no longer return `null`, but will return an empty string.
This normalizes the return type of the method to always return a string (or throw an exception).

Includes updated unit tests to match.

This change mirrors the upstream change made to the `File::getDeclarationName()` method in PHPCS 4.0.

Note: this change is NOT mirrored in the `ObjectDeclarations::getName()` method, as changing it there would constitute a breaking change for PHPCSUtils, so that change needs to wait until PHPCSUtils 2.0.

Ref: PHPCSStandards/PHP_CodeSniffer 1007
…mespace relative parent classes

The PHPCS `File::findExtendedClassName()` method did not handle namespace relative parent classes correctly prior to PHPCS 4.0.

The PHPCSUtils native `ObjectDeclarations::findExtendedClassName()` method **_did_** already handle this correctly.

This commit adds the PHPCS 4.x version of the `findExtendedClassName()` method to the `BCFile` class.

Includes moving related tests from the "Diff" test file to the "normal" test file and updating the docs to annotate this is no longer a difference between the PHPCS native and PHPCSUtils versions of the method.
…ng of namespace relative interfaces

The PHPCS `File::findImplementedInterfaceNames()` method did not handle namespace relative interfaces correctly prior to PHPCS 4.0.

The PHPCSUtils native `ObjectDeclarations::findImplementedInterfaceNames()` method **_did_** already handle this correctly.

This commit adds the PHPCS 4.x version of the `findImplementedInterfaceNames()` method to the `BCFile` class.

Includes moving related tests from the "Diff" test file to the "normal" test file and updating the docs to annotate this is no longer a difference between the PHPCS native and PHPCSUtils versions of the method.
…stream-4-branch

Update for new upstream PHPCS 4.x branch
…asym visibility support

Includes tests.

Ref: PHPCSStandards/PHP_CodeSniffer 1116
…eam / PHP 8.4 asym visibility support

Includes tests.

Ref: PHPCSStandards/PHP_CodeSniffer 1116
…ym-visibility

Sync with upstream / PHP 8.4 asym visibility support
This commit updates both the `GetVersionTest` class, as well as the GH Actions script which auto-updates the script, to allow for the `4.x-dev` branch.

It also removes the work-around which was in place for the experimental job against `4.x-dev` in the GH Actions test script. This should no longer be needed.
…low-for-4.x

GetVersionTest: update to allow for PHPCS 4.x releases
Includes fixing the grammar of some test documentation.
Have a few tests which pass an explicit `$previousUseStatements` array to better document the behaviour.
…rdermark-add-extra-test

FileInfo::hasByteOrderMark(): add some extra tests
…-extra-test

UseStatements::mergeImportUseStatements(): add extra tests
* Allow for Composer installation with PHPCS `^4.0`.
* Update GH Actions workflows to test all PHP versions against PHPCS 4.x and those builds are no longer allowed to fail.

Note: once PHPCS 4.0 has been released, the workflows will get another update to also test against "low" 4.x, but that should wait until the release.
…-4.x-support-official

Make PHPCS 4.x support official
@jrfnl jrfnl added this to the 1.1.0 milestone Jun 11, 2025
@jrfnl
Copy link
Member Author

jrfnl commented Jun 11, 2025

Note: the CI failure for RemarkLint can be ignored - this is related to the website not yet containing the documentation for the new classes which are being introduced. This will be fixed automatically when the website regenerates after the release.

jrfnl and others added 4 commits June 11, 2025 23:37
Includes changing the date as Coveralls is playing up, so blocked the release today.
* Improve the condition for when to allow for PHP deprecation notices.
* Remove duplication between test and coverage job.
* Add build against PHP 8.5 for PHPCS 4.x.
@jrfnl
Copy link
Member Author

jrfnl commented Jun 12, 2025

Okay, so Coveralls has an outage (again). I'm going to ignore it as the coverage won't have changed since the last functional change in develop anyway (and is now higher than ever before) and this release needs to get out.

@jrfnl jrfnl merged commit 6535567 into stable Jun 12, 2025
75 of 77 checks passed
@jrfnl
Copy link
Member Author

jrfnl commented Jun 12, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants