Skip to content

Commit de12dae

Browse files
committed
Merge pull request Alexia#6 from willbonde/master
Adding support for specifyng file extensions to consider as PHP files
2 parents 38d2d9d + b9773d0 commit de12dae

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

classes/options.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ class options {
7777
'nuance',
7878
'syntax'
7979
]
80-
]
80+
],
81+
'x' => [
82+
'option' => self::OPTION_OPTIONAL,
83+
'value' => self::VALUE_REQUIRED,
84+
'comment' => 'File extensions to include when scanning directory',
85+
'description' => 'A comma separated list of file extensions to consider as PHP files. Defaults to "php"',
86+
'example' => '-x="php,inc"'
87+
]
8188
];
8289

8390
/**

classes/scanner.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,30 @@ class scanner {
2525
*/
2626
private $files = [];
2727

28+
/**
29+
* List of file extension to process.
30+
*
31+
* @var array
32+
*/
33+
private $extensions = ['php'];
34+
2835
/**
2936
* Main Constructor
3037
*
3138
* @access public
3239
* @param string Project file or folder
3340
* @return void
3441
*/
35-
public function __construct($projectPath) {
42+
public function __construct($projectPath, Array $extensions = null) {
3643
if (empty($projectPath)) {
3744
throw new \Exception(__METHOD__.": Project path given was empty.");
3845
}
3946
$this->projectPath = $projectPath;
47+
48+
if (!is_null($extensions)) {
49+
$this->extensions = $extensions;
50+
}
51+
4052
$this->recursiveScan($this->projectPath);
4153
reset($this->files);
4254
}
@@ -63,7 +75,8 @@ private function recursiveScan($startFolder) {
6375
if (is_dir($path)) {
6476
$this->recursiveScan($path);
6577
} else {
66-
if (substr($content, -4) != '.php') {
78+
$fileExtension = pathinfo($content, PATHINFO_EXTENSION);
79+
if (strlen($fileExtension) == 0 || !in_array($fileExtension, $this->extensions)) {
6780
continue;
6881
}
6982
$this->files[] = $path;
@@ -100,5 +113,28 @@ public function scanNextFile() {
100113
public function getCurrentFilePath() {
101114
return current($this->files);
102115
}
116+
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+
}
130+
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+
}
103139
}
104140
?>

mar.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ public function __construct() {
7777
}
7878

7979
$start = microtime(true);
80-
$this->scanner = new scanner($this->projectPath);
80+
81+
$extensions = !empty($this->options->getOption('x')) ? explode(',', $this->options->getOption('x')) : null;
82+
$this->scanner = new scanner($this->projectPath, $extensions);
83+
8184

8285
$this->run();
8386
$end = microtime(true);

0 commit comments

Comments
 (0)