Skip to content

Commit

Permalink
Address more reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin committed Aug 11, 2019
1 parent 6e17293 commit efe3f05
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Standards/Generic/Sniffs/Files/FilePermissionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public function process(File $phpcsFile, $stackPtr)
$perms = fileperms($phpcsFile->getFilename());

if (($perms & 0x0040) !== 0 || ($perms & 0x0008) !== 0 || ($perms & 0x0001) !== 0) {
$error = "A PHP file should not be executable";
$phpcsFile->addError($error, $stackPtr, 'Executable');
$error = "A PHP file should not be executable. Found file permission set to %s.";
$data = [substr(sprintf('%o', $perms), -4)];
$phpcsFile->addError($error, 0, 'Executable', $data);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
57 changes: 57 additions & 0 deletions src/Standards/Generic/Tests/Files/FilePermissionsUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Unit test class for the FilePermissions sniff.
*
* @author Matthew Peveler <matt.peveler@gmail.com>
* @copyright 2019 Matthew Peveler
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Standards\Generic\Tests\Files;

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

class FilePermissionsUnitTest extends AbstractSniffUnitTest
{


/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getErrorList($testFile='')
{
switch ($testFile) {
case 'FilePermissionsUnitTest.2.inc':
return [1 => 1];
default:
return [];
}//end switch

}//end getErrorList()


/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList($testFile='')
{
return [];

}//end getWarningList()


}//end class

0 comments on commit efe3f05

Please sign in to comment.