12
12
use function array_filter ;
13
13
use function count ;
14
14
use function range ;
15
+ use SebastianBergmann \CodeCoverage \StaticAnalysis \Class_ ;
16
+ use SebastianBergmann \CodeCoverage \StaticAnalysis \Function_ ;
15
17
use SebastianBergmann \CodeCoverage \StaticAnalysis \LinesOfCode ;
18
+ use SebastianBergmann \CodeCoverage \StaticAnalysis \Method ;
19
+ use SebastianBergmann \CodeCoverage \StaticAnalysis \Trait_ ;
16
20
17
21
/**
18
22
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
19
23
*
20
- * @phpstan-import-type CodeUnitFunctionType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
21
- * @phpstan-import-type CodeUnitMethodType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
22
- * @phpstan-import-type CodeUnitClassType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
23
- * @phpstan-import-type CodeUnitTraitType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
24
24
* @phpstan-import-type LinesType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
25
25
*
26
26
* @phpstan-type ProcessedFunctionType = array{
@@ -129,15 +129,15 @@ final class File extends AbstractNode
129
129
private ?int $ numTestedFunctions = null ;
130
130
131
131
/**
132
- * @var array<int, array|array{0: CodeUnitClassType , 1: string}|array{0: CodeUnitFunctionType }|array{0: CodeUnitTraitType , 1: string}>
132
+ * @var array<int, array|array{0: Class_ , 1: string}|array{0: Function_ }|array{0: Trait_ , 1: string}>
133
133
*/
134
134
private array $ codeUnitsByLine = [];
135
135
136
136
/**
137
137
* @param array<int, ?list<non-empty-string>> $lineCoverageData
138
- * @param array<string, CodeUnitClassType> $classes
139
- * @param array<string, CodeUnitTraitType> $traits
140
- * @param array<string, CodeUnitFunctionType> $functions
138
+ * @param array<string, Class_> $classes
139
+ * @param array<string, Trait_> $traits
140
+ * @param array<string, Function_> $functions
141
141
*/
142
142
public function __construct (string $ name , AbstractNode $ parent , array $ lineCoverageData , array $ functionCoverageData , array $ testData , array $ classes , array $ traits , array $ functions , LinesOfCode $ linesOfCode )
143
143
{
@@ -355,9 +355,9 @@ public function numberOfTestedFunctions(): int
355
355
}
356
356
357
357
/**
358
- * @param array<string, CodeUnitClassType > $classes
359
- * @param array<string, CodeUnitTraitType > $traits
360
- * @param array<string, CodeUnitFunctionType > $functions
358
+ * @param array<string, Class_ > $classes
359
+ * @param array<string, Trait_ > $traits
360
+ * @param array<string, Function_ > $functions
361
361
*/
362
362
private function calculateStatistics (array $ classes , array $ traits , array $ functions ): void
363
363
{
@@ -462,7 +462,7 @@ private function calculateStatistics(array $classes, array $traits, array $funct
462
462
}
463
463
464
464
/**
465
- * @param array<string, CodeUnitClassType > $classes
465
+ * @param array<string, Class_ > $classes
466
466
*/
467
467
private function processClasses (array $ classes ): void
468
468
{
@@ -471,9 +471,9 @@ private function processClasses(array $classes): void
471
471
foreach ($ classes as $ className => $ class ) {
472
472
$ this ->classes [$ className ] = [
473
473
'className ' => $ className ,
474
- 'namespace ' => $ class[ ' namespace ' ] ,
474
+ 'namespace ' => $ class-> namespace () ,
475
475
'methods ' => [],
476
- 'startLine ' => $ class[ ' startLine ' ] ,
476
+ 'startLine ' => $ class-> startLine () ,
477
477
'executableLines ' => 0 ,
478
478
'executedLines ' => 0 ,
479
479
'executableBranches ' => 0 ,
@@ -483,11 +483,11 @@ private function processClasses(array $classes): void
483
483
'ccn ' => 0 ,
484
484
'coverage ' => 0 ,
485
485
'crap ' => 0 ,
486
- 'link ' => $ link . $ class[ ' startLine ' ] ,
486
+ 'link ' => $ link . $ class-> startLine () ,
487
487
];
488
488
489
- foreach ($ class[ ' methods ' ] as $ methodName => $ method ) {
490
- $ methodData = $ this ->newMethod ($ className , $ methodName , $ method , $ link );
489
+ foreach ($ class-> methods () as $ methodName => $ method ) {
490
+ $ methodData = $ this ->newMethod ($ className , $ method , $ link );
491
491
$ this ->classes [$ className ]['methods ' ][$ methodName ] = $ methodData ;
492
492
493
493
$ this ->classes [$ className ]['executableBranches ' ] += $ methodData ['executableBranches ' ];
@@ -500,7 +500,7 @@ private function processClasses(array $classes): void
500
500
$ this ->numExecutablePaths += $ methodData ['executablePaths ' ];
501
501
$ this ->numExecutedPaths += $ methodData ['executedPaths ' ];
502
502
503
- foreach (range ($ method[ ' startLine ' ] , $ method[ ' endLine ' ] ) as $ lineNumber ) {
503
+ foreach (range ($ method-> startLine () , $ method-> endLine () ) as $ lineNumber ) {
504
504
$ this ->codeUnitsByLine [$ lineNumber ] = [
505
505
&$ this ->classes [$ className ],
506
506
&$ this ->classes [$ className ]['methods ' ][$ methodName ],
@@ -511,7 +511,7 @@ private function processClasses(array $classes): void
511
511
}
512
512
513
513
/**
514
- * @param array<string, CodeUnitTraitType > $traits
514
+ * @param array<string, Trait_ > $traits
515
515
*/
516
516
private function processTraits (array $ traits ): void
517
517
{
@@ -520,9 +520,9 @@ private function processTraits(array $traits): void
520
520
foreach ($ traits as $ traitName => $ trait ) {
521
521
$ this ->traits [$ traitName ] = [
522
522
'traitName ' => $ traitName ,
523
- 'namespace ' => $ trait[ ' namespace ' ] ,
523
+ 'namespace ' => $ trait-> namespace () ,
524
524
'methods ' => [],
525
- 'startLine ' => $ trait[ ' startLine ' ] ,
525
+ 'startLine ' => $ trait-> startLine () ,
526
526
'executableLines ' => 0 ,
527
527
'executedLines ' => 0 ,
528
528
'executableBranches ' => 0 ,
@@ -532,11 +532,11 @@ private function processTraits(array $traits): void
532
532
'ccn ' => 0 ,
533
533
'coverage ' => 0 ,
534
534
'crap ' => 0 ,
535
- 'link ' => $ link . $ trait[ ' startLine ' ] ,
535
+ 'link ' => $ link . $ trait-> startLine () ,
536
536
];
537
537
538
- foreach ($ trait[ ' methods ' ] as $ methodName => $ method ) {
539
- $ methodData = $ this ->newMethod ($ traitName , $ methodName , $ method , $ link );
538
+ foreach ($ trait-> methods () as $ methodName => $ method ) {
539
+ $ methodData = $ this ->newMethod ($ traitName , $ method , $ link );
540
540
$ this ->traits [$ traitName ]['methods ' ][$ methodName ] = $ methodData ;
541
541
542
542
$ this ->traits [$ traitName ]['executableBranches ' ] += $ methodData ['executableBranches ' ];
@@ -549,7 +549,7 @@ private function processTraits(array $traits): void
549
549
$ this ->numExecutablePaths += $ methodData ['executablePaths ' ];
550
550
$ this ->numExecutedPaths += $ methodData ['executedPaths ' ];
551
551
552
- foreach (range ($ method[ ' startLine ' ] , $ method[ ' endLine ' ] ) as $ lineNumber ) {
552
+ foreach (range ($ method-> startLine () , $ method-> endLine () ) as $ lineNumber ) {
553
553
$ this ->codeUnitsByLine [$ lineNumber ] = [
554
554
&$ this ->traits [$ traitName ],
555
555
&$ this ->traits [$ traitName ]['methods ' ][$ methodName ],
@@ -560,7 +560,7 @@ private function processTraits(array $traits): void
560
560
}
561
561
562
562
/**
563
- * @param array<string, CodeUnitFunctionType > $functions
563
+ * @param array<string, Function_ > $functions
564
564
*/
565
565
private function processFunctions (array $ functions ): void
566
566
{
@@ -569,23 +569,23 @@ private function processFunctions(array $functions): void
569
569
foreach ($ functions as $ functionName => $ function ) {
570
570
$ this ->functions [$ functionName ] = [
571
571
'functionName ' => $ functionName ,
572
- 'namespace ' => $ function[ ' namespace ' ] ,
573
- 'signature ' => $ function[ ' signature ' ] ,
574
- 'startLine ' => $ function[ ' startLine ' ] ,
575
- 'endLine ' => $ function[ ' endLine ' ] ,
572
+ 'namespace ' => $ function-> namespace () ,
573
+ 'signature ' => $ function-> signature () ,
574
+ 'startLine ' => $ function-> startLine () ,
575
+ 'endLine ' => $ function-> endLine () ,
576
576
'executableLines ' => 0 ,
577
577
'executedLines ' => 0 ,
578
578
'executableBranches ' => 0 ,
579
579
'executedBranches ' => 0 ,
580
580
'executablePaths ' => 0 ,
581
581
'executedPaths ' => 0 ,
582
- 'ccn ' => $ function[ ' ccn ' ] ,
582
+ 'ccn ' => $ function-> cyclomaticComplexity () ,
583
583
'coverage ' => 0 ,
584
584
'crap ' => 0 ,
585
- 'link ' => $ link . $ function[ ' startLine ' ] ,
585
+ 'link ' => $ link . $ function-> startLine () ,
586
586
];
587
587
588
- foreach (range ($ function[ ' startLine ' ] , $ function[ ' endLine ' ] ) as $ lineNumber ) {
588
+ foreach (range ($ function-> startLine () , $ function-> endLine () ) as $ lineNumber ) {
589
589
$ this ->codeUnitsByLine [$ lineNumber ] = [&$ this ->functions [$ functionName ]];
590
590
}
591
591
@@ -629,31 +629,29 @@ static function (array $path)
629
629
}
630
630
631
631
/**
632
- * @param CodeUnitMethodType $method
633
- *
634
632
* @return ProcessedMethodType
635
633
*/
636
- private function newMethod (string $ className , string $ methodName , array $ method , string $ link ): array
634
+ private function newMethod (string $ className , Method $ method , string $ link ): array
637
635
{
638
636
$ methodData = [
639
- 'methodName ' => $ methodName ,
640
- 'visibility ' => $ method[ ' visibility ' ] ,
641
- 'signature ' => $ method[ ' signature ' ] ,
642
- 'startLine ' => $ method[ ' startLine ' ] ,
643
- 'endLine ' => $ method[ ' endLine ' ] ,
637
+ 'methodName ' => $ method -> name () ,
638
+ 'visibility ' => $ method-> visibility () ,
639
+ 'signature ' => $ method-> signature () ,
640
+ 'startLine ' => $ method-> startLine () ,
641
+ 'endLine ' => $ method-> endLine () ,
644
642
'executableLines ' => 0 ,
645
643
'executedLines ' => 0 ,
646
644
'executableBranches ' => 0 ,
647
645
'executedBranches ' => 0 ,
648
646
'executablePaths ' => 0 ,
649
647
'executedPaths ' => 0 ,
650
- 'ccn ' => $ method[ ' ccn ' ] ,
648
+ 'ccn ' => $ method-> cyclomaticComplexity () ,
651
649
'coverage ' => 0 ,
652
650
'crap ' => 0 ,
653
- 'link ' => $ link . $ method[ ' startLine ' ] ,
651
+ 'link ' => $ link . $ method-> startLine () ,
654
652
];
655
653
656
- $ key = $ className . '-> ' . $ methodName ;
654
+ $ key = $ className . '-> ' . $ method -> name () ;
657
655
658
656
if (isset ($ this ->functionCoverageData [$ key ]['branches ' ])) {
659
657
$ methodData ['executableBranches ' ] = count (
0 commit comments