| 1 |
package Analizo::Metric::AverageNumberOfParameters; |
| 2 |
use strict; |
| 3 |
use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); |
| 4 |
use Statistics::Descriptive; |
| 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 |
__PACKAGE__->mk_accessors(qw( model )); |
| 28 |
|
| 29 |
sub new { |
| 30 |
my ($package, %args) = @_; |
| 31 |
my @instance_variables = ( |
| 32 |
model => $args{model} |
| 33 |
); |
| 34 |
return bless { @instance_variables }, $package; |
| 35 |
} |
| 36 |
|
| 37 |
sub description { |
| 38 |
return "Average Number of Parameters per Method"; |
| 39 |
} |
| 40 |
|
| 41 |
sub calculate { |
| 42 |
my ($self, $module) = @_; |
| 43 |
|
| 44 |
my @functions = $self->model->functions($module); |
| 45 |
if (scalar(@functions) == 0) { |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
my $statisticalCalculator = Statistics::Descriptive::Full->new(); |
| 50 |
for my $function (@functions) { |
| 51 |
$statisticalCalculator->add_data($self->model->{parameters}->{$function} || 0); |
| 52 |
} |
| 53 |
|
| 54 |
return $statisticalCalculator->mean(); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
1; |
| 59 |
|