-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #816 from PHPCSStandards/feature/file-getdeclarati…
…onname-hardening-against-parse-errors File::getDeclarationName(): prevent incorrect result during live coding
- Loading branch information
Showing
7 changed files
with
95 additions
and
9 deletions.
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
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,5 @@ | ||
<?php | ||
|
||
/* testLiveCoding */ | ||
// Intentional parse error. This must be the only test in the file. | ||
function // Comment. |
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,37 @@ | ||
<?php | ||
/** | ||
* Tests for the \PHP_CodeSniffer\Files\File::getDeclarationName method. | ||
* | ||
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> | ||
* @copyright 2025 PHPCSStandards Contributors | ||
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Tests\Core\File; | ||
|
||
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; | ||
|
||
/** | ||
* Tests for the \PHP_CodeSniffer\Files\File:getDeclarationName method. | ||
* | ||
* @covers \PHP_CodeSniffer\Files\File::getDeclarationName | ||
*/ | ||
final class GetDeclarationNameParseError1Test extends AbstractMethodUnitTest | ||
{ | ||
|
||
|
||
/** | ||
* Test receiving "null" in case of a parse error. | ||
* | ||
* @return void | ||
*/ | ||
public function testGetDeclarationNameNull() | ||
{ | ||
$target = $this->getTargetToken('/* testLiveCoding */', T_FUNCTION); | ||
$result = self::$phpcsFile->getDeclarationName($target); | ||
$this->assertNull($result); | ||
|
||
}//end testGetDeclarationNameNull() | ||
|
||
|
||
}//end class |
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,6 @@ | ||
<?php | ||
|
||
/* testLiveCoding */ | ||
// Intentional parse error/live coding. This must be the only test in the file. | ||
// Safeguarding that the utility method does not confuse the `string` type with a function name. | ||
$closure = function (string $param) use ($var |
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,37 @@ | ||
<?php | ||
/** | ||
* Tests for the \PHP_CodeSniffer\Files\File::getDeclarationName method. | ||
* | ||
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> | ||
* @copyright 2025 PHPCSStandards Contributors | ||
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Tests\Core\File; | ||
|
||
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; | ||
|
||
/** | ||
* Tests for the \PHP_CodeSniffer\Files\File:getDeclarationName method. | ||
* | ||
* @covers \PHP_CodeSniffer\Files\File::getDeclarationName | ||
*/ | ||
final class GetDeclarationNameParseError2Test extends AbstractMethodUnitTest | ||
{ | ||
|
||
|
||
/** | ||
* Test receiving "null" in case of a parse error. | ||
* | ||
* @return void | ||
*/ | ||
public function testGetDeclarationNameNull() | ||
{ | ||
$target = $this->getTargetToken('/* testLiveCoding */', T_FUNCTION); | ||
$result = self::$phpcsFile->getDeclarationName($target); | ||
$this->assertNull($result); | ||
|
||
}//end testGetDeclarationNameNull() | ||
|
||
|
||
}//end class |
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
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