| 1 | package Analizo::Metric::AverageNumberOfParameters; | ||||||||||||
| 2 | 21 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 21 | ▶ | use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 21 | ▶ | use Statistics::Descriptive; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | =head1 NAME | ||||||||||||
| 7 | |||||||||||||
| 8 | Analizo::Metric::AverageNumberOfParamters - Average Number of Parameters (ANPM) metric | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||
| 11 | |||||||||||||
| 12 | The metric calculation is based on the following article and calculates the | ||||||||||||
| 13 | average of the number of parameters of the class methods. | ||||||||||||
| 14 | |||||||||||||
| 15 | Article: I<Monitoring of source code metrics in open source projects> by Paulo | ||||||||||||
| 16 | Roberto Miranda Meirelles. | ||||||||||||
| 17 | |||||||||||||
| 18 | See the adaptation of the paragraph about Average Number of Parameters per | ||||||||||||
| 19 | Class in the article: | ||||||||||||
| 20 | |||||||||||||
| 21 | "Calculates the average of parameters of the class methods. Its minimum value is zero | ||||||||||||
| 22 | and there is no upper limit to its result, but a high number of parameters may indicate | ||||||||||||
| 23 | that a method may have one more responsibility, i. e., more than one function" | ||||||||||||
| 24 | |||||||||||||
| 25 | =cut | ||||||||||||
| 26 | |||||||||||||
| 27 | 21 | __PACKAGE__->mk_accessors(qw( model )); | |||||||||||
| 28 | |||||||||||||
| 29 | 15 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 30 | 15 | my ($package, %args) = @_; | |||||||||||
| 31 | my @instance_variables = ( | ||||||||||||
| 32 | model => $args{model} | ||||||||||||
| 33 | 15 | ); | |||||||||||
| 34 | 15 | return bless { @instance_variables }, $package; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 4 | ▶ | sub description { | ||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 38 | 4 | return "Average Number of Parameters per Method"; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 9 | ▶ | sub calculate { | ||||||||||
|
Subroutine
calculate: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 42 | 9 | my ($self, $module) = @_; | |||||||||||
| 43 | |||||||||||||
| 44 | 9 | my @functions = $self->model->functions($module); | |||||||||||
| 45 | 9 | ▶ | if (scalar(@functions) == 0) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 1 | return 0; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 8 | my $statisticalCalculator = Statistics::Descriptive::Full->new(); | |||||||||||
| 50 | 8 | for my $function (@functions) { | |||||||||||
| 51 | 12 | ▶ | $statisticalCalculator->add_data($self->model->{parameters}->{$function} || 0); | ||||||||||
|
Condition100%2/2
$self->model->{'parameters'}{$function} || 0
MC/DC100%1/1
$self->model->{'parameters'}{$function} || 0
$self->model->{'parameters'}{$function}
Truth table100%2/2
A
A= $self->model->{'parameters'}{$function}
| |||||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 8 | return $statisticalCalculator->mean(); | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | |||||||||||||
| 58 | 21 | 1; | |||||||||||
| 59 | |||||||||||||