Skip to content

Commit 60f8a47

Browse files
committed
Add default file extensions
This adds default file extensions so files are always filtered by at least `php`, `inc`, and `module`.
1 parent 6f2231c commit 60f8a47

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

.codeclimate.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ engines:
55
enabled: true
66
config:
77
file_extensions: "php"
8-
standard: "PSR1,PSR2"
98
ratings:
109
paths:
1110
- "**.php"

Runner.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
class Runner
66
{
7+
const DEFAULT_EXTENSIONS = array("php", "inc", "module");
8+
79
private $config;
810
private $server;
911

@@ -29,16 +31,10 @@ public function queueDirectory($dir, $prefix = '')
2931
public function queueWithIncludePaths() {
3032
foreach ($this->config['include_paths'] as $f) {
3133
if ($f !== '.' and $f !== '..') {
32-
33-
if (is_dir("$f")) {
34+
if (is_dir("/code$f")) {
3435
$this->queuePaths("$f", "$f/");
35-
continue;
36-
}
37-
38-
if (isset($this->config['config']['file_extensions'])) {
39-
$this->filterByExtension($f);
4036
} else {
41-
$this->server->addwork(array("$f"));
37+
$this->filterByExtension($f);
4238
}
4339
}
4440
}
@@ -55,28 +51,32 @@ public function queuePaths($dir, $prefix = '', $exclusions = []) {
5551
if ($f !== '.' and $f !== '..') {
5652
if (is_dir("$dir/$f")) {
5753
$this->queuePaths("$dir/$f", "$prefix$f/", $exclusions);
58-
continue;
59-
}
60-
61-
if (isset($this->config['config']['file_extensions'])) {
62-
$this->filterByExtension($f, $prefix);
6354
} else {
64-
$prefix = ltrim($prefix, "\\/");
65-
$this->server->addwork(array("$prefix$f"));
55+
$this->filterByExtension($f, $prefix);
6656
}
6757
}
6858
}
6959
}
7060

7161
public function filterByExtension($f, $prefix = '') {
7262
foreach (explode(",", $this->config['config']['file_extensions']) as $file_extension) {
73-
if (S::create($f)->endsWith("." . $file_extension)) {
63+
if (S::create($f)->endsWith($file_extension)) {
7464
$prefix = ltrim($prefix, "\\/");
7565
$this->server->addwork(array("$prefix$f"));
7666
}
7767
}
7868
}
7969

70+
private function fileExtensions() {
71+
$extensions = $this->config['config']['file_extensions'];
72+
73+
if (empty($extensions)) {
74+
return self::DEFAULT_EXTENSIONS;
75+
} else {
76+
return explode(",", $extensions);
77+
}
78+
}
79+
8080
public function run($files)
8181
{
8282
$resultFile = tempnam(sys_get_temp_dir(), 'phpcodesniffer');

0 commit comments

Comments
 (0)