Skip to content

Commit bb811b2

Browse files
author
dereuromark
committed
Merge remote-tracking branch 'remotes/origin/master' into develop
2 parents 95cd5fa + c24bcf2 commit bb811b2

File tree

9 files changed

+38
-36
lines changed

9 files changed

+38
-36
lines changed

PSR2R/Sniffs/Commenting/FullyQualifiedClassNameInDocBlockSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ protected function findInSameNameSpace(File $phpCsFile, $className) {
190190
if (!$currentNameSpace) {
191191
return null;
192192
}
193+
$currentNameSpaceInfo = $this->getNamespaceInfo($phpCsFile);
194+
$currentNameSpace = $currentNameSpaceInfo['namespace'];
193195

194196
$file = $phpCsFile->getFilename();
195197
$dir = dirname($file) . DIRECTORY_SEPARATOR;

PSR2R/Sniffs/Namespaces/UnusedUseStatementSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function process(File $phpcsFile, $stackPtr) {
5454
return;
5555
}
5656

57-
$classUsed = $phpcsFile->findNext(T_STRING, ($classNameIndex + 1), null, false, $tokens[$classNameIndex]['content']);
57+
$classUsed = $phpcsFile->findNext([T_STRING, T_RETURN_TYPE], ($classNameIndex + 1), null, false, $tokens[$classNameIndex]['content']);
5858

5959
while ($classUsed !== false) {
6060
$beforeUsage = $phpcsFile->findPrevious(
@@ -74,7 +74,7 @@ public function process(File $phpcsFile, $stackPtr) {
7474
return;
7575
}
7676

77-
$classUsed = $phpcsFile->findNext(T_STRING, ($classUsed + 1), null, false, $tokens[$classNameIndex]['content']);
77+
$classUsed = $phpcsFile->findNext([T_STRING, T_RETURN_TYPE], ($classUsed + 1), null, false, $tokens[$classNameIndex]['content']);
7878
}
7979

8080
$warning = 'Unused use statement';

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,19 @@ For Win OS you should be using `\` as separator:
6969
vendor\bin\sniff -v
7070
```
7171

72-
#### Hook it into your IDE for live-correction
73-
You can easily make a "watcher" for your IDE, so any file you work on, will be auto-corrected when (auto-)saving.
74-
For PHPStorm, for example, make sure you switch `Show Console` to `never` to not be disturbed by it all the time.
72+
#### Include it in your IDE via hotkey
73+
E.g. for PHPStorm:
74+
* Open Settings -> Tools -> External Tools
75+
* Add a new tool named "cs-sniffer" and set Program to `$ProjectFileDir$/vendor/bin/phpcs`, Parameters to `--standard=$ProjectFileDir$/vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml -p $FilePath$` and Working directoy to `$ProjectFileDir$`.
76+
* Add a new tool named "cs-fixer" and set Program to `$ProjectFileDir$/vendor/bin/phpcbf`, Parameters to `--standard=$ProjectFileDir$/vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml -v $FilePath$` and Working directoy to `$ProjectFileDir$`.
77+
* Optionally uncheck "Open console" if you don't want to see any output here for the fixer.
78+
* Now set up your hotkeys under Settings -> Keymap (search for cs-sniffer and cs-fixer). E.g. `Control + Comma` for sniffing, and `Control + Dot` for fixing.
79+
80+
##### Hook it into your IDE for live-correction
81+
You can also easily make a "watcher" for your IDE, so any file you work on, will be auto-corrected when (auto-)saving.
82+
But here you should better only whitelist certain sniffs that only add things and don't remove anything.
83+
84+
Note: For PHPStorm, for example, make sure you switch `Show Console` to `never` to not be disturbed by it all the time.
7585

7686
### Writing new sniffs
7787
You can contribute by adding new sniffs as per PSR-2-R standard.

bin/sniff.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/php -q
22
<?php
33

4-
/**
5-
* Bin stub.
6-
*/
74
$options = [
8-
__DIR__ . '/../../../autoload.php',
9-
__DIR__ . '/../../autoload.php',
105
__DIR__ . '/../vendor/autoload.php',
116
__DIR__ . '/vendor/autoload.php'
127
];
8+
if (!empty($_SERVER['PWD'])) {
9+
array_unshift($options, $_SERVER['PWD'] . '/vendor/autoload.php');
10+
}
11+
1312
foreach ($options as $file) {
1413
if (file_exists($file)) {
1514
define('SNIFFER_COMPOSER_INSTALL', $file);

bin/tokenize.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/php -q
22
<?php
33

4-
/**
5-
* Bin stub.
6-
*/
74
$options = [
8-
__DIR__ . '/../../../autoload.php',
9-
__DIR__ . '/../../autoload.php',
105
__DIR__ . '/../vendor/autoload.php',
116
__DIR__ . '/vendor/autoload.php'
127
];
8+
if (!empty($_SERVER['PWD'])) {
9+
array_unshift($options, $_SERVER['PWD'] . '/vendor/autoload.php');
10+
}
11+
1312
foreach ($options as $file) {
1413
if (file_exists($file)) {
1514
define('SNIFFER_COMPOSER_INSTALL', $file);

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "fig-r/psr2r-sniffer",
33
"license": "MIT",
44
"description": "Code-Sniffer, Auto-Fixer and Tokenizer for PSR-2-R",
5+
"type": "phpcodesniffer-standard",
6+
"keywords": ["cs", "codesniffer"],
57
"authors": [
68
{
79
"name": "Mark Scherer",

docs/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,17 @@ You can also test specific methods per Test file using `--filter=testNameOfMetho
111111
### Running own sniffs on this project
112112
There is a convenience script to run all sniffs for this repository:
113113
```
114-
sh phpcs.sh
114+
composer cs-check
115115
```
116116
If you want to fix the fixable errors, use
117117
```
118-
sh phpcs.sh -f
118+
composer cs-fix
119119
```
120120
Make sure the root folder name is the same as the GitHub repository name (psr2r-sniffer) to exclude vendor as expected.
121121
Once everything is green you can make a PR with your changes.
122+
123+
### Updating docs
124+
Run
125+
```
126+
composer docs
127+
```

docs/sniffs.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PSR2R Code Sniffer
22

33

4-
The PSR2R/ruleset.xml standard contains 101 sniffs
4+
The PSR2R/ruleset.xml standard contains 102 sniffs
55

66
Generic (13 sniffs)
77
-------------------
@@ -25,7 +25,7 @@ PEAR (3 sniffs)
2525
- PEAR.Functions.ValidDefaultValue
2626
- PEAR.NamingConventions.ValidClassName
2727

28-
PSR2R (64 sniffs)
28+
PSR2R (65 sniffs)
2929
-----------------
3030
- PSR2R.Classes.BraceOnSameLine
3131
- PSR2R.Classes.ClassCreateInstance
@@ -38,6 +38,7 @@ PSR2R (64 sniffs)
3838
- PSR2R.Commenting.DocBlockParamAllowDefaultValue
3939
- PSR2R.Commenting.DocBlockParamArray
4040
- PSR2R.Commenting.DocBlockParamNoOp
41+
- PSR2R.Commenting.DocBlockParamNotJustNull
4142
- PSR2R.Commenting.DocBlockParam
4243
- PSR2R.Commenting.DocBlockPipeSpacing
4344
- PSR2R.Commenting.DocBlockReturnSelf

phpcs.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)