| 1 | package Analizo::GlobalMetrics; | ||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use parent qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use Analizo::GlobalMetric::TotalAbstractClasses; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use Analizo::GlobalMetric::MethodsPerAbstractClass; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use Analizo::GlobalMetric::ChangeCost; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 20 | ▶ | use Statistics::Descriptive; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 20 | __PACKAGE__->mk_accessors(qw( | |||||||||||||||||||||||||||
| 13 | model | ||||||||||||||||||||||||||||
| 14 | calculators | ||||||||||||||||||||||||||||
| 15 | metric_report | ||||||||||||||||||||||||||||
| 16 | values_lists | ||||||||||||||||||||||||||||
| 17 | module_metrics_list | ||||||||||||||||||||||||||||
| 18 | )); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 35 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 35 | my ($package, %args) = @_; | |||||||||||||||||||||||||||
| 22 | my @instance_variables = ( | ||||||||||||||||||||||||||||
| 23 | model => $args{model}, | ||||||||||||||||||||||||||||
| 24 | 35 | calculators => _initialize_calculators($args{model}), | |||||||||||||||||||||||||||
| 25 | metric_report => _initialize_metric_report(), | ||||||||||||||||||||||||||||
| 26 | values_lists => {}, | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | 35 | return bless { @instance_variables }, $package; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 35 | ▶ | sub _initialize_calculators { | ||||||||||||||||||||||||||
|
Subroutine
_initialize_calculators: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 35 | my ($model) = @_; | |||||||||||||||||||||||||||
| 33 | 35 | my %calculators = ( | |||||||||||||||||||||||||||
| 34 | total_abstract_classes => Analizo::GlobalMetric::TotalAbstractClasses->new(model => $model), | ||||||||||||||||||||||||||||
| 35 | total_methods_per_abstract_class => Analizo::GlobalMetric::MethodsPerAbstractClass->new(model => $model), | ||||||||||||||||||||||||||||
| 36 | change_cost => Analizo::GlobalMetric::ChangeCost->new(model => $model), | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | 35 | return \%calculators; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 35 | ▶ | sub _initialize_metric_report { | ||||||||||||||||||||||||||
|
Subroutine
_initialize_metric_report: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 35 | my %metric_report = ( | |||||||||||||||||||||||||||
| 43 | total_modules => 0, | ||||||||||||||||||||||||||||
| 44 | total_modules_with_defined_methods => 0, | ||||||||||||||||||||||||||||
| 45 | total_modules_with_defined_attributes => 0, | ||||||||||||||||||||||||||||
| 46 | total_nom => 0, | ||||||||||||||||||||||||||||
| 47 | total_loc => 0, | ||||||||||||||||||||||||||||
| 48 | total_cof => 0 | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | 35 | return \%metric_report; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 55 | 2 | my %list = ( | |||||||||||||||||||||||||||
| 56 | total_cof => "Total Coupling Factor", | ||||||||||||||||||||||||||||
| 57 | total_modules => "Total Number of Modules", | ||||||||||||||||||||||||||||
| 58 | total_nom => "Total Number of Methods", | ||||||||||||||||||||||||||||
| 59 | total_loc => "Total Lines of Code", | ||||||||||||||||||||||||||||
| 60 | total_modules_with_defined_methods => "Total number of modules with at least one defined method", | ||||||||||||||||||||||||||||
| 61 | total_modules_with_defined_attributes => "Total number of modules with at least one defined attributes" | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | 2 | for my $metric (keys %{$self->calculators}) { | |||||||||||||||||||||||||||
| 64 | 6 | $list{$metric} = $self->calculators->{$metric}->description; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 2 | return %list; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 34 | ▶ | sub add_module_values { | ||||||||||||||||||||||||||
|
Subroutine
add_module_values: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 34 | my ($self, $values) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 34 | $self->_update_metric_report($values); | |||||||||||||||||||||||||||
| 73 | 34 | $self->_add_values_to_values_lists($values); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 34 | ▶ | sub _update_metric_report { | ||||||||||||||||||||||||||
|
Subroutine
_update_metric_report: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 77 | 34 | my ($self, $values) = @_; | |||||||||||||||||||||||||||
| 78 | 34 | $self->metric_report->{'total_modules'} += 1; | |||||||||||||||||||||||||||
| 79 | 34 | ▶ | $self->metric_report->{'total_modules_with_defined_methods'} += 1 if $values->{'nom'} > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 34 | ▶ | $self->metric_report->{'total_modules_with_defined_attributes'} += 1 if $values->{'noa'} > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 34 | $self->metric_report->{'total_nom'} += $values->{'nom'}; | |||||||||||||||||||||||||||
| 82 | 34 | $self->metric_report->{'total_loc'} += $values->{'loc'}; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 34 | ▶ | sub _add_values_to_values_lists { | ||||||||||||||||||||||||||
|
Subroutine
_add_values_to_values_lists: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 34 | my ($self, $values) = @_; | |||||||||||||||||||||||||||
| 87 | 34 | for my $metric (keys %{$values}) { | |||||||||||||||||||||||||||
| 88 | 135 | $self->_add_metric_value_to_values_list($metric, $values->{$metric}); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 135 | ▶ | sub _add_metric_value_to_values_list { | ||||||||||||||||||||||||||
|
Subroutine
_add_metric_value_to_values_list: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 93 | 135 | my ($self, $metric, $metric_value) = @_; | |||||||||||||||||||||||||||
| 94 | 135 | ▶ | if( $metric ne '_module' && $metric ne '_filename' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$metric ne "_module" and $metric ne "_filename"
MC/DC100%2/2
$metric ne "_module" and $metric ne "_filename"
$metric ne "_module"
$metric ne "_filename"
Truth table100%3/3
A and B
A= $metric ne "_module"B= $metric ne "_filename"
| |||||||||||||||||||||||||||||
| 95 | 121 | ▶ | $self->values_lists->{$metric} = [] unless ($self->values_lists->{$metric}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 121 | push @{$self->values_lists->{$metric}}, $metric_value; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 30 | ▶ | sub report { | ||||||||||||||||||||||||||
|
Subroutine
report: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 30 | my ($self) = @_; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 30 | $self->_include_metrics_from_calculators; | |||||||||||||||||||||||||||
| 105 | 30 | $self->_add_statistics; | |||||||||||||||||||||||||||
| 106 | 30 | $self->_add_total_coupling_factor; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 30 | return \%{$self->metric_report}; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 30 | ▶ | sub _include_metrics_from_calculators { | ||||||||||||||||||||||||||
|
Subroutine
_include_metrics_from_calculators: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 112 | 30 | my ($self) = @_; | |||||||||||||||||||||||||||
| 113 | 30 | for my $metric (keys %{$self->calculators}) { | |||||||||||||||||||||||||||
| 114 | 90 | $self->metric_report->{$metric} = $self->calculators->{$metric}->calculate(); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 30 | ▶ | sub _add_statistics { | ||||||||||||||||||||||||||
|
Subroutine
_add_statistics: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 119 | 30 | my ($self) = @_; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 30 | for my $metric (keys %{$self->values_lists}) { | |||||||||||||||||||||||||||
| 122 | 63 | my $statistics = Statistics::Descriptive::Full->new(); | |||||||||||||||||||||||||||
| 123 | 63 | $statistics->add_data(@{$self->values_lists->{$metric}}); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 63 | $self->_add_descriptive_statistics($metric, $statistics); | |||||||||||||||||||||||||||
| 126 | 63 | $self->_add_distributions_statistics($metric, $statistics); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 63 | ▶ | sub _add_descriptive_statistics { | ||||||||||||||||||||||||||
|
Subroutine
_add_descriptive_statistics: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 131 | 63 | my ($self, $metric, $statistics) = @_; | |||||||||||||||||||||||||||
| 132 | 63 | $self->metric_report->{$metric . "_mean"} = $statistics->mean(); | |||||||||||||||||||||||||||
| 133 | 63 | $self->metric_report->{$metric . "_mode"} = $statistics->mode(); | |||||||||||||||||||||||||||
| 134 | 63 | $self->metric_report->{$metric . "_standard_deviation"} = $statistics->standard_deviation(); | |||||||||||||||||||||||||||
| 135 | 63 | $self->metric_report->{$metric . "_sum"} = $statistics->sum(); | |||||||||||||||||||||||||||
| 136 | 63 | $self->metric_report->{$metric . "_variance"} = $statistics->variance(); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 63 | $self->metric_report->{$metric . "_quantile_min"} = $statistics->min(); #minimum | |||||||||||||||||||||||||||
| 139 | 63 | $self->metric_report->{$metric . "_quantile_lower"} = $statistics->quantile(1); #lower quartile | |||||||||||||||||||||||||||
| 140 | 63 | $self->metric_report->{$metric . "_quantile_median"} = $statistics->median(); #median | |||||||||||||||||||||||||||
| 141 | 63 | $self->metric_report->{$metric . "_quantile_upper"} = $statistics->quantile(3); #upper quartile | |||||||||||||||||||||||||||
| 142 | 63 | $self->metric_report->{$metric . "_quantile_ninety_five"} = $statistics->percentile(95); #95th percentile | |||||||||||||||||||||||||||
| 143 | 63 | $self->metric_report->{$metric . "_quantile_max"} = $statistics->max(); #maximum | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 63 | ▶ | sub _add_distributions_statistics { | ||||||||||||||||||||||||||
|
Subroutine
_add_distributions_statistics: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||
| 147 | 63 | my ($self, $metric, $statistics) = @_; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 63 | ▶ | if (($statistics->count >= 4) && ($statistics->variance() > 0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$statistics->count >= 4 and $statistics->variance > 0
MC/DC0%0/2
$statistics->count >= 4 and $statistics->variance > 0
$statistics->count >= 4
$statistics->variance > 0
Truth table66%2/3
A and B
A= $statistics->count >= 4B= $statistics->variance > 0
| |||||||||||||||||||||||||||||
| 150 | 0 | $self->metric_report->{$metric . "_kurtosis"} = $statistics->kurtosis(); | |||||||||||||||||||||||||||
| 151 | 0 | $self->metric_report->{$metric . "_skewness"} = $statistics->skewness(); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||
| 154 | 63 | $self->metric_report->{$metric . "_kurtosis"} = 0; | |||||||||||||||||||||||||||
| 155 | 63 | $self->metric_report->{$metric . "_skewness"} = 0; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 30 | ▶ | sub _add_total_coupling_factor { | ||||||||||||||||||||||||||
|
Subroutine
_add_total_coupling_factor: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 160 | 30 | my ($self) = @_; | |||||||||||||||||||||||||||
| 161 | 30 | my $total_modules = $self->metric_report->{'total_modules'}; | |||||||||||||||||||||||||||
| 162 | 30 | my $total_acc = $self->metric_report->{'acc_sum'}; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 30 | $self->metric_report->{"total_cof"} = $self->coupling_factor($total_acc, $total_modules); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 30 | ▶ | sub coupling_factor { | ||||||||||||||||||||||||||
|
Subroutine
coupling_factor: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 168 | 30 | my ($self, $total_acc, $total_modules) = @_; | |||||||||||||||||||||||||||
| 169 | 30 | ▶ | return ($total_modules > 1) ? $total_acc / _number_of_combinations($total_modules) : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 10 | ▶ | sub _number_of_combinations { | ||||||||||||||||||||||||||
|
Subroutine
_number_of_combinations: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 173 | 10 | my ($total_modules) = @_; | |||||||||||||||||||||||||||
| 174 | 10 | return $total_modules * ($total_modules - 1); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 20 | 1; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||