-
-
Notifications
You must be signed in to change notification settings - Fork 109
Rewrite PSR12.Files.DeclareStatement sniff
#578
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
Open
fredden
wants to merge
3
commits into
PHPCSStandards:4.x
Choose a base branch
from
fredden:rewrite/PSR12.Files.DeclareStatement
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+581
−162
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
439 changes: 288 additions & 151 deletions
439
src/Standards/PSR12/Sniffs/Files/DeclareStatementSniff.php
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
3 changes: 3 additions & 0 deletions
3
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.10.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Parse error. Missing directive value. | ||
| declare(ticks=) |
3 changes: 3 additions & 0 deletions
3
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.11.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Parse error. Missing semicolon (or PHP close tag). | ||
| declare(ticks=1) |
3 changes: 3 additions & 0 deletions
3
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.12.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Parse error. Missing closing curly bracket | ||
| declare(ticks=1) { |
6 changes: 6 additions & 0 deletions
6
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.3.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| // This is a parse error, but the sniff should still handle this correctly. | ||
| declare($something = $value); | ||
|
|
||
| const STRICT_TYPES = 1; | ||
64 changes: 64 additions & 0 deletions
64
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.4.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
| declare(ticks=1); | ||
| declare (ticks=1); | ||
| declare( ticks=1); | ||
| declare(ticks =1); | ||
| declare(ticks= 1); | ||
| declare(ticks=1 ); | ||
| declare(ticks=1) ; | ||
| declare (ticks=1); | ||
| declare( ticks=1); | ||
| declare(ticks =1); | ||
| declare(ticks= 1); | ||
| declare(ticks=1 ); | ||
| declare(ticks=1) ; | ||
| declare (ticks=1); | ||
| declare( ticks=1); | ||
| declare(ticks =1); | ||
| declare(ticks= 1); | ||
| declare(ticks=1 ); | ||
| declare(ticks=1) ; | ||
| declare | ||
| (ticks=1); | ||
| declare( | ||
| ticks=1); | ||
| declare(ticks | ||
| =1); | ||
| declare(ticks= | ||
| 1); | ||
| declare(ticks=1 | ||
| ); | ||
| declare(ticks=1) | ||
| ; | ||
| declare | ||
| (ticks=1); | ||
| declare( | ||
| ticks=1); | ||
| declare(ticks | ||
| =1); | ||
| declare(ticks= | ||
| 1); | ||
| declare(ticks=1 | ||
| ); | ||
| declare(ticks=1) | ||
| ; | ||
| declare/* test */(ticks=1); | ||
| declare(/* test */ticks=1); | ||
| declare(ticks/* test */=1); | ||
| declare(ticks=/* test */1); | ||
| declare(ticks=1/* test */); | ||
| declare(ticks=1)/* test */; | ||
| declare(ticks=1);/* test */ | ||
| declare// test | ||
| (ticks=1); | ||
| declare(// test | ||
| ticks=1); | ||
| declare(ticks// test | ||
| =1); | ||
| declare(ticks=// test | ||
| 1); | ||
| declare(ticks=1// test | ||
| ); | ||
| declare(ticks=1)// test | ||
| ; | ||
| declare(ticks=1);// test |
52 changes: 52 additions & 0 deletions
52
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.4.inc.fixed
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare(ticks=1); | ||
| declare/* test */(ticks=1); | ||
| declare(/* test */ticks=1); | ||
| declare(ticks/* test */=1); | ||
| declare(ticks=/* test */1); | ||
| declare(ticks=1/* test */); | ||
| declare(ticks=1)/* test */; | ||
| declare(ticks=1);/* test */ | ||
| declare// test | ||
| (ticks=1); | ||
| declare(// test | ||
| ticks=1); | ||
| declare(ticks// test | ||
| =1); | ||
| declare(ticks=// test | ||
| 1); | ||
| declare(ticks=1// test | ||
| ); | ||
| declare(ticks=1)// test | ||
| ; | ||
| declare(ticks=1);// test |
23 changes: 23 additions & 0 deletions
23
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.5.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php declare(strict_types=1); ?> | ||
| The line above is correct. The line below should complain that it's not the first line. | ||
| <?php declare(strict_types=1); ?> | ||
|
|
||
| This line should complain. It's included because the optional semicolon is missing here. | ||
| <?php declare(strict_types=1) ?> | ||
|
|
||
| This should complain that all three parts are not on the first line of the file. | ||
| <?php | ||
| declare(strict_types=1); | ||
| ?> | ||
|
|
||
| This is fine because it's not strict_types. | ||
| <?php declare(ticks=1); ?> | ||
|
|
||
| These can be automatically fixed because there is an incorect number of spaces | ||
| between the end of the declare statement and the closing PHP tag. | ||
| <?php declare(ticks=1)?> | ||
| <?php declare(ticks=1) ?> | ||
| <?php declare(ticks=1)/* test */?> | ||
|
|
||
| This is missing its closing PHP tag. It should be the last test in this file. | ||
| <?php declare(strict_types=1); |
22 changes: 22 additions & 0 deletions
22
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.5.inc.fixed
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php declare(strict_types=1); ?> | ||
| The line above is correct. The line below should complain that it's not the first line. | ||
| <?php declare(strict_types=1); ?> | ||
|
|
||
| This line should complain. It's included because the optional semicolon is missing here. | ||
| <?php declare(strict_types=1) ?> | ||
|
|
||
| This should complain that all three parts are not on the first line of the file. | ||
| <?php | ||
| declare(strict_types=1); ?> | ||
|
|
||
| This is fine because it's not strict_types. | ||
| <?php declare(ticks=1); ?> | ||
|
|
||
| These can be automatically fixed because there is an incorect number of spaces | ||
| between the end of the declare statement and the closing PHP tag. | ||
| <?php declare(ticks=1) ?> | ||
| <?php declare(ticks=1) ?> | ||
| <?php declare(ticks=1)/* test */?> | ||
|
|
||
| This is missing its closing PHP tag. It should be the last test in this file. | ||
| <?php declare(strict_types=1); |
3 changes: 3 additions & 0 deletions
3
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.6.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Parse error. Missing opening parenthesis. | ||
| declare |
3 changes: 3 additions & 0 deletions
3
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.7.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Parse error. Missing closing parenthesis. | ||
| declare( |
3 changes: 3 additions & 0 deletions
3
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.8.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Parse error. Missing directive. | ||
| declare() |
3 changes: 3 additions & 0 deletions
3
src/Standards/PSR12/Tests/Files/DeclareStatementUnitTest.9.inc
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Parse error. Missing equals sign. | ||
| declare(ticks) |
This file contains hidden or 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy of
src/Standards/Generic/Tests/PHP/RequireStrictTypesUnitTest.5.incto ensure that the sniff does not act on line 6.