11<?php
22
3+ namespace Combodo \iTop \Setup \ModuleDiscovery ;
4+
35use Combodo \iTop \PhpParser \Evaluation \PhpExpressionEvaluator ;
6+ use CoreException ;
7+ use Exception ;
8+ use ParseError ;
9+ use PhpParser \Error ;
10+ use PhpParser \Node \Expr \StaticCall ;
11+ use PhpParser \Node \Stmt \Expression ;
12+ use PhpParser \Node \Stmt \If_ ;
13+ use PhpParser \ParserFactory ;
14+ use PhpParser \Node \Expr \Assign ;
15+ use \PhpParser \Node \Stmt \ElseIf_ ;
16+ use PhpParser \Node \Expr \Array_ ;
17+ use PhpParser \Node \Scalar \String_ ;
18+ use PhpParser \Node \Arg ;
419
520require_once __DIR__ . '/ModuleFileReaderException.php ' ;
621require_once APPROOT . 'sources/PhpParser/Evaluation/PhpExpressionEvaluator.php ' ;
@@ -47,24 +62,24 @@ public function ReadModuleFileInformation(string $sModuleFilePath) : array
4762 {
4863 try
4964 {
50- $ oParser = (new \ PhpParser \ ParserFactory ())->createForNewestSupportedVersion ();
65+ $ oParser = (new ParserFactory ())->createForNewestSupportedVersion ();
5166 $ aNodes = $ oParser ->parse (file_get_contents ($ sModuleFilePath ));
5267 }
53- catch (PhpParser \ Error $ e ) {
54- throw new \ ModuleFileReaderException ($ e ->getMessage (), 0 , $ e , $ sModuleFilePath );
68+ catch (Error $ e ) {
69+ throw new ModuleFileReaderException ($ e ->getMessage (), 0 , $ e , $ sModuleFilePath );
5570 }
5671
5772 try {
5873 foreach ($ aNodes as $ sKey => $ oNode ) {
59- if ($ oNode instanceof \ PhpParser \ Node \ Stmt \ Expression) {
74+ if ($ oNode instanceof Expression) {
6075 $ aModuleInfo = $ this ->GetModuleInformationFromAddModuleCall ($ sModuleFilePath , $ oNode );
6176 if (! is_null ($ aModuleInfo )){
6277 $ this ->CompleteModuleInfoWithFilePath ($ aModuleInfo );
6378 return $ aModuleInfo ;
6479 }
6580 }
6681
67- if ($ oNode instanceof PhpParser \ Node \ Stmt \ If_) {
82+ if ($ oNode instanceof If_) {
6883 $ aModuleInfo = $ this ->GetModuleInformationFromIf ($ sModuleFilePath , $ oNode );
6984 if (! is_null ($ aModuleInfo )){
7085 $ this ->CompleteModuleInfoWithFilePath ($ aModuleInfo );
@@ -186,17 +201,17 @@ public function GetAndCheckModuleInstallerClass($aModuleInfo) : ?string
186201 * @param \PhpParser\Node\Expr\Assign $oAssignation
187202 *
188203 * @return array|null
189- * @throws \ ModuleFileReaderException
204+ * @throws ModuleFileReaderException
190205 */
191206 private function GetModuleInformationFromAddModuleCall (string $ sModuleFilePath , \PhpParser \Node \Stmt \Expression $ oExpression ) : ?array
192207 {
193208 /** @var Assign $oAssignation */
194209 $ oAssignation = $ oExpression ->expr ;
195- if (false === ($ oAssignation instanceof PhpParser \ Node \ Expr \ StaticCall)) {
210+ if (false === ($ oAssignation instanceof StaticCall)) {
196211 return null ;
197212 }
198213
199- /** @var PhpParser\Node\Expr\ StaticCall $oAssignation */
214+ /** @var StaticCall $oAssignation */
200215
201216 if ("SetupWebPage " !== $ oAssignation ?->class?->name) {
202217 return null ;
@@ -212,24 +227,24 @@ private function GetModuleInformationFromAddModuleCall(string $sModuleFilePath,
212227 }
213228
214229 $ oModuleId = $ aArgs [1 ];
215- if (false === ($ oModuleId instanceof PhpParser \ Node \ Arg)) {
230+ if (false === ($ oModuleId instanceof Arg)) {
216231 throw new ModuleFileReaderException ("2nd parameter to SetupWebPage::AddModule call issue: " . get_class ($ oModuleId ), 0 , null , $ sModuleFilePath );
217232 }
218233
219- /** @var PhpParser\Node\ Arg $oModuleId */
220- if (false === ($ oModuleId ->value instanceof PhpParser \ Node \ Scalar \ String_)) {
234+ /** @var Arg $oModuleId */
235+ if (false === ($ oModuleId ->value instanceof String_)) {
221236 throw new ModuleFileReaderException ("2nd parameter to SetupWebPage::AddModule not a string: " . get_class ($ oModuleId ->value ), 0 , null , $ sModuleFilePath );
222237 }
223238
224239 $ sModuleId = $ this ->oPhpExpressionEvaluator ->EvaluateExpression ($ oModuleId ->value );
225240
226241 $ oModuleConfigInfo = $ aArgs [2 ];
227- if (false === ($ oModuleConfigInfo instanceof PhpParser \ Node \ Arg)) {
242+ if (false === ($ oModuleConfigInfo instanceof Arg)) {
228243 throw new ModuleFileReaderException ("3rd parameter to SetupWebPage::AddModule call issue: " . get_class ($ oModuleConfigInfo ), 0 , null , $ sModuleFilePath );
229244 }
230245
231- /** @var PhpParser\Node\ Arg $oModuleConfigInfo */
232- if (false === ($ oModuleConfigInfo ->value instanceof PhpParser \ Node \ Expr \ Array_)) {
246+ /** @var Arg $oModuleConfigInfo */
247+ if (false === ($ oModuleConfigInfo ->value instanceof Array_)) {
233248 throw new ModuleFileReaderException ("3rd parameter to SetupWebPage::AddModule not an array: " . get_class ($ oModuleConfigInfo ->value ), 0 , null , $ sModuleFilePath );
234249 }
235250
@@ -251,14 +266,14 @@ private function GetModuleInformationFromAddModuleCall(string $sModuleFilePath,
251266 * @param \PhpParser\Node\Stmt\If_ $oNode
252267 *
253268 * @return array|null
254- * @throws \ ModuleFileReaderException
269+ * @throws ModuleFileReaderException
255270 */
256271 private function GetModuleInformationFromIf (string $ sModuleFilePath , \PhpParser \Node \Stmt \If_ $ oNode ) : ?array
257272 {
258273 $ bCondition = $ this ->oPhpExpressionEvaluator ->EvaluateExpression ($ oNode ->cond );
259274 if ($ bCondition ) {
260275 foreach ($ oNode ->stmts as $ oSubNode ) {
261- if ($ oSubNode instanceof \ PhpParser \ Node \ Stmt \ Expression) {
276+ if ($ oSubNode instanceof Expression) {
262277 $ aModuleConfig = $ this ->GetModuleInformationFromAddModuleCall ($ sModuleFilePath , $ oSubNode );
263278 if (!is_null ($ aModuleConfig )) {
264279 return $ aModuleConfig ;
@@ -271,7 +286,7 @@ private function GetModuleInformationFromIf(string $sModuleFilePath, \PhpParser\
271286
272287 if (! is_null ($ oNode ->elseifs )) {
273288 foreach ($ oNode ->elseifs as $ oElseIfSubNode ) {
274- /** @var \PhpParser\Node\Stmt\ ElseIf_ $oElseIfSubNode */
289+ /** @var ElseIf_ $oElseIfSubNode */
275290 $ bCondition = $ this ->oPhpExpressionEvaluator ->EvaluateExpression ($ oElseIfSubNode ->cond );
276291 if ($ bCondition ) {
277292 return $ this ->GetModuleConfigurationFromStatement ($ sModuleFilePath , $ oElseIfSubNode ->stmts );
@@ -289,7 +304,7 @@ private function GetModuleInformationFromIf(string $sModuleFilePath, \PhpParser\
289304 private function GetModuleConfigurationFromStatement (string $ sModuleFilePath , array $ aStmts ) : ?array
290305 {
291306 foreach ($ aStmts as $ oSubNode ) {
292- if ($ oSubNode instanceof \ PhpParser \ Node \ Stmt \ Expression) {
307+ if ($ oSubNode instanceof Expression) {
293308 $ aModuleConfig = $ this ->GetModuleInformationFromAddModuleCall ($ sModuleFilePath , $ oSubNode );
294309 if (!is_null ($ aModuleConfig )) {
295310 return $ aModuleConfig ;
0 commit comments