Skip to content

Commit eb40797

Browse files
committed
configure CI
1 parent 4c254ef commit eb40797

12 files changed

Lines changed: 254 additions & 45 deletions

File tree

.coveralls.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repo_token: 1vgToo4k8mxqrZ2TY3j5048GbYAoWAB9B

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/node_modules/
2+
/test/cache/*.json
3+
/coverage/

.istanbul.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
verbose: false
2+
instrumentation:
3+
root: .
4+
extensions:
5+
- .js
6+
default-excludes: true
7+
excludes: []
8+
embed-source: false
9+
variable: __coverage__
10+
compact: true
11+
preserve-comments: false
12+
complete-copy: false
13+
save-baseline: false
14+
baseline-file: ./coverage/coverage-baseline.json
15+
include-all-sources: false
16+
include-pid: false
17+
reporting:
18+
print: summary
19+
reports:
20+
- lcov
21+
dir: ./coverage
22+
watermarks:
23+
statements: [50, 80]
24+
lines: [50, 80]
25+
functions: [50, 80]
26+
branches: [50, 80]
27+
report-config:
28+
clover: {file: clover.xml}
29+
cobertura: {file: cobertura-coverage.xml}
30+
json: {file: coverage-final.json}
31+
json-summary: {file: coverage-summary.json}
32+
lcovonly: {file: lcov.info}
33+
teamcity: {file: null, blockName: Code Coverage Summary}
34+
text: {file: null, maxCols: 0}
35+
text-lcov: {file: lcov.info}
36+
text-summary: {file: null}
37+
hooks:
38+
hook-run-in-context: false
39+
post-require-hook: null
40+
handle-sigint: false
41+
check:
42+
global:
43+
statements: 0
44+
lines: 0
45+
branches: 0
46+
functions: 0
47+
excludes: []
48+
each:
49+
statements: 0
50+
lines: 0
51+
branches: 0
52+
functions: 0
53+
excludes: []

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/docs/
2+
/test/

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- '0.12'
4+
notifications:
5+
email: false
6+
script: npm run test
7+
after_success: cat /home/travis/build/glayzzle/php-reflection/coverage/lcov.info | /home/travis/build/glayzzle/php-reflection/node_modules/coveralls/bin/coveralls.js

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Enables to parse php files and from AST extracts code informations (namespaces, classes, functions ...)",
55
"main": "src/repository.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "node --stack-size=5000 node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- test/*"
88
},
99
"repository": {
1010
"type": "git",
@@ -29,6 +29,9 @@
2929
"devDependencies": {
3030
"grunt": "^1.0.1",
3131
"grunt-contrib-watch": "^1.0.0",
32-
"grunt-documentation": "^1.2.1"
32+
"grunt-documentation": "^1.2.1",
33+
"istanbul": "^0.4.5",
34+
"mocha": "^3.2.0",
35+
"should": "^11.1.1"
3336
}
3437
}

src/file.js

Lines changed: 115 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,130 @@ var comment = require('./comment');
2020
* @property {Date} version Last time when the file was parsed
2121
* @property {integer} size The total file size
2222
* @property {String} name The filename
23-
* @property {namespace[]} namespaces {@link NAMESPACE.md|:link:} List of namespaces
24-
* @property {declare[]} declares {@link DECLARE.md|:link:} List of declare nodes
25-
* @property {reference[]} links {@link REFERENCE.md|:link:} List of references (constants, classes, interfaces...)
26-
* @property {external[]} externals {@link EXTERNAL.md|:link:} List of external references
23+
* @property {node[]} nodes {@link NODE.md|:link:} List of nodes
2724
* @property {error} error Error node
2825
*/
2926
var file = block.extends(function file(repository, name, ast) {
3027
this.repository = repository;
3128
this.version = new Date();
3229
this.size = 0;
3330
this.name = name;
34-
this.namespaces = [];
35-
this.declares = [];
36-
this.links = [];
37-
this.externals = [];
31+
this.nodes = [];
3832
this.error = null;
39-
this._scopes = [];
4033

4134
// super constructor
4235
block.apply(this, [this, ast]);
4336
});
4437

38+
/**
39+
* Generic lookup by node type
40+
* @return {node[]}
41+
*/
42+
file.prototype.getByType = function(type) {
43+
// build type index
44+
if (!this._indexNodeType) {
45+
this._indexNodeType = {};
46+
var result = [];
47+
for(var i = 0; i < this.nodes.length; i++) {
48+
var item = this.nodes[i];
49+
if (!this._indexNodeType.hasOwnProperty(item.type)) {
50+
this._indexNodeType[item.type] = [];
51+
}
52+
this._indexNodeType[item.type].push(item);
53+
}
54+
}
55+
return this._indexNodeType.hasOwnProperty(type) ?
56+
this._indexNodeType[type] : []
57+
;
58+
};
59+
60+
/**
61+
* Generic lookup by node name
62+
* @return {node[]}
63+
*/
64+
file.prototype.getByName = function(type, name) {
65+
if (!this._indexNodeName) {
66+
this._indexNodeName = {};
67+
}
68+
69+
// build names index
70+
if (!this._indexNodeName.hasOwnProperty(type)) {
71+
var nodes = this.getByType(type);
72+
var cache = {};
73+
for(var i = 0; i < nodes.length; i++) {
74+
var item = nodes[i];
75+
var index = null;
76+
if (item.hasOwnProperty('fullName')) {
77+
index = item.fullName;
78+
} else if (item.hasOwnProperty('name')) {
79+
index = item.name;
80+
}
81+
if (index) {
82+
if (!cache.hasOwnProperty(index)) {
83+
cache[index] = [];
84+
}
85+
cache[index].push(item);
86+
}
87+
}
88+
this._indexNodeName[type] = cache;
89+
}
90+
91+
return this._indexNodeType[type].hasOwnProperty(name) ?
92+
this._indexNodeType[type][name] : []
93+
;
94+
};
95+
96+
/**
97+
* Generic lookup by node name
98+
* @return {node|null}
99+
*/
100+
file.prototype.getFirstByName = function(type, name) {
101+
var result = this.getByName(type, name);
102+
return result.length > 0 ? result[0] : null;
103+
};
104+
105+
/**
106+
* @return {namespace[]}
107+
*/
108+
file.prototype.getNamespaces = function() {
109+
return this.getByType('namespace');
110+
};
111+
112+
/**
113+
* @return {class[]}
114+
*/
115+
file.prototype.getClasses = function() {
116+
return this.getByType('class');
117+
};
118+
119+
/**
120+
* @return {interfaces[]}
121+
*/
122+
file.prototype.getInterfaces = function() {
123+
return this.getByType('class');
124+
};
125+
126+
/**
127+
* @return {external[]}
128+
*/
129+
file.prototype.getIncludes = function() {
130+
return this.getByType('external');
131+
};
132+
133+
/**
134+
* @return {class}
135+
*/
136+
file.prototype.getClass = function(name) {
137+
return this.getFirstByName('class', name);
138+
};
139+
140+
/**
141+
* @return {class}
142+
*/
143+
file.prototype.getNamespace = function(name) {
144+
return this.getFirstByName('namespace', name);
145+
};
146+
45147
/**
46148
* @protected Consumes the current ast node
47149
*/
@@ -63,7 +165,7 @@ file.prototype.consume = function(ast) {
63165
ast[1].forEach(function(item) {
64166
var type = block.getASTType(item);
65167

66-
if (type) {
168+
if (type) {/*
67169
if (type === 'declare') {
68170
this.declares.push(
69171
new declare(this, item)
@@ -82,15 +184,15 @@ file.prototype.consume = function(ast) {
82184
root.push(doc);
83185
}
84186
root.push(item);
85-
}
187+
}*/
86188
}
87189
}.bind(this));
88190

89191
// create an empty namespace
90192
if (root.length > 0) {
91-
new namespace(this, [
193+
/*new namespace(this, [
92194
'namespace', [''], root
93-
]);
195+
]);*/
94196
}
95197
};
96198

src/repository.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var fs = require('fs');
8+
var path = require('path');
89
var parser = require('php-parser');
910
var file = require('./file');
1011

@@ -22,8 +23,9 @@ var file = require('./file');
2223
*
2324
* @public @constructor {repository}
2425
*/
25-
var repository = function() {
26+
var repository = function(directory) {
2627
this.files = {};
28+
this.directory = path.resolve(directory);
2729
};
2830

2931
/**
@@ -37,7 +39,9 @@ repository.prototype.parse = function(filename, encoding) {
3739
if (!this.files.hasOwnProperty(filename)) {
3840
var self = this;
3941
this.files[filename] = new Promise(function(done, reject) {
40-
fs.readFile(filename, encoding, function(err, data) {
42+
fs.readFile(
43+
path.join(self.directory, filename),
44+
encoding, function(err, data) {
4145
if (!err) {
4246
try {
4347
var reader = new parser({
@@ -154,22 +158,26 @@ repository.prototype.cache = function(data) {
154158
// sets the data
155159
this.files = {};
156160
if (data) {
161+
this.directory = data.directory;
157162
// creating files from structure
158-
for(var name in data) {
163+
for(var name in data.files) {
159164
this.files[name] = file.import(data[name]);
160165
}
161166
// update object links
162-
for(var name in files) {
167+
for(var name in this.files) {
163168
this.files[name].import();
164169
}
165170
}
166171
return this;
167172
} else {
168173
// gets the data
169-
var result = {};
174+
var result = {
175+
directory: this.directory,
176+
files: {}
177+
};
170178
for(var name in this.files) {
171179
if (this.files[name] instanceof file) {
172-
result[name] = this.files[name].export();
180+
result.files[name] = this.files[name].export();
173181
}
174182
}
175183
return result;
@@ -206,7 +214,9 @@ repository.prototype.refresh = function(filename, encoding) {
206214
return this.files[name];
207215
}
208216
this.files[filename] = new Promise(function(done, reject) {
209-
fs.readFile(filename, encoding, function(err, data) {
217+
fs.readFile(
218+
path.join(self.directory, filename),
219+
encoding, function(err, data) {
210220
// @todo
211221
});
212222
});

test/cache/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Cache folder
2+
3+
This folder contains caching JSON files for tests

test/index.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)