File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -397,6 +397,41 @@ private function getSignature(array $tokens, $idx)
397
397
return $ signature ;
398
398
}
399
399
400
+ /**
401
+ * @return integer
402
+ */
403
+ private function getCCN ($ tokens , $ idx )
404
+ {
405
+ $ ccn = 1 ;
406
+ $ end = $ this ->getEndTokenId ($ tokens , $ idx );
407
+
408
+ $ ccnTokens = array (
409
+ T_IF ,
410
+ T_ELSEIF ,
411
+ T_FOR ,
412
+ T_FOREACH ,
413
+ T_WHILE ,
414
+ T_CASE ,
415
+ T_CATCH ,
416
+ T_BOOLEAN_AND ,
417
+ T_LOGICAL_AND ,
418
+ T_BOOLEAN_OR ,
419
+ T_LOGICAL_OR
420
+ );
421
+ for ($ i = $ idx ; $ i <= $ end ; $ i ++) {
422
+ $ tconst = $ this ->tconst ($ tokens [$ i ]);
423
+ if (in_array ($ tconst , $ ccnTokens )) {
424
+ $ ccn ++;
425
+ }
426
+ $ tclass = $ this ->tclass ($ tokens [$ i ]);
427
+ if ($ tclass === 'PHP_Token_QUESTION_MARK ' ) {
428
+ $ ccn ++;
429
+ }
430
+ }
431
+
432
+ return $ ccn ;
433
+ }
434
+
400
435
public function tokenize () {
401
436
$ sourceCode = file_get_contents ($ this ->filename );
402
437
$ tokens = token_get_all ($ sourceCode );
@@ -474,7 +509,7 @@ public function tokenize() {
474
509
'signature ' => $ this ->getSignature ($ tokens , $ i ),
475
510
'startLine ' => $ this ->tline ($ token ),
476
511
'endLine ' => $ this ->getEndLine ($ tokens , $ i ),
477
- 'ccn ' => $ token ->getCCN (),
512
+ 'ccn ' => $ this ->getCCN ($ tokens , $ i ),
478
513
'file ' => $ this ->filename
479
514
);
480
515
You can’t perform that action at this time.
0 commit comments