Skip to content

Commit efe3f05

Browse files
committed
Address more reviewer comments
1 parent 6e17293 commit efe3f05

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

src/Standards/Generic/Sniffs/Files/FilePermissionsSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public function process(File $phpcsFile, $stackPtr)
4545
$perms = fileperms($phpcsFile->getFilename());
4646

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Unit test class for the FilePermissions sniff.
4+
*
5+
* @author Matthew Peveler <matt.peveler@gmail.com>
6+
* @copyright 2019 Matthew Peveler
7+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8+
*/
9+
10+
namespace PHP_CodeSniffer\Standards\Generic\Tests\Files;
11+
12+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
13+
14+
class FilePermissionsUnitTest extends AbstractSniffUnitTest
15+
{
16+
17+
18+
/**
19+
* Returns the lines where errors should occur.
20+
*
21+
* The key of the array should represent the line number and the value
22+
* should represent the number of errors that should occur on that line.
23+
*
24+
* @param string $testFile The name of the file being tested.
25+
*
26+
* @return array<int, int>
27+
*/
28+
public function getErrorList($testFile='')
29+
{
30+
switch ($testFile) {
31+
case 'FilePermissionsUnitTest.2.inc':
32+
return [1 => 1];
33+
default:
34+
return [];
35+
}//end switch
36+
37+
}//end getErrorList()
38+
39+
40+
/**
41+
* Returns the lines where warnings should occur.
42+
*
43+
* The key of the array should represent the line number and the value
44+
* should represent the number of warnings that should occur on that line.
45+
*
46+
* @param string $testFile The name of the file being tested.
47+
*
48+
* @return array<int, int>
49+
*/
50+
public function getWarningList($testFile='')
51+
{
52+
return [];
53+
54+
}//end getWarningList()
55+
56+
57+
}//end class

0 commit comments

Comments
 (0)