Analizo/Metric/LackOfCohesionOfMethods.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 2 / 2 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 33.3% 1 / 3 totaltotal 95.5% 43 / 45 CC 5 SCAR 11.0
CC
5
Cov
100%
calculate
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« Analizo/Batch/Job.pm ↑ Summary Analizo.pm »
1 package Analizo::Metric::LackOfCohesionOfMethods;
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use parent qw(Class::Accessor::Fast Analizo::ModuleMetric);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Analizo::Metric::LackOfCohesionOfMethods - Lack of Cohesion of Methods (LCOM4) metric
9  
10 =head1 DESCRIPTION
11  
12 The metric calculation is based on the following article and calculates the
13 cohesion of the class.
14  
15 Article:
16  
17 M. Hitz and B. Montazeri, "Measuring coupling and cohesion in
18 object-oriented systems," in Proceedings of the International. Symposium on
19 Applied Corporate Computing, 1995.
20 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.409.4862
21  
22 The LCOM4 value for a module is the number of connected components of an
23 undirected graph, where the nodes are the module's subroutines (methods,
24 functions etc.), and the edges indicate that two subroutines use at least one
25 attribute/variable in common, or that one subroutines calls the other. These
26 connected components represent independent parts of a module, and modules
27 that have more than one of them have independent, distinct responsibilities.
28  
29 You can see a study using the LCOM4 metric on the following paper:
30  
31 Terceiro, Antonio, et al. "Understanding structural complexity evolution: A
32 quantitative analysis." Software Maintenance and Reengineering (CSMR), 2012
33 16th European Conference on. IEEE, 2012. NBR 6023
34 http://ieeexplore.ieee.org/abstract/document/6178856/
35  
36 For a comparative study on the various LCOM1, LCOM2, LCOM3, LCOM4 and LCOM5
37 see:
38  
39 Kaur, Taranjeet, and Rupinder Kaur. "Comparison of various lacks of Cohesion
40 Metrics." International Journal of Computer Trends and Technology (IJCTT)
41 4.5 (2013). NBR 6023
42 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.686.2543
43  
44 =cut
45  
46 22 __PACKAGE__->mk_accessors(qw( model graph ));
47  
48 19 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
49 19 my ($package, %args) = @_;
50 my @instance_variables = (
51 model => $args{model},
52 19 graph => Graph->new,
53 );
54 19 return bless { @instance_variables }, $package;
55 }
56  
57 4 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod undocumented
58 4 return "Lack of Cohesion of Methods";
59 }
60  
61 13 ▶sub calculate {
Subroutine calculate: called CC=5 SCAR=16.1
Pod undocumented
62 13 my ($self, $module) = @_;
63 13 my $graph = Graph->new;
64 13 my @functions = $self->model->functions($module);
65 13 my @variables = $self->model->variables($module);
66 13 for my $function (@functions) {
67 28 $graph->add_vertex($function);
68 28 for my $used (keys(%{$self->model->calls->{$function}})) {
69 # only include in the graph functions and variables that are inside the module.
70 27 ▶ if ((grep { $_ eq $used } @functions) || (grep { $_ eq $used } @variables)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $used;} @functions or grep {$_ eq $used;} @variables) 19 8 27
Condition100%3/3
grep {$_ eq $used;} @functions or grep {$_ eq $used;} @variables
l!l&&r!l&&!r
3168
MC/DC100%2/2
grep {$_ eq $used;} @functions or grep {$_ eq $used;} @variables
grep {$_ eq $used;} @functions grep {$_ eq $used;} @variables
Truth table100%3/3
A or B
A= grep {$_ eq $used;} @functionsB= grep {$_ eq $used;} @variables
ABresult
1X1
011
000
71 19 $graph->add_edge($function, $used);
72 }
73 }
74 }
75 13 my @components = $graph->weakly_connected_components;
76 13 return scalar @components;
77 }
78  
79 22 1;
80  
« Analizo/Batch/Job.pm ↑ Summary Analizo.pm »