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
New BackCompat\BCFile class - import of utilities from phpcs itself #12
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import the PHPCS native utility methods from the `File` class as per PHPCS 3.5.0, as well as any associated unit tests. These methods will be improved upon further and - in so far possible - made backward-compatible to allow using the most recent PHPCS versions of these utility methods in older PHPCS version as well. Copyright of the original code here is held by Squizlabs and the respective contributors to PHP_CodeSniffer. Co-authored-by: Greg Sherwood <gsherwood@squiz.net> Co-authored-by: Jaroslav Hanslík <kukulich@kukulich.cz> Co-authored-by: jdavis <jdavis@bamboohr.com> Co-authored-by: Klaus Purer <klaus.purer@gmail.com> Co-authored-by: Nick Wilde <nick@briarmoon.ca> Co-authored-by: Martin Hujer <mhujer@gmail.com> Co-authored-by: Chris Wilkinson <c.wilkinson@elifesciences.org> Co-authored-by: Pascal Borreli <pascal@borreli.com> Co-authored-by: Diogo Oliveira de Melo <dmelo87@gmail.com> Co-authored-by: Stefano Kowalke <blueduck@gmx.net> Co-authored-by: George Mponos <gmponos@gmail.com> Co-authored-by: Tyson Andre <tysonandre775@hotmail.com> Co-authored-by: Phil Davis <phil@jankaritech.com>
Add author and copyright information for all the imported code. Note: the names and email addresses used are per the commits made by the contributors to `PHP_CodeSniffer`, which is information in the public domain.
* Adjust namespace. * Minor adjustments to import use statements. * Adjust class name. The class is named `BCFile` instead of `File` on purpose to more easily allow sniffs to use both the PHPCS native File class as well as this class without always having to alias one of the two. * Adjust method signatures - Make all methods `static`. - Add `$phpcsFile` as first parameter to all methods. * Adjust code within methods: - Add calls to `File::getTokens()` and use local `$tokens` variable. - Adjust function calls and property access to use `$phpcsFile`. - Remove `Utils\` from uses of the `Tokens` class.
Adjust namespace statement, import use statements and the calls to the functions being tested to point to the PHPCSUtils versions of the classes/methods.
Minimal adjustments to the docs and code style to make the class fit into PHPCSUtils properly. * Add standard PHPCSUtils file docblock info. * Add class docblock. * Add function `@since` tags for PHPCSUtils. * Remove extraneous blank lines between methods. * Remove function, class, control structure `//end` comments.
Minimal adjustments to the docs and code style to make the classes fit into PHPCSUtils properly. * Add standard PHPCSUtils file docblock info. * Add class docblock. * Remove extraneous blank lines between methods. * Remove function and class `//end` comments.
... between PHPCS 2.6.0 and now.
... between PHPCS 2.6.0 and now.
List the unit tests in the order they are run.
…omplete [1] Test the correct determination of the token position for the various `...token` index keys.
…omplete [2] * Test the situations in which the method returns an empty array. * Add a significant number of additional unit tests: - Cover all situations this method handles, i.e. test closures and closure use statements. - Test variadic functions. - Test handling of _all_ type declarations supported by PHP. - Test handling of the PHPCS 3.2.0+ ignore annotations. - Test (document) the behaviour of the function with fully qualified class names as type declaration, including when such a type declaration is interlaced with comments and whitespace. - Verify that a ternary in a default expression will not be confused with nullability. * Test the `Exceptions` being thrown by the method.
Fixed a bug where a subsequent parameter without type declaration would get the `type_hint_end_token` from the end of the type declaration from a previous parameter. This bug fix is included in PHPCS 3.5.3 upstream. Ref: squizlabs/PHP_CodeSniffer 2685
* Between PHPCS 2.4.0 and 3.2.3, array type declaration were tokenized as `T_ARRAY_HINT`. This has been changed to "normalized" tokenization in PHPCS 3.3.0.
* The `T_NULLABLE` token was only introduced in PHPCS 2.8.0, so the constant may not exist. For PHPCS < 2.8.0, the token will be `T_INLINE_THEN`.
... between PHPCS 2.6.0 and now.
…omplete * Test the correct determination of the token position for the `return_type_token` index key. * Test the `Exception` being thrown by the method. * Test recognition of array return type declaration with a code sample which will be incorrectly tokenized in PHPCS < 2.8.0.
* Between PHPCS 2.4.0 and 3.2.3, return types were tokenized as `T_RETURN_TYPE`. This has been changed to "normalized" tokenization in PHPCS 3.3.0. * A bug existed with the tokenization of return types to `T_RETURN_TYPE` which would cause `array` return type declarations to be tokenized as `T_ARRAY_HINT` in certain circumstances. This bug was fixed in PHPCS 2.8.0. * The `T_NULLABLE` token was only introduced in PHPCS 2.8.0, so the constant may not exist. For PHPCS < 2.8.0, the token will be `T_INLINE_THEN`.
... between PHPCS 2.6.0 and now.
…omplete * Test the correct determination of the token position for the `type_token` and the `type_end_token` index keys. * Test handling of the PHPCS 3.2.0+ ignore annotations.
…e with PHPUnit 8+
* The `T_NULLABLE` token was only introduced in PHPCS 2.8.0, so the constant may not exist. * Prior to PHPCS 3.5.0, even when the `T_NULLABLE` token _does_ exist, the nullable indicator for typed property declarations would not be corrected to `T_NULLABLE` by the Tokenizer and would still be a `T_INLINE_THEN` token. See: PHPCS issue 2413 * Prior to PHPCS 3.3.0, the array keyword when not used to declare an array would be tokenized as `T_ARRAY_HINT`. This has been changed to "normalized" tokenization in PHPCS 3.3.0 and it will now be tokenized as a `T_STRING`.
... between PHPCS 2.6.0 and now.
... between PHPCS 2.6.0 and now.
* Test passing an unexpected token. * Test assignment using null coalesce equals.
... as while the `T_COALESCE_EQUAL` was introduced in PHPCS 2.8.1, it wasn't added to the `Tokens::$assignmentTokens` array until PHPCS 2.9.0.
... between PHPCS 2.6.0 and now.
... between PHPCS 2.6.0 and now.
... between PHPCS 2.6.0 and now.
... between PHPCS 2.6.0 and now.
... between PHPCS 2.6.0 and now.
... between PHPCS 2.6.0 and now.
… complete * Test support of anonymous classes. * Test the situations in which the method returns `false`. * Confirm non-support of multi-extended interfaces.
... between PHPCS 2.6.0 and now.
… feature complete * Test support of anonymous classes. * Test handling of the PHPCS 3.2.0+ ignore annotations. * Test the situations in which the method returns `false`.
Add documentation about which Tokenizer changes are being accounted for in the utility methods in this class.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BackCompat\BCFile: import from PHPCS 3.5.0
Import the PHPCS native utility methods from the
File
class as per PHPCS 3.5.0, as well as any associated unit tests.These methods will be improved upon further and - in so far possible - made backward-compatible to allow using the most recent PHPCS versions of these utility methods in older PHPCS version as well.
Copyright of the original code here is held by Squizlabs and the respective contributors to PHP_CodeSniffer.
Contributors to the specific code imported have been credited and added as co-authors to this commit.
BackCompat\BCFile: give credit where credit is due
Add author and copyright information for all the imported code.
Note: the names and email addresses used are per the commits made by the contributors to
PHP_CodeSniffer
, which is information in the public domain.BackCompat\BCFile: adjust to work within PHPCSUtils
The class is named
BCFile
instead ofFile
on purpose to more easily allow sniffs to use both the PHPCS native File class as well as this class without always having to alias one of the two.static
.$phpcsFile
as first parameter to all methods.File::getTokens()
and use local$tokens
variable.$phpcsFile
.Utils\
from uses of theTokens
class.BackCompat\BCFile: adjust to work within PHPCSUtils (unit tests)
Adjust namespace statement, import use statements and the calls to the functions being tested to point to the PHPCSUtils versions of the classes/methods.
BackCompat\BCFile: adjust docs & CS
Minimal adjustments to the docs and code style to make the class fit into PHPCSUtils properly.
@since
tags for PHPCSUtils.//end
comments.BackCompat\BCFile: adjust docs & CS (unit tests)
Minimal adjustments to the docs and code style to make the classes fit into PHPCSUtils properly.
//end
comments.BackCompat\BCFile: document work-arounds added
Add documentation about which Tokenizer changes are being accounted for in the utility methods in this class.
Method specific changes
BCFile::getDeclarationName()
BCFile::getMethodParameters()
List the unit tests in the order they are run.
Test the correct determination of the token position for the various
...token
index keys.Exceptions
being thrown by the method.Fixed a bug where a subsequent parameter without type declaration would get the
type_hint_end_token
from the end of the type declaration from a previous parameter.This bug fix is included in PHPCS 3.5.3 upstream.
Ref: File::getMethodParameters() setting typeHintEndToken for vars with no type hint squizlabs/PHP_CodeSniffer#2685
T_ARRAY_HINT
.This has been changed to "normalized" tokenization in PHPCS 3.3.0.
T_NULLABLE
token was only introduced in PHPCS 2.8.0, so the constant may not exist.For PHPCS < 2.8.0, the token will be
T_INLINE_THEN
.BCFile::getMethodProperties()
return_type_token
index key.Exception
being thrown by the method.T_RETURN_TYPE
.This has been changed to "normalized" tokenization in PHPCS 3.3.0.
T_RETURN_TYPE
which would causearray
return type declarations to be tokenized asT_ARRAY_HINT
in certain circumstances.This bug was fixed in PHPCS 2.8.0.
T_NULLABLE
token was only introduced in PHPCS 2.8.0, so the constant may not exist.For PHPCS < 2.8.0, the token will be
T_INLINE_THEN
.BCFile::getMemberProperties()
type_token
and thetype_end_token
index keys.T_NULLABLE
token was only introduced in PHPCS 2.8.0, so the constant may not exist.T_NULLABLE
token does exist, the nullable indicator for typed property declarations would not be corrected toT_NULLABLE
by the Tokenizer and would still be aT_INLINE_THEN
token.See: PHPCS issue PHP 7.4: tokenizing of typed properties squizlabs/PHP_CodeSniffer#2413
T_ARRAY_HINT
.This has been changed to "normalized" tokenization in PHPCS 3.3.0 and it will now be tokenized as a
T_STRING
.BCFile::getClassProperties()
BCFile::isReference()
... as while the
T_COALESCE_EQUAL
was introduced in PHPCS 2.8.1, it wasn't added to theTokens::$assignmentTokens
array until PHPCS 2.9.0.BCFile::getTokensAsString()
BCFile::findStartOfStatement()
BCFile::findEndOfStatement()
BCFile::hasCondition()
BCFile::getCondition()
BCFile::findExtendedClassName()
false
.BCFile::findImplementedInterfaceNames()
false
.