Skip to content

Commit 34cec6f

Browse files
committed
Clean up code style to K&R/OTB style. Fix a couple bugs with empty() return value.
1 parent de12dae commit 34cec6f

File tree

3 files changed

+49
-44
lines changed

3 files changed

+49
-44
lines changed

classes/options.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ class options {
7878
'syntax'
7979
]
8080
],
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-
]
81+
'x' => [
82+
'option' => self::OPTION_OPTIONAL,
83+
'value' => self::VALUE_REQUIRED,
84+
'comment' => 'File extensions to include when scanning a directory.',
85+
'description' => 'A comma separated list of file extensions to consider as PHP files. Defaults to "php"',
86+
'example' => '-x="php,inc"',
87+
'comma_delimited' => true
88+
]
8889
];
8990

9091
/**
@@ -191,9 +192,11 @@ private function parseOption($rawOption) {
191192
if ($validOptions[$option]['value'] === self::VALUE_REQUIRED && !isset($value)) {
192193
die("The option `{$option}` requires a value, but none was given.\n");
193194
}
194-
if (isset($validOptions[$option]['allowed'])) {
195+
if (isset($validOptions[$option]['allowed']) || (isset($validOptions[$option]['comma_delimited']) && $validOptions[$option]['comma_delimited'] == true)) {
195196
$value = explode(',', $value);
196197
$value = array_map('trim', $value);
198+
}
199+
if (isset($validOptions[$option]['allowed'])) {
197200
foreach ($value as $_value) {
198201
if (!in_array($_value, $validOptions[$option]['allowed'])) {
199202
die("The value `{$_value}` for `{$option}` is not valid.\n");

classes/scanner.php

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +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'];
28+
/**
29+
* List of file extension(s) to process.
30+
*
31+
* @var array
32+
*/
33+
private $extensions = ['php'];
3434

3535
/**
3636
* Main Constructor
3737
*
3838
* @access public
3939
* @param string Project file or folder
40+
* @param array [Optional] Array of allowed file extensions.
4041
* @return void
4142
*/
42-
public function __construct($projectPath, Array $extensions = null) {
43+
public function __construct($projectPath, $extensions = null) {
4344
if (empty($projectPath)) {
4445
throw new \Exception(__METHOD__.": Project path given was empty.");
4546
}
4647
$this->projectPath = $projectPath;
4748

48-
if (!is_null($extensions)) {
49-
$this->extensions = $extensions;
50-
}
49+
if (!is_null($extensions)) {
50+
$this->setFileExtensions($extensions);
51+
}
5152

5253
$this->recursiveScan($this->projectPath);
5354
reset($this->files);
@@ -75,8 +76,8 @@ private function recursiveScan($startFolder) {
7576
if (is_dir($path)) {
7677
$this->recursiveScan($path);
7778
} 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())) {
8081
continue;
8182
}
8283
$this->files[] = $path;
@@ -114,27 +115,28 @@ public function getCurrentFilePath() {
114115
return current($this->files);
115116
}
116117

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+
}
130131

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+
}
139141
}
140142
?>

mar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ public function __construct() {
7272

7373
$this->tests = new tests($this->options->getOption('t'));
7474

75-
if (!empty($this->options->getOption('php'))) {
75+
$phpBinary = $this->options->getOption('php');
76+
if (!empty($phpBinary)) {
7677
$this->tests->setPHPBinaryPath($this->options->getOption('php'));
7778
}
7879

7980
$start = microtime(true);
8081

81-
$extensions = !empty($this->options->getOption('x')) ? explode(',', $this->options->getOption('x')) : null;
82-
$this->scanner = new scanner($this->projectPath, $extensions);
82+
$this->scanner = new scanner($this->projectPath, (is_array($this->options->getOption('x')) ? $this->options->getOption('x') : null));
8383

8484

8585
$this->run();

0 commit comments

Comments
 (0)