File tree Expand file tree Collapse file tree 7 files changed +86
-2
lines changed
src/Hal/Component/OOP/Reflected
Structural/HenryAndKafura Expand file tree Collapse file tree 7 files changed +86
-2
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,4 @@ provision.sh
88Makefile
99/nbproject
1010phpmetrics.yml.dist
11- log
11+ log
Original file line number Diff line number Diff line change @@ -273,6 +273,16 @@ public function getDependencies()
273273 foreach ($ this ->dependencies as $ name ) {
274274 array_push ($ dependencies , $ this ->nameResolver ->resolve ($ name , null ));
275275 }
276+
277+ // returned values
278+ $ resolver = new TypeResolver ();
279+ foreach ($ this ->returns as $ return ) {
280+ $ name = $ return ->getType ();
281+ if (!$ resolver ->isNative ($ name )) {
282+ array_push ($ dependencies , $ this ->nameResolver ->resolve ($ name , null ));
283+ }
284+ }
285+
276286 return array_unique ($ dependencies );
277287 }
278288
Original file line number Diff line number Diff line change @@ -110,7 +110,6 @@ public function providesForMethodsArgs() {
110110
111111 /**
112112 * @dataProvider provideCodeForReturns
113- * @group wip
114113 */
115114 public function testReturnsAreFound ($ expected , $ code ) {
116115 $ searcher = new Searcher ();
Original file line number Diff line number Diff line change @@ -35,4 +35,21 @@ public function testMcCaybeResultCanBeConvertedToArray() {
3535
3636 $ this ->assertArrayHasKey ('cyclomaticComplexity ' , $ array );
3737 }
38+
39+ /**
40+ * @dataProvider provideCCNPHP7
41+ * @group php7
42+ */
43+ public function testICanCountComplexityOfAnonymousClass ($ filename , $ expectedCCN ) {
44+
45+ $ loc = new McCabe (new \Hal \Component \Token \Tokenizer ());
46+ $ r = $ loc ->calculate ($ filename );
47+ $ this ->assertEquals ($ expectedCCN , $ r ->getCyclomaticComplexityNumber ());
48+ }
49+
50+ public function provideCCNPHP7 () {
51+ return array (
52+ array (__DIR__ .'/../../../../../resources/mccaybe/php7-1.php ' , 4 )
53+ );
54+ }
3855}
Original file line number Diff line number Diff line change 11<?php
22namespace Test \Hal \Metrics \Complexity \Structural \HenryAndKafura ;
3+ use Hal \Component \OOP \Extractor \ClassMap ;
4+ use Hal \Component \OOP \Extractor \Extractor ;
5+ use Hal \Component \Token \Tokenizer ;
36use Hal \Metrics \Complexity \Structural \HenryAndKafura \Coupling ;
47
58/**
@@ -57,4 +60,18 @@ public function testICanExportCoupling() {
5760 );
5861 $ this ->assertEquals ($ expected , $ this ->result ->get ('\Ns1\Class1 ' )->asArray ());
5962 }
63+
64+ public function testCouplingTakesCareOfReturnedValues () {
65+ $ filename = __DIR__ .'/../../../../../resources/coupling/f1.php ' ;
66+ $ extractor = new Extractor (new Tokenizer ());
67+ $ classmap = new ClassMap ();
68+ $ classmap ->push ($ filename , $ extractor ->extract ($ filename ));
69+ $ coupling = new Coupling ();
70+ $ this ->result = $ coupling ->calculate ($ classmap );
71+
72+ $ this ->assertEquals (0 , $ this ->result ->get ('\\ClassWhoUseAnother ' )->getAfferentCoupling ());
73+ $ this ->assertEquals (1 , $ this ->result ->get ('\\ClassWhoUseAnother ' )->getEfferentCoupling ());
74+ $ this ->assertEquals (1 , $ this ->result ->get ('\\ClassWhoIsUsed ' )->getAfferentCoupling ());
75+ $ this ->assertEquals (0 , $ this ->result ->get ('\\ClassWhoIsUsed ' )->getEfferentCoupling ());
76+ }
6077}
Original file line number Diff line number Diff line change 1+ <?php
2+ class ClassWhoUseAnother {
3+ public function demo ()
4+ {
5+ return new ClassWhoIsUsed ;
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ class A {
3+ public function foo() {
4+
5+ $ a = new class {
6+ public function bar () {
7+ if ( c1 () )
8+ f1 ();
9+ else
10+ f2 ();
11+
12+ if ( c2 () )
13+ f3 ();
14+ else
15+ f4 ();
16+ }
17+ }
18+
19+ $ b = new class {
20+ public function bar () {
21+ if ( c1 () )
22+ f1 ();
23+ else
24+ f2 ();
25+
26+ if ( c2 () )
27+ f3 ();
28+ else
29+ f4 ();
30+ }
31+ }
32+
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments