From 87c36672ce2a727b31e622d847f51ad923f9b32b Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Wed, 30 Jul 2003 13:46:48 +0000 Subject: [PATCH] Cleaned up code, sorted by pctg git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2120 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-web/src/PMD/Project.pm | 98 ++++++++++++++++++++++---------------- pmd-web/src/webpmd.pl | 18 +++---- 2 files changed, 65 insertions(+), 51 deletions(-) diff --git a/pmd-web/src/PMD/Project.pm b/pmd-web/src/PMD/Project.pm index 1e86ccb883..fcae18540e 100644 --- a/pmd-web/src/PMD/Project.pm +++ b/pmd-web/src/PMD/Project.pm @@ -9,6 +9,7 @@ push @EXPORT, '&getUnixName'; push @EXPORT, '&getModuleDir'; push @EXPORT, '&getSrcDir'; push @EXPORT, '&getString'; +push @EXPORT, '&getPctg'; push @EXPORT, '&getJobsFile'; push @EXPORT, '&getRptFile'; push @EXPORT, '&getRptURL'; @@ -16,54 +17,71 @@ push @EXPORT, '&getLines'; push @EXPORT, '&getLocation'; sub new { - my $self = {}; - bless($self); - if ((scalar(@_)-1) == 1) { - ($self->{LOCATION},$self->{TITLE},$self->{UNIXNAME}, $self->{MODULEDIR}, $self->{SRCDIR}) = split(":", @_[1]); - } else { - $self->{LOCATION} = @_[1]; - $self->{TITLE} = @_[2]; - $self->{UNIXNAME} = @_[3]; - $self->{MODULEDIR} = @_[4]; - $self->{SRCDIR} = @_[5]; - } - return $self; + my $self = {}; + bless($self); + if ((scalar(@_)-1) == 1) { + ($self->{LOCATION},$self->{TITLE},$self->{UNIXNAME}, $self->{MODULEDIR}, $self->{SRCDIR}) = split(":", @_[1]); + } else { + $self->{LOCATION} = @_[1]; + $self->{TITLE} = @_[2]; + $self->{UNIXNAME} = @_[3]; + $self->{MODULEDIR} = @_[4]; + $self->{SRCDIR} = @_[5]; + } + + # count lines in the report + open(FILE,getRptFile($self)); + my @x = ; + close(FILE); + my $lines; + foreach (@x) { + $lines = $lines + 1 if $_ =~ "{LINES} = sprintf("%0.f", $lines/4); + + # get NCSS lines + if (! -e getNCSSFile($self)) { + $self->{NCSS} = "TBD"; + } else { + open(FILE,getNCSSFile($self)); + my @x = ; + close(FILE); + @splits = split(/:/,$x[0]); + $self->{NCSS} = $splits[1]; + } + + return $self; } sub getLines() { - my $self = shift; - open(FILE,getRptFile($self)); - my @x = ; - close(FILE); - my $lines; - foreach (@x) { - $lines = $lines + 1 if $_ =~ "{LINES} +} + +sub getPctg() { + my $self = shift; + my $mungencss = $self->{NCSS}; + if ($mungencss == 0) { + $mungencss = 1; + } + return (int(($self->{LINES}/$mungencss)*10000))/100; } sub getCPDLines() { - my $self = shift; - open(FILE,getCPDRptFile($self)); - my @x = ; - close(FILE); - my $lines; - foreach (@x) { - $lines = $lines + 1 if $_ =~ "================================="; - } - return sprintf("%0.f", $lines); + my $self = shift; + open(FILE,getCPDRptFile($self)); + my @x = ; + close(FILE); + my $lines; + foreach (@x) { + $lines = $lines + 1 if $_ =~ "================================="; + } + return sprintf("%0.f", $lines); } sub getNCSS() { - my $self=shift; - if (! -e getNCSSFile($self)) { - return "TBD"; - } - open(FILE,getNCSSFile($self)); - my @x = ; - close(FILE); - @splits = split(/:/,$x[0]); - return $splits[1]; + my $self = shift; + return $self->{NCSS}; } sub getLocation() { @@ -115,7 +133,7 @@ sub getCPDRptURL() { sub getRptFile() { my $self = shift; - my $name = $self->getReportName(); + my $name = getReportName($self); return "../htdocs/reports/${name}"; } diff --git a/pmd-web/src/webpmd.pl b/pmd-web/src/webpmd.pl index 9c1e6be969..743915e6bc 100644 --- a/pmd-web/src/webpmd.pl +++ b/pmd-web/src/webpmd.pl @@ -66,7 +66,7 @@ sub loadProjectList() { } } - @newprojects = sort { $b->getLocation() cmp $a->getLocation() || $a->getTitle() cmp $b->getTitle() } @projects; + @newprojects = sort { $a->getPctg() cmp $b->getPctg() } @projects; my $result=""; foreach $project (@newprojects) { @@ -76,23 +76,19 @@ sub loadProjectList() { } $result="${result}"; $result="${result}"; - my $ncss = $project->getNCSS(); - if ($ncss == 0) { - $ncss = 1; - } - my $rounded = (int(($project->getLines()/$ncss)*10000))/100; + my $pctg = $project->getPctg(); my $color="red"; - if ($rounded < .2) { + if ($pctg < .2) { $color="#00ff00"; - } elsif ($rounded < .8 ) { + } elsif ($pctg < .8 ) { $color="yellow"; } - $rounded = sprintf("%0.2f", $rounded); + $pctg = sprintf("%0.2f", $pctg); if ($project->getNCSS() == "TBD") { - $rounded = "N/A"; + $pctg = "N/A"; $color = "white"; } - $result="${result}"; + $result="${result}"; my $cpdLink="0"; if (-e $project->getCPDRptFile() && $project->getCPDLines() > 0) { $cpdLink="getCPDRptURL]}\">@{[$project->getCPDLines()]}";
ProjectHome pageNCSSProblemsPercentage
Unused Code
Duplicate
Code
${jobLink}@{[$project->getHomePage()]}@{[$project->getNCSS()]}@{[$project->getLines()]}$rounded@{[$project->getLines()]}$pctg