Analizo/Metric/NumberOfChildren.pm

filter: Statementstmt 100% 20 / 20 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 33.3% 1 / 3 totaltotal 93.5% 29 / 31 CC 3 SCAR 5.6
CC
3
Cov
100%
calculate
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« Analizo/ModuleMetric.pm ↑ Summary Analizo/Metric/AverageCycloComplexity.pm »
1 package Analizo::Metric::NumberOfChildren;
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  
5  
6 =head1 NAME
7  
8 Analizo::Metric::NumberOfChildren - Number of Children (NOC) metric
9  
10 =head1 DESCRIPTION
11  
12 The metric calculation is based on the following article and calculates the
13 number of immediate subclasses subordinate to a class in the hierarchy.
14  
15 Article: I<Software Quality Metrics for Object-Oriented Environments> by Linda
16 H. Rosenberg and Lawrence E. Hyatt.
17  
18 See the paragraph about Number of Children in the article:
19  
20 The number of children is the number of immediate subclasses subordinate to a
21 class in the hierarchy. It is an indicator of the potential influence a class
22 can have on the design and on the system. The greater the number of children,
23 the greater the likelihood of improper abstraction of the parent and may be a
24 case of misuse of subclassing. But the greater the number of children, the
25 greater the reusability since inheritance is a form of reuse. If a class has a
26 large number of children, it may require more testing of the methods of that
27 class, thus increase the testing time.
28  
29 =cut
30  
31 21 __PACKAGE__->mk_accessors(qw( model ));
32  
33 15 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34 15 my ($package, %args) = @_;
35 my @instance_variables = (
36 model => $args{model}
37 15 );
38 15 return bless { @instance_variables }, $package;
39 }
40  
41 4 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod undocumented
42 4 return "Number of Children";
43 }
44  
45 17 ▶sub calculate {
Subroutine calculate: called CC=3 SCAR=11.0
Pod undocumented
46 17 my ($self, $module) = @_;
47  
48 17 my $number_of_children = 0;
49 17 for my $other_module ($self->model->module_names) {
50 52 ▶ $number_of_children++ if ($self->_module_parent_of_other($module, $other_module));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_module_parent_of_other($module, $other_module) 6 46 52
51 }
52 17 return $number_of_children;
53 }
54  
55 52 ▶sub _module_parent_of_other {
Subroutine _module_parent_of_other: called CC=1 SCAR=0.0
56 52 my ($self, $module, $other_module) = @_;
57 52 return grep {$_ eq $module} $self->model->inheritance($other_module);
58 }
59  
60 21 1;
61  
« Analizo/ModuleMetric.pm ↑ Summary Analizo/Metric/AverageCycloComplexity.pm »