File Coverage

blib/lib/Perl/Metrics/Lite/Report/CheckStyle.pm
Criterion Covered Total %
statement 6 68 8.8
branch 0 8 0.0
condition n/a
subroutine 2 8 25.0
pod 0 6 0.0
total 8 90 8.8


line stmt bran cond sub pod time code
1             package Perl::Metrics::Lite::Report::CheckStyle;
2 1     1   1900 use strict;
  1         2  
  1         29  
3 1     1   6 use warnings;
  1         2  
  1         630  
4              
5             my $DEFAULT_MAX_SUB_LINES = 60;
6             my $DEFAULT_MAX_MCCABE_COMPLEXITY = 10;
7              
8             sub new {
9 0     0 0   my ( $class, %args ) = @_;
10 0           my $self = bless( {}, $class );
11              
12             my $max_sub_lines
13             = exists $args{max_sub_lines}
14             ? $args{max_sub_lines}
15 0 0         : $DEFAULT_MAX_SUB_LINES;
16             my $max_sub_mccabe_complexity = $args{max_sub_mccabe_complexity}
17             = exists $args{max_sub_mccabe_complexity}
18             ? $args{max_sub_mccabe_complexity}
19 0 0         : $DEFAULT_MAX_MCCABE_COMPLEXITY;
20 0           $self->{max_sub_lines} = $max_sub_lines;
21 0           $self->{max_sub_mccabe_complexity} = $max_sub_mccabe_complexity;
22 0           return $self;
23             }
24              
25             sub report {
26 0     0 0   my ( $self, $analysis ) = @_;
27              
28 0           my $sub_stats = $analysis->sub_stats;
29 0           my $checkstyle_xml = $self->create_checkstyle_xml($sub_stats);
30              
31 0           print $checkstyle_xml;
32             }
33              
34             sub create_checkstyle_xml {
35 0     0 0   my ( $self, $sub_stats ) = @_;
36              
37 0           my $xml = "";
38 0           $xml .= "\n";
39 0           foreach my $file_path ( keys %{$sub_stats} ) {
  0            
40 0           my $sub_metrics = $sub_stats->{$file_path};
41 0           $xml .= $self->file_xml_fragment( $file_path, $sub_metrics );
42             }
43 0           $xml .= "";
44 0           return $xml;
45             }
46              
47             sub file_xml_fragment {
48 0     0 0   my ( $self, $file_path, $sub_metrics ) = @_;
49              
50 0           my $xml = "";
51 0           $xml .= " \n";
52 0           foreach my $sub_metric ( @{$sub_metrics} ) {
  0            
53              
54 0 0         if ( $sub_metric->{lines} >= $self->{max_sub_lines} ) {
55 0           $xml .= $self->sub_lines_xml_fragment($sub_metric);
56             }
57              
58 0 0         if ( $sub_metric->{mccabe_complexity}
59             >= $self->{max_sub_mccabe_complexity} )
60             {
61 0           $xml .= $self->sub_mccabe_complexity_xml_fragment($sub_metric);
62             }
63             }
64              
65 0           $xml .= " ";
66 0           $xml .= "\n";
67 0           return $xml;
68             }
69              
70             sub sub_lines_xml_fragment {
71 0     0 0   my ( $self, $sub_metric ) = @_;
72 0           my $xml = "";
73 0           $xml .= ' 74 0           $xml .= $sub_metric->{line_number};
75 0           $xml .= '"';
76 0           $xml .= ' column="1"';
77 0           $xml .= ' severity="error"';
78 0           $xml .= ' message="\'';
79 0           $xml .= $sub_metric->{name};
80 0           $xml .= '\' method length is ';
81 0           $xml .= $sub_metric->{lines};
82 0           $xml .= ' lines."';
83 0           $xml
84             .= ' source="com.puppycrawl.tools.checkstyle.checks.sizes.MethodLengthCheck"/>';
85 0           $xml .= "\n";
86 0           return $xml;
87             }
88              
89             sub sub_mccabe_complexity_xml_fragment {
90 0     0 0   my ( $self, $sub_metric ) = @_;
91              
92 0           my $xml = "";
93 0           $xml .= ' 94 0           $xml .= $sub_metric->{line_number};
95 0           $xml .= '"';
96 0           $xml .= ' column="1"';
97 0           $xml .= ' severity="error"';
98 0           $xml .= ' message="\'';
99 0           $xml .= $sub_metric->{name};
100 0           $xml .= '\' method cyclomatic complexity is ';
101 0           $xml .= $sub_metric->{mccabe_complexity};
102 0           $xml .= '"';
103 0           $xml
104             .= ' source="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"/>';
105 0           $xml .= "\n";
106 0           return $xml;
107             }
108              
109             1;
110              
111             __END__