JSV/Keyword/Draft4/Items.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 92.8% 13 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 92.3% 60 / 65 CC 9 SCAR 17.6
CC
9
Cov
95%
validate
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
« JSV/Keyword/Draft4/Type.pm ↑ Summary JSV/Util/Type.pm »
1 package JSV::Keyword::Draft4::Items;
2  
3 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 47 ▶use parent qw(JSV::Keyword);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 47 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 47 ▶use JSV::Keyword qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 47 ▶use JSV::Util::Type qw(detect_instance_type escape_json_pointer);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub instance_type() { INSTANCE_TYPE_ARRAY(); }
13 sub keyword() { "items" }
14 sub keyword_priority() { 10; }
15  
16 57 ▶sub validate {
Subroutine validate: called CC=9 SCAR=22.0
Pod undocumented
17 57 my ($class, $context, $schema, $instance) = @_;
18  
19 57 my $items = $class->keyword_value($schema);
20 57 my $additional_items = $class->keyword_value($schema, "additionalItems");
21  
22 57 my $items_type = detect_instance_type($items);
23 57 my $additional_items_type = detect_instance_type($additional_items);
24  
25 57 ▶ if ($items_type eq "object") { ### items as schema
Branch: 2 branches
BranchTrueFalseTotal
if ($items_type eq 'object') { } 21 36 57
elsif ($items_type eq 'array') { } 36 0 36
26 21 local $context->{current_schema_pointer} = $context->{current_schema_pointer} . "/" . $class->keyword;
27 21 ▶ for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $l) 49 21 70
28 49 local $context->{current_pointer} = $context->{current_pointer} . "/" . $i;
29 49 $context->validate($items, $instance->[$i]);
30 }
31 }
32 elsif ($items_type eq "array") { ### items as schema array
33 36 ▶ for (my $i = 0, my $l = scalar @$instance; $i < $l; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $l) 112 36 148
34 112 local $context->{current_pointer} = $context->{current_pointer} . "/" . $i;
35  
36 112 ▶ if (defined $items->[$i]) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $items->[$i]) { } 89 23 112
elsif ($additional_items_type eq 'object') { } 13 10 23
elsif ($additional_items_type eq 'boolean' and $additional_items == JSON::false()) { } 4 12 16
37 local $context->{current_schema_pointer} =
38 89 $context->{current_schema_pointer} . "/" . $class->keyword . "/" . $i;
39 89 $context->validate($items->[$i], $instance->[$i]);
40 }
41 elsif ($additional_items_type eq "object") {
42 local $context->{current_schema_pointer} =
43 13 $context->{current_schema_pointer} . "/additionalItems";
44 13 $context->validate($additional_items, $instance->[$i]);
45 }
46 ▶ elsif ($additional_items_type eq "boolean" && $additional_items == JSON::false) {
Condition66%2/3
$additional_items_type eq "boolean" and $additional_items == JSON::false()
!ll&&!rl&&r
604
MC/DC50%1/2
$additional_items_type eq "boolean" and $additional_items == JSON::false()
$additional_items_type eq "boolean" $additional_items == JSON::false()
Truth table66%2/3
A and B
A= $additional_items_type eq "boolean"B= $additional_items == JSON::false()
ABresult
0X0
100
111
47 4 $context->log_error("additionalItems are not allowed");
48 }
49 }
50 }
51 else { ### wrong schema
52 0 $context->log_error("Wrong schema definition");
53 }
54 }
55  
56 47 1;
« JSV/Keyword/Draft4/Type.pm ↑ Summary JSV/Util/Type.pm »