Skip to content

Commit 5f65b15

Browse files
sirbrilligjrfnl
andauthored
Throw an error if phpcsutils is not available (#177)
* Add PHPCSUtils as a rule in the ruleset to make it required * Update installation instructions in README to include phpcsutils * Update README.md to fix typo Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
1 parent ad1b668 commit 5f65b15

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ Plugin for PHP_CodeSniffer static analysis tool that adds analysis of problemati
1212

1313
### Requirements
1414

15-
VariableAnalysis requires PHP 5.6 or higher and [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) version **3.1.0** or higher.
15+
VariableAnalysis requires PHP 5.6 or higher and [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) version 3.1.0 or higher.
16+
17+
It also requires [PHPCSUtils](https://phpcsutils.com/) which must be installed as a PHPCS standard. If you are using composer, this will be done automatically (see below).
1618

1719
### With PHPCS Composer Installer
1820

@@ -40,19 +42,21 @@ It should just work after that!
4042

4143
### Standalone
4244

43-
1. Install PHP_CodeSniffer by following its [installation instructions](https://github.com/squizlabs/PHP_CodeSniffer#installation) (via Composer, Phar file, PEAR, or Git checkout).
45+
1. Install PHP_CodeSniffer (PHPCS) by following its [installation instructions](https://github.com/squizlabs/PHP_CodeSniffer#installation) (via Composer, Phar file, PEAR, or Git checkout).
46+
47+
Do ensure that PHP_CodeSniffer's version matches our [requirements](#requirements).
4448

45-
Do ensure that PHP_CodeSniffer's version matches our [requirements](#requirements)
49+
2. Install PHPCSUtils (required by this sniff). Download either the zip or tar.gz file from [the PHPCSUtils latest release page](https://github.com/PHPCSStandards/PHPCSUtils/releases/latest). Expand the file and rename the resulting directory to `phpcsutils`. Move the directory to a place where you'd like to keep all your PHPCS standards.
4650

47-
2. Download and uncompress the latest release:
51+
3. Install VariableAnalysis. Download either the zip or tar.gz file from [the VariableAnalysis latest release page](https://github.com/sirbrillig/phpcs-variable-analysis/releases/latest). Expand the file and rename the resulting directory to `phpcs-variable-analysis`. Move the directory to a place where you'd like to keep all your PHPCS standards.
4852

49-
Click to download either the zip or tar.gz file from [the latest release page](https://github.com/sirbrillig/phpcs-variable-analysis/releases/latest). Expand the file and rename the resulting directory to `VariableAnalysis`.
53+
4. Add the paths of the newly installed standards to the [PHP_CodeSniffer installed_paths configuration](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths). The following command should append the new standards to your existing standards (be sure to supply the actual paths to the directories you created above).
5054

51-
3. Add its path to the PHP_CodeSniffer configuration:
55+
phpcs --config-set installed_paths "$(phpcs --config-show|grep installed_paths|awk '{ print $2 }'),/path/to/phpcsutils,/path/to/phpcs-variable-analysis"
5256

53-
phpcs --config-set installed_paths /path/to/VariableAnalysis
57+
If you do not have any other standards installed, you can do this more easily (again, be sure to supply the actual paths):
5458

55-
If you already have installed paths, [use a comma to separate them](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths).
59+
phpcs --config-set installed_paths /path/to/phpcsutils,/path/to/phpcs-variable-analysis
5660

5761
## Customization
5862

@@ -85,7 +89,6 @@ To set these these options, you must use XML in your ruleset. For details, see t
8589
- [ImportDetection](https://github.com/sirbrillig/phpcs-import-detection): A set of phpcs sniffs to look for unused or unimported symbols.
8690
- [phpcs-changed](https://github.com/sirbrillig/phpcs-changed): Run phpcs on files, but only report warnings/errors from lines which were changed.
8791

88-
8992
## Original
9093

9194
This was forked from the excellent work in https://github.com/illusori/PHP_Codesniffer-VariableAnalysis
@@ -107,7 +110,6 @@ To run linting, use:
107110

108111
```
109112
composer lint
110-
composer lint-self
111113
```
112114

113115
To run static analysis, use:

VariableAnalysis/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
<!-- If you want everything, with the defaults, just include this line -->
66
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis"/>
7+
<!-- PHPCSUtils is required for this sniff to operate -->
8+
<rule ref="PHPCSUtils"/>
79
<!--
810
You can also refer to these policy codes to customize them:
911
VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable

0 commit comments

Comments
 (0)