Skip to content

Commit f315b1d

Browse files
committed
Pass options array to export method instead of the whole class
1 parent 5ef29b9 commit f315b1d

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

PHPCtags.class.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ class PHPCtags
77

88
private $mParser;
99

10-
private $mOptions;
11-
12-
public function __construct($file, $options=array())
10+
public function __construct($file)
1311
{
1412
//@todo Check for existence
1513
$this->mFile = $file;
@@ -23,7 +21,6 @@ public function __construct($file, $options=array())
2321
'i' => 'interface',
2422
);
2523
$this->mParser = new PHPParser_Parser(new PHPParser_Lexer);
26-
$this->mOptions = $options;
2724
}
2825

2926
private function getNodeAccess($node)
@@ -143,7 +140,7 @@ private function struct($node, $parent=array())
143140
return $structs;
144141
}
145142

146-
private function render($structs)
143+
private function render($structs, $options)
147144
{
148145
$str = '';
149146
$lines = file($this->mFile);
@@ -159,37 +156,37 @@ private function render($structs)
159156

160157
$str .= "\t" . $this->mFile;
161158

162-
if ($this->mOptions['excmd'] == 'number') {
159+
if ($options['excmd'] == 'number') {
163160
$str .= "\t" . $struct['line'];
164161
} else { //excmd == 'mixed' or 'pattern', default behavior
165162
$str .= "\t" . "/^" . rtrim($lines[$struct['line'] - 1], "\n") . "$/";
166163
}
167164

168-
if ($this->mOptions['format'] == 1) {
165+
if ($options['format'] == 1) {
169166
$str .= "\n";
170167
continue;
171168
}
172169

173170
$str .= ";\"";
174171

175172
#field=k, kind of tag as single letter
176-
if (in_array('k', $this->mOptions['fields'])) {
177-
in_array('z', $this->mOptions['fields']) && $str .= "kind:";
173+
if (in_array('k', $options['fields'])) {
174+
in_array('z', $options['fields']) && $str .= "kind:";
178175
$str .= "\t" . $struct['kind'];
179176
} else
180177
#field=K, kind of tag as fullname
181-
if (in_array('K', $this->mOptions['fields'])) {
182-
in_array('z', $this->mOptions['fields']) && $str .= "kind:";
178+
if (in_array('K', $options['fields'])) {
179+
in_array('z', $options['fields']) && $str .= "kind:";
183180
$str .= "\t" . $this->mKinds[$struct['kind']];
184181
}
185182

186183
#field=n
187-
if (in_array('n', $this->mOptions['fields'])) {
184+
if (in_array('n', $options['fields'])) {
188185
$str .= "\t" . "line:" . $struct['line'];
189186
}
190187

191188
#field=s
192-
if (in_array('s', $this->mOptions['fields']) && !empty($struct['scope'])) {
189+
if (in_array('s', $options['fields']) && !empty($struct['scope'])) {
193190
$scope = array_pop($struct['scope']);
194191
list($type,$name) = each($scope);
195192
switch ($type) {
@@ -206,7 +203,7 @@ private function render($structs)
206203
}
207204

208205
#field=a
209-
if (in_array('a', $this->mOptions['fields']) && !empty($struct['access'])) {
206+
if (in_array('a', $options['fields']) && !empty($struct['access'])) {
210207
$str .= "\t" . "access:" . $struct['access'];
211208
}
212209

@@ -215,9 +212,9 @@ private function render($structs)
215212
return $str;
216213
}
217214

218-
public function export()
215+
public function export($options)
219216
{
220217
$structs = $this->struct($this->mParser->parse(file_get_contents($this->mFile)));
221-
echo $this->render($structs);
218+
echo $this->render($structs,$options);
222219
}
223220
}

phpctags

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ if(isset($options['fields'])) {
3737
$options['fields'] = array('k','s');
3838
}
3939

40-
$ctags = new PHPCtags($file, $options);
41-
$ctags->export();
40+
$ctags = new PHPCtags($file);
41+
$ctags->export($options);

tests/PHPCtagsTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ class PHPCtagsTest extends PHPUnit_Framework_TestCase
1515
*/
1616
protected function setUp()
1717
{
18-
$options = array(
19-
'excmd' => 'pattern',
20-
'fields' => array('n','k','s','S','a'),
21-
'format' => 2,
22-
);
23-
24-
$this->object = new PHPCtags(__DIR__ . '/PHPCtagsTest.example.php', $options);
18+
$this->object = new PHPCtags(__DIR__ . '/PHPCtagsTest.example.php');
2519
}
2620

2721
/**
@@ -37,7 +31,13 @@ protected function tearDown()
3731
*/
3832
public function testExport()
3933
{
40-
$this->object->export();
34+
$options = array(
35+
'excmd' => 'pattern',
36+
'fields' => array('n','k','s','S','a'),
37+
'format' => 2,
38+
);
39+
40+
$this->object->export($options);
4141
}
4242

4343
}

0 commit comments

Comments
 (0)