Skip to content

Commit 0d79aa6

Browse files
committed
2 parents 2311922 + efb1b91 commit 0d79aa6

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

Inpsyde/Sniffs/CodeQuality/FunctionBodyStartSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function checkBodyStart(
8686

8787
$error =
8888
($isMultiLineDeclare || $isSingleLineSignature) && $bodyLine !== ($openerLine + 2)
89-
|| $isSingleLineDeclare && $bodyLine !== ($openerLine + 1);
89+
|| $isSingleLineDeclare && $bodyLine > ($openerLine + 2);
9090

9191
if (!$error) {
9292
return [null, null, null];
@@ -95,7 +95,7 @@ private function checkBodyStart(
9595
$startWithComment = in_array($tokens[$bodyStart]['code'], Tokens::$emptyTokens, true);
9696

9797
if (!$startWithComment && ($isMultiLineDeclare || $isSingleLineSignature)) {
98-
$where = $isSingleLineSignature === 'SingleLineSignature'
98+
$where = $isSingleLineSignature
9999
? 'with single-line signature and open curly bracket on same line'
100100
: 'where arguments declaration spans across multiple lines';
101101
$code = $isSingleLineSignature

Inpsyde/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,6 @@
123123
<rule ref="Squiz.Scope.MemberVarScope"/>
124124
<rule ref="Squiz.Scope.StaticThisUsage"/>
125125

126+
<rule ref="PHPCompatibility"/>
127+
126128
</ruleset>

README.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -279,32 +279,26 @@ class Foo
279279
## PhpStorm
280280

281281
After having installed the package as explained above in the _"Installation"_ section,
282-
open PhpStorm settings, and navigate the settings:
282+
open PhpStorm settings, and navigate to
283283

284-
`Language & Frameworks` -> `PHP` -> `Code Sniffer`
284+
`Language & Frameworks` -> `PHP` -> `Quality Tools` -> `PHP_CodeSniffer`
285285

286-
There will be a dropdown with label _"Configuration"_, choose _"Local"_.
287-
Next to the dropdown there will be a button with _"..."_ and once clicked will show a dialog
288-
were it is possible to select the path for the Code Sniffer executable.
289-
Navigate inside the `vendor` folder a found the file: `/vendor/bin/phpcs` (`phpcs.bat` in Windows).
286+
Choose _"Local"_ in the _"Configuration"_ dropdown.
287+
Click the _"..."_ button next to the dropdown, it will show a dialog
288+
where you need to specify the path for the Code Sniffer executable.
289+
Open the file selection dialog, navigate to `vendor/bin/` in your project and select `phpcs` (`phpcs.bat` on Windows).
290+
Click the _"Validate"_ button next to the path input field, if everything is fine
291+
a success message will be shown at the bottom of the window.
290292

291-
Next to the input for path selection there's a button _"Validate"_, click it, if everything is fine
292-
a success message will be shown.
293-
294-
At this point navigate to the settings:
293+
Navigate to
295294

296295
`Editor` -> `Inspections`
297296

298-
From the list of inspections, expand the _"PHP"_ one and scroll down to _"PHP Code Sniffer validation"_
299-
to enable it.
297+
Type `codesniffer` in the search field before the list of inspections, select `PHP` -> `Quality Tools` -> `PHP_CodeSniffer validation` and enable it using the checkbox in the list, press _"Apply"_.
300298

301-
When selecting _"PHP Code Sniffer validation"_ inspections, on the right there a dropdown to select the
302-
code style.
299+
Select _"PHP_CodeSniffer validation"_, press the refresh icon next to the _"Coding standard"_ dropdown on the right and choose `Inpsyde`.
303300

304-
If you have created a `phpcs.xml` file, select _"Custom"_ as standard, then using the _"..."_ button
305-
next to the dropdown for standard selection, you can pick the `phpcs.xml` file.
306-
In case of no `phpcs.xml` present, it is possible to select _"Inpsyde"_ standard from the dropdown.
307-
If _"Inpsyde"_ is not present in the dropdown, click the "refresh" icon next to the dropdown.
301+
If you do not see `Inpsyde` here, you may need to specify `phpcs.xml` file by selecting _"Custom"_ as standard and using the _"..."_ button next to the dropdown.
308302

309-
Now PhpStorm integration is complete, and errors in the codestyle will be shown in the IDE editor
310-
so can be recognized without running any command at all.
303+
Now PhpStorm integration is complete, and errors in the code style will be shown in the IDE editor
304+
allowing to detect them without running any commands at all.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"require": {
3030
"php": ">=7.0",
3131
"squizlabs/php_codesniffer": "^3",
32-
"dealerdirect/phpcodesniffer-composer-installer": "^0.4",
32+
"dealerdirect/phpcodesniffer-composer-installer": "^0.5",
3333
"wp-coding-standards/wpcs": "^0.14",
3434
"automattic/phpcs-neutron-standard": "^1",
3535
"phpcompatibility/php-compatibility": "^9.0"

tests/fixtures/function-body-start.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ function foo()
88
return 'foo';
99
}
1010

11-
// @phpcsWarningCodeOnNextLine WrongForSingleLineDeclaration
11+
// tolerate this as PHPStorm code styler cannot distinguish between
12+
// single line and multiline function declarations. See issue #32
1213
function bar()
1314
{
1415

1516
return 'bar';
1617
}
1718

19+
// @phpcsWarningCodeOnNextLine WrongForSingleLineSignature
20+
function lorem() {
21+
22+
23+
return 'ipsum';
24+
}
25+
1826
// @phpcsWarningCodeOnNextLine WrongForMultiLineDeclaration
1927
function fooFoo(
2028
string $foo,
@@ -66,13 +74,19 @@ public function foo()
6674
return 'foo';
6775
}
6876

69-
// @phpcsWarningCodeOnNextLine WrongForSingleLineDeclaration
7077
private function bar()
7178
{
7279

7380
return 'bar';
7481
}
7582

83+
// @phpcsWarningCodeOnNextLine WrongForSingleLineSignature
84+
public function lorem() {
85+
86+
87+
return 'ipsum';
88+
}
89+
7690
// @phpcsWarningCodeOnNextLine WrongForMultiLineDeclaration
7791
protected function fooFoo(
7892
string $foo,

0 commit comments

Comments
 (0)