Analizo/GlobalMetric/ChangeCost.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 33.3% 1 / 3 totaltotal 95.3% 41 / 43 CC 4 SCAR 7.9
CC
4
Cov
100%
calculate
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« Analizo/Metric/LinesOfCode.pm ↑ Summary Analizo/Extractor.pm »
1 package Analizo::GlobalMetric::ChangeCost;
2 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 21 ▶use parent qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use List::Util qw( sum );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use Graph::TransitiveClosure::Matrix;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Analizo::GlobalMetric::ChangeCost - Change Cost global metric
10  
11 =head1 DESCRIPTION
12  
13 The metric calculation is based on the following article and calculates the
14 degree to which a change to any file causes a (potential) change to other files
15 in the system.
16  
17 Article: Exploring the Structure of Complex Software Designs: An Empirical
18 Study of Open Source and Proprietary Code by Alan MacCormack, John Rusnak and
19 Carliss Baldwin.
20  
21 See the paragraph about Change Cost in the article:
22  
23 "... characterize the structure of a design is by measuring the degree of
24 'coupling' it exhibits, as captured by the degree to which a change to any
25 single element causes a (potential) change to other elements in the system,
26 either directly or indirectly (i.e., through a chain of dependencies that exist
27 across elements).
28  
29 ... measures the percentage of elements affected, on average, when a change is
30 made to one element in the system."
31  
32 =cut
33  
34 21 __PACKAGE__->mk_accessors(qw( model ));
35  
36 39 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
37 39 my ($package, %args) = @_;
38 my @instance_variables = (
39 model => $args{model},
40 39 );
41 39 return bless { @instance_variables }, $package;
42 }
43  
44 3 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod undocumented
45 3 return "Change Cost";
46 }
47  
48 32 ▶sub calculate {
Subroutine calculate: called CC=4 SCAR=13.9
Pod undocumented
49 32 my ($self) = @_;
50 32 my $reachability_matrix = $self->model->files_graph->transitive_closure_matrix;
51 32 my @vertices = sort $reachability_matrix->vertices;
52 32 my $rows = scalar @vertices;
53 32 ▶ return unless $rows;
Branch: 1 branch
BranchTrueFalseTotal
unless $rows 31 1 32
54 1 my @fan_out = (0) x $rows;
55 1 my $n = 0;
56 1 foreach my $i (@vertices) {
57 6 foreach my $j (@vertices) {
58 36 $fan_out[$n] += $reachability_matrix->[0]->get($i, $j);
59 }
60 6 $fan_out[$n] = $fan_out[$n] / $rows;
61 6 $n++;
62 }
63 1 sprintf("%0.02f", sum(@fan_out) / $rows);
64 }
65  
66 21 1;
« Analizo/Metric/LinesOfCode.pm ↑ Summary Analizo/Extractor.pm »