@@ -47,88 +47,92 @@ function get_wp_files( $directory ) {
4747function parse_files ( $ files , $ root ) {
4848 $ output = array ();
4949
50- foreach ( $ files as $ filename ) {
51- // echo "\n\e[90mRunning file '\e[35m{$filename}\e[m\n";
52- $ file = new File_Reflector ( $ filename );
53-
54- $ path = ltrim ( substr ( $ filename , strlen ( $ root ) ), DIRECTORY_SEPARATOR );
55- $ file ->setFilename ( $ path );
56-
57- $ file ->process ();
50+ try {
51+ foreach ( $ files as $ filename ) {
52+ $ file = new File_Reflector ( $ filename );
5853
59- // TODO proper exporter
60- $ out = array (
61- 'file ' => export_docblock ( $ file ),
62- 'path ' => str_replace ( DIRECTORY_SEPARATOR , '/ ' , $ file ->getFilename () ),
63- 'root ' => $ root ,
64- );
54+ $ path = ltrim ( substr ( $ filename , strlen ( $ root ) ), DIRECTORY_SEPARATOR );
55+ $ file ->setFilename ( $ path );
6556
66- if ( ! empty ( $ file ->uses ) ) {
67- $ out ['uses ' ] = export_uses ( $ file ->uses );
68- }
57+ $ file ->process ();
6958
70- foreach ( $ file -> getIncludes () as $ include ) {
71- $ out[ ' includes ' ][] = array (
72- 'name ' => $ include -> getName ( ),
73- 'line ' => $ include -> getLineNumber ( ),
74- 'type ' => $ include -> getType () ,
59+ // TODO proper exporter
60+ $ out = array (
61+ 'file ' => export_docblock ( $ file ),
62+ 'path ' => str_replace ( DIRECTORY_SEPARATOR , ' / ' , $ file -> getFilename () ),
63+ 'root ' => $ root ,
7564 );
76- }
7765
78- foreach ( $ file ->getConstants () as $ constant ) {
79- $ out ['constants ' ][] = array (
80- 'name ' => $ constant ->getShortName (),
81- 'line ' => $ constant ->getLineNumber (),
82- 'value ' => $ constant ->getValue (),
83- );
84- }
66+ if ( ! empty ( $ file ->uses ) ) {
67+ $ out ['uses ' ] = export_uses ( $ file ->uses );
68+ }
8569
86- if ( ! empty ( $ file ->uses ['hooks ' ] ) ) {
87- $ out ['hooks ' ] = export_hooks ( $ file ->uses ['hooks ' ] );
88- }
70+ foreach ( $ file ->getIncludes () as $ include ) {
71+ $ out ['includes ' ][] = array (
72+ 'name ' => $ include ->getName (),
73+ 'line ' => $ include ->getLineNumber (),
74+ 'type ' => $ include ->getType (),
75+ );
76+ }
8977
90- foreach ( $ file ->getFunctions () as $ function ) {
91- $ func = array (
92- 'name ' => $ function ->getShortName (),
93- 'namespace ' => $ function ->getNamespace (),
94- 'aliases ' => $ function ->getNamespaceAliases (),
95- 'line ' => $ function ->getLineNumber (),
96- 'end_line ' => $ function ->getNode ()->getAttribute ( 'endLine ' ),
97- 'arguments ' => export_arguments ( $ function ->getArguments () ),
98- 'doc ' => export_docblock ( $ function ),
99- 'hooks ' => array (),
100- );
78+ foreach ( $ file ->getConstants () as $ constant ) {
79+ $ out ['constants ' ][] = array (
80+ 'name ' => $ constant ->getShortName (),
81+ 'line ' => $ constant ->getLineNumber (),
82+ 'value ' => $ constant ->getValue (),
83+ );
84+ }
10185
102- if ( ! empty ( $ function ->uses ) ) {
103- $ func ['uses ' ] = export_uses ( $ function ->uses );
86+ if ( ! empty ( $ file ->uses ['hooks ' ] ) ) {
87+ $ out ['hooks ' ] = export_hooks ( $ file ->uses ['hooks ' ] );
88+ }
10489
105- if ( ! empty ( $ function ->uses ['hooks ' ] ) ) {
106- $ func ['hooks ' ] = export_hooks ( $ function ->uses ['hooks ' ] );
90+ foreach ( $ file ->getFunctions () as $ function ) {
91+ $ func = array (
92+ 'name ' => $ function ->getShortName (),
93+ 'namespace ' => $ function ->getNamespace (),
94+ 'aliases ' => $ function ->getNamespaceAliases (),
95+ 'line ' => $ function ->getLineNumber (),
96+ 'end_line ' => $ function ->getNode ()->getAttribute ( 'endLine ' ),
97+ 'arguments ' => export_arguments ( $ function ->getArguments () ),
98+ 'doc ' => export_docblock ( $ function ),
99+ 'hooks ' => array (),
100+ );
101+
102+ if ( ! empty ( $ function ->uses ) ) {
103+ $ func ['uses ' ] = export_uses ( $ function ->uses );
104+
105+ if ( ! empty ( $ function ->uses ['hooks ' ] ) ) {
106+ $ func ['hooks ' ] = export_hooks ( $ function ->uses ['hooks ' ] );
107+ }
107108 }
108- }
109109
110- $ out ['functions ' ][] = $ func ;
111- }
110+ $ out ['functions ' ][] = $ func ;
111+ }
112112
113- foreach ( $ file ->getClasses () as $ class ) {
114- $ class_data = array (
115- 'name ' => $ class ->getShortName (),
116- 'namespace ' => $ class ->getNamespace (),
117- 'line ' => $ class ->getLineNumber (),
118- 'end_line ' => $ class ->getNode ()->getAttribute ( 'endLine ' ),
119- 'final ' => $ class ->isFinal (),
120- 'abstract ' => $ class ->isAbstract (),
121- 'extends ' => $ class ->getParentClass (),
122- 'implements ' => $ class ->getInterfaces (),
123- 'properties ' => export_properties ( $ class ->getProperties () ),
124- 'methods ' => export_methods ( $ class ->getMethods () ),
125- 'doc ' => export_docblock ( $ class ),
126- );
113+ foreach ( $ file ->getClasses () as $ class ) {
114+ $ class_data = array (
115+ 'name ' => $ class ->getShortName (),
116+ 'namespace ' => $ class ->getNamespace (),
117+ 'line ' => $ class ->getLineNumber (),
118+ 'end_line ' => $ class ->getNode ()->getAttribute ( 'endLine ' ),
119+ 'final ' => $ class ->isFinal (),
120+ 'abstract ' => $ class ->isAbstract (),
121+ 'extends ' => $ class ->getParentClass (),
122+ 'implements ' => $ class ->getInterfaces (),
123+ 'properties ' => export_properties ( $ class ->getProperties () ),
124+ 'methods ' => export_methods ( $ class ->getMethods () ),
125+ 'doc ' => export_docblock ( $ class ),
126+ );
127+
128+ $ out ['classes ' ][] = $ class_data ;
129+ }
127130
128- $ out [ ' classes ' ][] = $ class_data ;
131+ $ output [] = $ out ;
129132 }
130-
131- $ output [] = $ out ;
133+ } catch ( \Exception | \Error $ e ) {
134+ error_log ( \sprintf ( 'Error processing file [%s]: %s ' , $ filename , $ e ->getMessage () ) );
135+ throw $ e ;
132136 }
133137
134138 return $ output ;
0 commit comments