Skip to content

Commit

Permalink
Merge pull request #94 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
Release 1.0.0-alpha2
  • Loading branch information
jrfnl authored Feb 16, 2020
2 parents 17c3692 + a6f14a1 commit 4422f0b
Show file tree
Hide file tree
Showing 257 changed files with 26,609 additions and 365 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
/.gitignore export-ignore
/.travis.yml export-ignore
/phpcs.xml.dist export-ignore
/phpdoc.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/docs/ export-ignore
/Tests/ export-ignore

#
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ vendor/
/composer.lock
/.phpcs.xml
/phpcs.xml
/phpdoc.xml
/phpunit.xml
/.phpunit.result.cache
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
include:
#### SNIFF STAGE ####
- stage: sniff
php: 7.3
php: 7.4
env: PHPCS_VERSION="dev-master"
addons:
apt:
Expand Down Expand Up @@ -165,12 +165,6 @@ install:
if [[ $PHPCS_VERSION == "n/a" ]]; then
# Don't install PHPUnit when it's not needed.
composer remove --dev phpunit/phpunit --no-update --no-scripts
elif [[ "$PHPCS_VERSION" < "3.1.0" ]]; then
# PHPCS < 3.1.0 is not compatible with PHPUnit 6.x.
composer require --dev phpunit/phpunit:"^4.0||^5.0" --no-update --no-scripts
elif [[ "$PHPCS_VERSION" < "3.2.3" ]]; then
# PHPCS < 3.2.3 is not compatible with PHPUnit 7.x.
composer require --dev phpunit/phpunit:"^4.0||^5.0||^6.0" --no-update --no-scripts
fi
# --prefer-dist will allow for optimal use of the travis caching ability.
Expand Down
119 changes: 119 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Change Log for PHPCSUtils for PHP Codesniffer

All notable changes to this project will be documented in this file.

This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses [Semantic Versioning](http://semver.org/).


## [Unreleased]

_Nothing yet._


## [1.0.0-alpha2] - 2020-02-16

### Added

* New `PHPCSUtils\Utils\ControlStructures` class: Utility functions for use when examining control structures. [#70](https://github.com/PHPCSStandards/PHPCSUtils/pull/70)
* New `PHPCSUtils\Utils\FunctionDeclarations::isArrowFunction()` method. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)
* New `PHPCSUtils\Utils\FunctionDeclarations::getArrowFunctionOpenClose()` method. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)

#### PHPCS Backcompat
* `BCFile::isReference()`: support for arrow functions returning by reference. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77)
* `BCFile::getMethodParameters()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)
* `BCFile::getMethodProperties()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79), [#89](https://github.com/PHPCSStandards/PHPCSUtils/pull/89)
* `BCFile::getDeclarationName()`: allow functions to be called "fn". [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77)
* `BCFile::findEndOfStatement()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)
* `BCFile::findStartOfStatement()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77)

#### Tokens
* New `Collections::$alternativeControlStructureSyntaxTokens` property. [#70](https://github.com/PHPCSStandards/PHPCSUtils/pull/70)
* New `Collections::$alternativeControlStructureSyntaxCloserTokens` property. [#68](https://github.com/PHPCSStandards/PHPCSUtils/pull/68), [#69](https://github.com/PHPCSStandards/PHPCSUtils/pull/69)
* New `Collections::$controlStructureTokens` property. [#70](https://github.com/PHPCSStandards/PHPCSUtils/pull/70)
* New `Collections::arrowFunctionTokensBC()` method. [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)

#### Utils
* `Arrays::getDoubleArrowPtr()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79), [#84](https://github.com/PHPCSStandards/PHPCSUtils/pull/84)
* `FunctionDeclarations::getParameters()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)
* `FunctionDeclarations::getProperties()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)
* `Operators::isReference()`: support for arrow functions returning by reference. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77)
* `Parentheses::getOwner()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77)
* `Parentheses::isOwnerIn()`: support for arrow functions. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77), [#79](https://github.com/PHPCSStandards/PHPCSUtils/pull/79)

#### Other
* Documentation website at https://phpcsutils.com/

### Changed

#### PHPCS Backcompat
* `BCFile::getCondition()`: sync with PHPCS 3.5.4 - added support for new `$first` parameter. [#73](https://github.com/PHPCSStandards/PHPCSUtils/pull/73)

#### Tokens
* The `Collections::$returnTypeTokens` property now includes `T_ARRAY` to allow for supporting arrow functions in PHPCS < 3.5.3. [#77](https://github.com/PHPCSStandards/PHPCSUtils/pull/77)

#### Utils
* :warning: `Conditions::getCondition()`: sync with PHPCS 3.5.4 - renamed the existing `$reverse` parameter to `$first` and reversing the meaning of the boolean values, to stay in line with PHPCS itself. [#73](https://github.com/PHPCSStandards/PHPCSUtils/pull/73)
* :warning: `Numbers`: the `$unsupportedPHPCSVersions` property has been replaced with an `UNSUPPORTED_PHPCS_VERSION` constant.

#### Other
* Various housekeeping.


## 1.0.0-alpha1 - 2020-01-23

Initial alpha release containing:
* A `PHPCS23Utils` standard which can be used to allow an external PHPCS standard to be compatible with both PHPCS 2.x as well as 3.x.
* A `PHPCSUtils` standard which contains generic utilities which can be used when writing sniffs.
**_This standard does not contain any sniffs!_**
To use these utilities in PHPCS 3.x, all that is needed is for this package to be installed and registered with PHPCS using `installed_paths`. If the package is requested via Composer, this will automatically be handled by the [DealerDirect Composer PHPCS plugin].
To use these utilities in PHPCS 2.x, make sure the external standard includes the `PHPCS23Utils` standard in the `ruleset.xml` file like so: `<rule ref="PHPCS23Utils"/>`.

All utilities offered are compatible with PHP_CodeSniffer 2.6.0 up to the latest stable release.

This initial alpha release contains the following utility classes:

### Abstract Sniffs
* `AbstractArrayDeclarationSniff`: to examine array declarations.

### Backcompat
* `BCFile`: Backport of the latest versions of PHPCS native utility functions from the `PHP_CodeSniffer\Files\File` class to make them available in older PHPCS versions without the bugs and other quirks that the older versions of the native functions had.
* `BCTokens`: Backport of the latest versions of PHPCS native token arrays from the `PHP_CodeSniffer\Util\Tokens` class to make them available in older PHPCS versions.
* `Helper`: Utility methods to retrieve (configuration) information from PHP_CodeSniffer 2.x as well as 3.x.

### Fixers
* `SpacesFixer`: Utility to check and, if necessary, fix the whitespace between two tokens.

### TestUtils
* `UtilityMethodTestCase`: Base class for use when testing utility methods for PHP_CodeSniffer.
Compatible with both PHPCS 2.x as well as 3.x. Supports PHPUnit 4.x up to 8.x.
See the usage instructions in the class docblock.

### Tokens
* `Collections`: Collections of related tokens as often used and needed for sniffs.
These are additional "token groups" to compliment the ones available through the PHPCS native `PHP_CodeSniffer\Util\Tokens` class.

### Utils
* `Arrays`: Utility functions for use when examining arrays.
* `Conditions`: Utility functions for use when examining token conditions.
* `FunctionDeclarations`: Utility functions for use when examining function declaration statements.
* `GetTokensAsString`: Utility functions to retrieve the content of a set of tokens as a string.
* `Lists`: Utility functions to retrieve information when working with lists.
* `Namespaces`: Utility functions for use when examining T_NAMESPACE tokens and to determine the namespace of arbitrary tokens.
* `Numbers`: Utility functions for working with integer/float tokens.
* `ObjectDeclarations`: Utility functions for use when examining object declaration statements.
* `Operators`: Utility functions for use when working with operators.
* `Orthography`: Utility functions for checking the orthography of arbitrary text strings.
* `Parentheses`: Utility functions for use when examining parenthesis tokens and arbitrary tokens wrapped in parentheses.
* `PassedParameters`: Utility functions to retrieve information about parameters passed to function calls, array declarations, isset and unset constructs.
* `Scopes`: Utility functions for use when examining token scopes.
* `TextStrings`: Utility functions for working with text string tokens.
* `UseStatements`: Utility functions for examining use statements.
* `Variables`: Utility functions for use when examining variables.


[DealerDirect Composer PHPCS plugin]: https://github.com/Dealerdirect/phpcodesniffer-composer-installer/


[Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0-alpha2...HEAD
[1.0.0-alpha2]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0-alpha1...1.0.0-alpha2

4 changes: 2 additions & 2 deletions PHPCS23Utils/Sniffs/Load/LoadUtilsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
*
* @package PHPCSUtils
* @copyright 2019 PHPCSUtils Contributors
* @copyright 2019-2020 PHPCSUtils Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSUtils
*/
Expand All @@ -13,7 +13,7 @@
/*
* Here be magic.
*
* This include allows for the Utility functions to work PHPCS cross-version.
* This `include` allows for the Utility functions to work in both PHPCS 2.x as well as PHPCS 3.x.
*/
require_once \dirname(\dirname(\dirname(__DIR__))) . '/phpcsutils-autoload.php';

Expand Down
4 changes: 1 addition & 3 deletions PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
*
* @package PHPCSUtils
* @copyright 2019 PHPCSUtils Contributors
* @copyright 2019-2020 PHPCSUtils Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSUtils
*/
Expand Down Expand Up @@ -483,8 +483,6 @@ public function getActualArrayKey(File $phpcsFile, $startPtr, $endPtr)
* an acceptable index key for an array and if not, what it would turn into.
*/

$integerKey = false;

switch (\gettype($key)) {
case 'NULL':
// An array key of `null` will become an empty string.
Expand Down
Loading

0 comments on commit 4422f0b

Please sign in to comment.