File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ <documentation title =" File Permissions" >
2
+ <standard >
3
+ <![CDATA[
4
+ Files should not be executable.
5
+ ]]>
6
+ </standard >
7
+ </documentation >
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Tests that files are not executable.
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 \Sniffs \Files ;
11
+
12
+ use PHP_CodeSniffer \Sniffs \Sniff ;
13
+ use PHP_CodeSniffer \Files \File ;
14
+
15
+ class FileExtensionSniff implements Sniff
16
+ {
17
+ /**
18
+ * Returns an array of tokens this test wants to listen for.
19
+ *
20
+ * @return array
21
+ */
22
+ public function register ()
23
+ {
24
+ return [T_OPEN_TAG ];
25
+
26
+ }//end register()
27
+
28
+
29
+ /**
30
+ * Processes this test, when one of its tokens is encountered.
31
+ *
32
+ * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
33
+ * @param int $stackPtr The position of the current token in the
34
+ * stack passed in $tokens.
35
+ *
36
+ * @return int
37
+ */
38
+ public function process (File $ phpcsFile , $ stackPtr )
39
+ {
40
+ $ perms = fileperms ($ phpcsFile ->getFilename ());
41
+
42
+ if ($ perms & 0x0040 || $ perms & 0x0008 || $ perms & 0x0001 ) {
43
+ $ error = "A PHP file must not be executable " ;
44
+ $ phpcsFile ->addError ($ error , $ stackPtr , 'Executable ' );
45
+ }
46
+
47
+ // Ignore the rest of the file.
48
+ return ($ phpcsFile ->numTokens + 1 );
49
+
50
+ }//end process()
51
+
52
+
53
+ }//end class
You can’t perform that action at this time.
0 commit comments