@@ -25,29 +25,30 @@ class scanner {
25
25
*/
26
26
private $ files = [];
27
27
28
- /**
29
- * List of file extension to process.
30
- *
31
- * @var array
32
- */
33
- private $ extensions = ['php ' ];
28
+ /**
29
+ * List of file extension(s) to process.
30
+ *
31
+ * @var array
32
+ */
33
+ private $ extensions = ['php ' ];
34
34
35
35
/**
36
36
* Main Constructor
37
37
*
38
38
* @access public
39
39
* @param string Project file or folder
40
+ * @param array [Optional] Array of allowed file extensions.
40
41
* @return void
41
42
*/
42
- public function __construct ($ projectPath , Array $ extensions = null ) {
43
+ public function __construct ($ projectPath , $ extensions = null ) {
43
44
if (empty ($ projectPath )) {
44
45
throw new \Exception (__METHOD__ .": Project path given was empty. " );
45
46
}
46
47
$ this ->projectPath = $ projectPath ;
47
48
48
- if (!is_null ($ extensions )) {
49
- $ this ->extensions = $ extensions ;
50
- }
49
+ if (!is_null ($ extensions )) {
50
+ $ this ->setFileExtensions ( $ extensions) ;
51
+ }
51
52
52
53
$ this ->recursiveScan ($ this ->projectPath );
53
54
reset ($ this ->files );
@@ -75,8 +76,8 @@ private function recursiveScan($startFolder) {
75
76
if (is_dir ($ path )) {
76
77
$ this ->recursiveScan ($ path );
77
78
} else {
78
- $ fileExtension = pathinfo ($ content , PATHINFO_EXTENSION );
79
- if (strlen ($ fileExtension ) == 0 || !in_array ($ fileExtension , $ this ->extensions )) {
79
+ $ fileExtension = pathinfo ($ content , PATHINFO_EXTENSION );
80
+ if (strlen ($ fileExtension ) == 0 || !in_array ($ fileExtension , $ this ->getFileExtensions () )) {
80
81
continue ;
81
82
}
82
83
$ this ->files [] = $ path ;
@@ -114,27 +115,28 @@ public function getCurrentFilePath() {
114
115
return current ($ this ->files );
115
116
}
116
117
117
- /**
118
- * Sets the file extensions to be considered as PHP file. Ex:
119
- *
120
- * array('php', 'inc')
121
- *
122
- * Do NOT include the dot before the extension
123
- *
124
- * @access public
125
- * @param array $ extensions
126
- */
127
- public function setFileExtensions (Array $ extensions ) {
128
- $ this ->extensions = $ extensions ;
129
- }
118
+ /**
119
+ * Sets the file extensions to be considered as PHP file. Ex:
120
+ *
121
+ * array('php', 'inc')
122
+ *
123
+ * Do NOT include the dot before the extension
124
+ *
125
+ * @access public
126
+ * @param array Allowed file extensions
127
+ */
128
+ public function setFileExtensions (array $ extensions ) {
129
+ $ this ->extensions = $ extensions ;
130
+ }
130
131
131
- /**
132
- * Gets the list of extensions to be considered PHP files when scanning
133
- *
134
- * @return array File extensions to be considered as PHP files
135
- */
136
- public function getFileExtensions () {
137
- return $ this ->extensions ;
138
- }
132
+ /**
133
+ * Gets the list of extensions to be considered PHP files when scanning
134
+ *
135
+ * @access public
136
+ * @return array File extensions to be considered as PHP files.
137
+ */
138
+ public function getFileExtensions () {
139
+ return (array ) $ this ->extensions ;
140
+ }
139
141
}
140
142
?>
0 commit comments