-
Notifications
You must be signed in to change notification settings - Fork 15
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
Allow parsing mixed HTML and PHP #234
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d6c6539
Add test for mixed html and php
sirbrillig 0146335
Consider html and closing tags to be empty tokens
sirbrillig 7191e41
Remove explicit return type to support PHP 5.6
sirbrillig d3ae74c
Add additional test for sniff codes for closing tags fixture
sirbrillig 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
This file contains 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,31 @@ | ||
<?php | ||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
||
class ClosingPhpTagsTest extends BaseTestCase { | ||
public function testVariableWarningsWhenClosingTagsAreUsed() { | ||
$fixtureFile = $this->getFixture('ClosingPhpTagsFixture.php'); | ||
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); | ||
$phpcsFile->process(); | ||
$lines = $this->getWarningLineNumbersFromFile($phpcsFile); | ||
$expectedWarnings = [ | ||
6, | ||
8, | ||
13, | ||
16, | ||
]; | ||
$this->assertEquals($expectedWarnings, $lines); | ||
} | ||
|
||
public function testVariableWarningsHaveCorrectSniffCodesWhenClosingTagsAreUsed() { | ||
$fixtureFile = $this->getFixture('ClosingPhpTagsFixture.php'); | ||
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); | ||
$phpcsFile->process(); | ||
$warnings = $phpcsFile->getWarnings(); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[6][1][0]['source']); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[8][6][0]['source']); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[13][1][0]['source']); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[16][6][0]['source']); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Tests/VariableAnalysisSniff/fixtures/ClosingPhpTagsFixture.php
This file contains 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,18 @@ | ||
<html> | ||
<h1>Page Title</h1> | ||
<?php | ||
$foo = 'hello'; | ||
$blue = 'hello'; | ||
$bar = 'bye'; // unused variable | ||
echo $foo; | ||
echo $baz; // undefined variable | ||
?> | ||
<p>More stuff</p> | ||
<?php | ||
$foo2 = 'hello'; | ||
$bar2 = 'bye'; // unused variable | ||
echo $foo2; | ||
echo $blue; | ||
echo $baz2; // undefined variable | ||
?> | ||
</html> |
This file contains 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
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.
Array functions like
array_merge()
andarray_values()
are "expensive".Changing it to the above will be more efficient performance + memory-use-wise.
You could even choose to optimize it further like this:
It's not as if this compound array will change at any time during the run.
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.
Oh! Good to know. I reduced how often this function is called in #236 but I made #237 to make sure I remember to clean this up.