From 7132c9b49ca0c2abf7592d56e4b467be9107dd3f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 28 Dec 2015 15:47:01 +0000 Subject: [PATCH] Bug 15209: Check the parameter at the beginning of the subroutines It seems better to check if parameters exist at the beginning of a subroutine. It makes the code easier to read and there is 1 indentation level less. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Signed-off-by: Brendan A Gallagher (cherry picked from commit 372881ebfd5552ecb83450c7afea6a76f2df1a0b) Signed-off-by: Julian Maurice --- C4/Koha.pm | 108 ++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 6339ed3270..b2a009a06d 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1538,29 +1538,27 @@ sub display_marc_indicators { sub GetNormalizedUPC { my ($marcrecord,$marcflavour) = @_; - if ($marcrecord) { - if ($marcflavour eq 'UNIMARC') { - my @fields = $marcrecord->field('072'); - foreach my $field (@fields) { - my $upc = _normalize_match_point($field->subfield('a')); - if ($upc) { - return $upc; - } + return unless $marcrecord; + if ($marcflavour eq 'UNIMARC') { + my @fields = $marcrecord->field('072'); + foreach my $field (@fields) { + my $upc = _normalize_match_point($field->subfield('a')); + if ($upc) { + return $upc; } - } - else { # assume marc21 if not unimarc - my @fields = $marcrecord->field('024'); - foreach my $field (@fields) { - my $indicator = $field->indicator(1); - my $upc = _normalize_match_point($field->subfield('a')); - if ($upc && $indicator == 1 ) { - return $upc; - } + + } + else { # assume marc21 if not unimarc + my @fields = $marcrecord->field('024'); + foreach my $field (@fields) { + my $indicator = $field->indicator(1); + my $upc = _normalize_match_point($field->subfield('a')); + if ($upc && $indicator == 1 ) { + return $upc; } } } - return; } # Normalizes and returns the first valid ISBN found in the record @@ -1573,60 +1571,60 @@ sub GetNormalizedISBN { ($isbn) = split(/\|/, $isbn ); return _isbn_cleanup($isbn); } - if ($marcrecord) { - - if ($marcflavour eq 'UNIMARC') { - my @fields = $marcrecord->field('010'); - foreach my $field (@fields) { - my $isbn = $field->subfield('a'); - if ($isbn) { - return _isbn_cleanup($isbn); - } + + return unless $marcrecord; + + if ($marcflavour eq 'UNIMARC') { + my @fields = $marcrecord->field('010'); + foreach my $field (@fields) { + my $isbn = $field->subfield('a'); + if ($isbn) { + return _isbn_cleanup($isbn); } } - else { # assume marc21 if not unimarc - my @fields = $marcrecord->field('020'); - foreach my $field (@fields) { - $isbn = $field->subfield('a'); - if ($isbn) { - return _isbn_cleanup($isbn); - } + } + else { # assume marc21 if not unimarc + my @fields = $marcrecord->field('020'); + foreach my $field (@fields) { + $isbn = $field->subfield('a'); + if ($isbn) { + return _isbn_cleanup($isbn); } } } - return; } sub GetNormalizedEAN { my ($marcrecord,$marcflavour) = @_; - if ($marcrecord) { - if ($marcflavour eq 'UNIMARC') { - my @fields = $marcrecord->field('073'); - foreach my $field (@fields) { - my $ean = _normalize_match_point($field->subfield('a')); - if ( $ean ) { - return $ean; - } + return unless $marcrecord; + + if ($marcflavour eq 'UNIMARC') { + my @fields = $marcrecord->field('073'); + foreach my $field (@fields) { + my $ean = _normalize_match_point($field->subfield('a')); + if ( $ean ) { + return $ean; } } - else { # assume marc21 if not unimarc - my @fields = $marcrecord->field('024'); - foreach my $field (@fields) { - my $indicator = $field->indicator(1); - my $ean = _normalize_match_point($field->subfield('a')); - if ( $ean && $indicator == 3 ) { - return $ean; - } + } + else { # assume marc21 if not unimarc + my @fields = $marcrecord->field('024'); + foreach my $field (@fields) { + my $indicator = $field->indicator(1); + my $ean = _normalize_match_point($field->subfield('a')); + if ( $ean && $indicator == 3 ) { + return $ean; } } } - return; } sub GetNormalizedOCLCNumber { my ($marcrecord,$marcflavour) = @_; - if ($marcrecord && $marcflavour ne 'UNIMARC' ) { + return unless $marcrecord; + + if ($marcflavour ne 'UNIMARC' ) { my @fields = $marcrecord->field('035'); foreach my $field (@fields) { my $oclc = $field->subfield('a'); @@ -1635,8 +1633,10 @@ sub GetNormalizedOCLCNumber { return $oclc; } } + } else { + # TODO for UNIMARC } - return; + return } sub GetAuthvalueDropbox { -- 2.39.5