• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wickedOne / gitlab-perl-helpers / 9930703181

14 Jul 2024 09:03PM UTC coverage: 100.0%. Remained the same
9930703181

push

github

web-flow
regex fixes (#30)

- fixed regex bug which caused the script to step out of the teardown
  too early.

2 of 2 new or added lines in 1 file covered. (100.0%)

842 of 842 relevant lines covered (100.0%)

21.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/GPH/PHPMD.pm
1
package GPH::PHPMD;
2

3
use strict;
1✔
4
use warnings FATAL => 'all';
1✔
5

6
use XML::LibXML;
1✔
7
use GPH::Util::XMLHelper;
1✔
8

9
sub new {
10
    my ($class, %args) = @_;
5✔
11

12
    (exists($args{owner}) and exists($args{cyclo_level})) or die "$!";
5✔
13

14
    my $self = {
15
        owner      => $args{owner},
16
        cycloLevel => $args{cyclo_level},
17
        generator  => GPH::Util::XMLHelper->new(),
3✔
18
    };
19

20
    bless $self, $class;
3✔
21

22
    return $self;
3✔
23
}
24

25
sub getConfig {
26
    my $self = shift;
1✔
27

28
    my $ruleset = $self->{generator}->buildElement((name => 'ruleset', attributes => {
1✔
29
        'xmlns:xsi'                     => 'http://www.w3.org/2001/XMLSchema-instance',
30
        'xsi:schemaLocation'            => 'http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd',
31
        'xsi:noNamespaceSchemaLocation' => 'http://pmd.sf.net/ruleset_xml_schema.xsd',
32
        'name'                          => "$self->{owner} PHPMD rule set",
33
    }));
34

35
    $ruleset->setNamespace('http://pmd.sf.net/ruleset/1.0.0');
1✔
36

37
    my $rule = $self->{generator}->buildElement((name => 'rule', parent => $ruleset, attributes => {
1✔
38
        'ref' => 'rulesets/codesize.xml/CyclomaticComplexity'
39
    }));
40

41
    my $properties = $self->{generator}->buildElement((name => 'properties', parent => $rule));
1✔
42

43
    $self->{generator}->buildElement((name => 'property', parent => $properties, attributes => {
44
        'name'  => 'reportLevel',
45
        'value' => $self->{cycloLevel}
46
    }));
1✔
47

48
    my $dom = $self->{generator}->getDom();
1✔
49

50
    $dom->setDocumentElement($ruleset);
1✔
51

52
    return ($dom->toString(1));
1✔
53
}
54

55
1;
56

57
__END__
58

59
=head1 NAME
60

61
GPH::PHPMD - generate custom configuration file for L<PHP Mess Detector|https://phpmd.org/>
62

63
=head1 SYNOPSIS
64

65
    use GPH::PHPMD;
66

67
    my $phpmd = GPH::PHPMD->new((
68
        owner       => '@teams/alpha',
69
        cyclo_level => 5,
70
    ));
71

72
    print $phpmd->getConfig();
73

74
=head1 METHODS
75

76
=over 4
77

78
=item C<< -E<gt>new(%args) >>
79

80
the C<new> method creates a new GPH::PHPMD instance. it takes a hash of options, valid option keys include:
81

82
=over
83

84
=item owner B<(required)>
85

86
code owner name
87

88
=item cyclo_level B<(required)>
89

90
cyclomatic complexity level
91

92
=back
93

94
=item C<< -E<gt>getConfig() >>
95

96
returns configuration xml for PHPMD
97

98
=back
99

100
=head1 AUTHOR
101

102
the GPH::PHPMD module was written by wicliff wolda <wicliff.wolda@gmail.com>
103

104
=head1 COPYRIGHT AND LICENSE
105

106
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
107

108
=cut
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc