-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (49 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*!
* Copyright (C) 2017 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/code-sniper/graphs/contributors
* @url http://glayzzle.com
*/
import Report from './src/report';
import Session from './src/session';
import Visitor from './src/visitor';
import phpParser from 'php-parser';
/**
* Main class for handling parsing
*/
export default class Sniper {
constructor(options) {
this.setOptions(options ? options : {});
}
/**
*
*/
setOptions(options) {
this.options = options;
this.clear();
return this;
}
/**
* Clean up current report informations
*/
clear() {
this.parser = new phpParser(
'parser' in this.options ? this.options.parser : null
);
this.report = new Report();
this.session = new Session();
this.visitor = new Visitor(this);
return this;
}
/**
* Gets the php-parser instance in order to manually parse things
*/
getParser() {
return this.parser;
}
/**
* Parses the current file and returns its AST
*/
parseFile(filename, buffer) {
return this.parser.parseCode(buffer, filename);
}
}