From 6e8dd1a2a1f3f6b23d6ab130e9f9e548562965e4 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Thu, 24 May 2018 15:38:36 +0200 Subject: [PATCH] TT#37221 fix perlcritic error Subroutines::ProhibitExplicitReturnUndef this is to clean the Sipwise TAP tests for this repo the critical places where undef is really the intended return value (because a scalar should always be returned) the rule has been overridden Change-Id: I66e217a03a00e0f366db9c0cbc5007dd15cd9f96 --- lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm | 2 +- lib/NGCP/Panel/Form/ProfilePackage/PackageAPI.pm | 2 +- lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm | 2 +- lib/NGCP/Panel/Form/Topup/Log.pm | 2 +- lib/NGCP/Panel/Utils/BillingMappings.pm | 2 +- lib/NGCP/Panel/Utils/BillingNetworks.pm | 4 +++- lib/NGCP/Panel/Utils/ContractLocations.pm | 4 +++- lib/NGCP/Panel/Utils/Events.pm | 4 ++-- lib/NGCP/Panel/Utils/Form.pm | 2 +- lib/NGCP/Panel/Utils/Journal.pm | 9 +++++---- lib/NGCP/Panel/Utils/Peering.pm | 2 +- lib/NGCP/Panel/Utils/Preferences.pm | 2 +- lib/NGCP/Panel/Utils/ProfilePackages.pm | 6 +++--- lib/NGCP/Panel/Utils/Subscriber.pm | 2 +- t/api-rest/api-customercontacts.t | 4 ++-- t/api-rest/api-journals.t | 6 +++--- t/api-rest/api-lnp.t | 10 +++++----- t/api-rest/api-systemcontacts.t | 2 +- 18 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm b/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm index 6ebedfa703..27505071af 100644 --- a/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm +++ b/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm @@ -149,7 +149,7 @@ sub GET :Allow { sub item_base { my ($self,$c,$id) = @_; $c->stash->{contract_id} = $id; - return undef; + return; } sub item_get { diff --git a/lib/NGCP/Panel/Form/ProfilePackage/PackageAPI.pm b/lib/NGCP/Panel/Form/ProfilePackage/PackageAPI.pm index aad38a835f..7369b6c21b 100644 --- a/lib/NGCP/Panel/Form/ProfilePackage/PackageAPI.pm +++ b/lib/NGCP/Panel/Form/ProfilePackage/PackageAPI.pm @@ -257,7 +257,7 @@ has_field 'topup_profiles.network_id' => ( sub _deflate_lock_level { my ($self,$value) = @_; if (defined $value and length($value) == 0) { - return undef; + return; } return $value; } diff --git a/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm b/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm index 1817b357e3..61e6931480 100644 --- a/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm +++ b/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm @@ -346,7 +346,7 @@ has_block 'actions' => ( sub _deflate_lock_level { my ($self,$value) = @_; if (defined $value and length($value) == 0) { - return undef; + return; } return $value; } diff --git a/lib/NGCP/Panel/Form/Topup/Log.pm b/lib/NGCP/Panel/Form/Topup/Log.pm index d546023b02..23814450fe 100644 --- a/lib/NGCP/Panel/Form/Topup/Log.pm +++ b/lib/NGCP/Panel/Form/Topup/Log.pm @@ -181,7 +181,7 @@ sub deflate_money { sub _deflate_lock_level { my ($self,$value) = @_; if (defined $value and length($value) == 0) { - return undef; + return; } return $value; } diff --git a/lib/NGCP/Panel/Utils/BillingMappings.pm b/lib/NGCP/Panel/Utils/BillingMappings.pm index 98776f9868..1d27bc72d1 100644 --- a/lib/NGCP/Panel/Utils/BillingMappings.pm +++ b/lib/NGCP/Panel/Utils/BillingMappings.pm @@ -18,7 +18,7 @@ sub get_actual_billing_mapping { if ($bm_actual) { return $bm_actual->billing_mappings->first; } - return undef; + return; } sub get_actual_billing_mapping_stmt { diff --git a/lib/NGCP/Panel/Utils/BillingNetworks.pm b/lib/NGCP/Panel/Utils/BillingNetworks.pm index 700b8388fd..2f09296206 100644 --- a/lib/NGCP/Panel/Utils/BillingNetworks.pm +++ b/lib/NGCP/Panel/Utils/BillingNetworks.pm @@ -96,7 +96,7 @@ sub _set_ip_net_from_to { $resource->{_ipv6_net_from} = $from; $resource->{_ipv6_net_to} = $to; } - return undef; + return; } #deflate column values for search parameters doesn't work, so we need this sub @@ -119,6 +119,8 @@ sub _prepare_query_param_value { my ($q,$v) = @_; my ($bytes,$version) = _ip_to_bytes($q); if (defined $v) { + # really complex interaction + ## no critic (ProhibitExplicitReturnUndef) return undef if (!defined $bytes || $v != $version); return $bytes; } else { diff --git a/lib/NGCP/Panel/Utils/ContractLocations.pm b/lib/NGCP/Panel/Utils/ContractLocations.pm index e9b55fe8cb..9e44716f32 100644 --- a/lib/NGCP/Panel/Utils/ContractLocations.pm +++ b/lib/NGCP/Panel/Utils/ContractLocations.pm @@ -89,7 +89,7 @@ sub _set_ip_net_from_to { $resource->{_ipv6_net_from} = $from; $resource->{_ipv6_net_to} = $to; } - return undef; + return; } #deflate column values for search parameters doesn't work, so we need this sub @@ -112,6 +112,8 @@ sub _prepare_query_param_value { my ($q,$v) = @_; my ($bytes,$version) = _ip_to_bytes($q); if (defined $v) { + # really complex interaction + ## no critic (ProhibitExplicitReturnUndef) return undef if (!defined $bytes || $v != $version); return $bytes; } else { diff --git a/lib/NGCP/Panel/Utils/Events.pm b/lib/NGCP/Panel/Utils/Events.pm index c90594f341..6e139a6647 100644 --- a/lib/NGCP/Panel/Utils/Events.pm +++ b/lib/NGCP/Panel/Utils/Events.pm @@ -712,7 +712,7 @@ sub get_relation_value { return $relation_data->val; } } - return undef; + return; } sub get_tag_value { @@ -728,7 +728,7 @@ sub get_tag_value { return $tag_data->val; } } - return undef; + return; } 1; diff --git a/lib/NGCP/Panel/Utils/Form.pm b/lib/NGCP/Panel/Utils/Form.pm index f768509302..e409a3ff44 100644 --- a/lib/NGCP/Panel/Utils/Form.pm +++ b/lib/NGCP/Panel/Utils/Form.pm @@ -82,7 +82,7 @@ sub validate_entities { my $schema = $c->model('DB'); if ('CODE' ne ref $err_code) { - $err_code = sub { return undef; }; + $err_code = sub { return; }; } my $validate_field = sub { diff --git a/lib/NGCP/Panel/Utils/Journal.pm b/lib/NGCP/Panel/Utils/Journal.pm index 79c49b4064..880c362ca4 100644 --- a/lib/NGCP/Panel/Utils/Journal.pm +++ b/lib/NGCP/Panel/Utils/Journal.pm @@ -220,7 +220,7 @@ sub get_api_journal_query_params { sub handle_api_item_base_journal { my ($controller,$c,$id) = @_; $c->stash->{item_id_journal} = $id; - return undef; + return; } sub handle_api_journals_get { @@ -500,6 +500,7 @@ sub get_journal_relation_link { ) } } + ## no critic (ProhibitExplicitReturnUndef) return undef; } @@ -582,7 +583,7 @@ sub _serialize_content { #run this in eval only, deflate somehow inflicts a segf return Sereal::Encoder::encode_sereal($data); } } - return undef; + return; } sub _deserialize_content { @@ -600,7 +601,7 @@ sub _deserialize_content { return Sereal::Decoder::decode_sereal($serialized); } } - return undef; + return; } sub _create_journal { @@ -649,7 +650,7 @@ sub _create_journal { last; }; } - return undef; + return; } 1; diff --git a/lib/NGCP/Panel/Utils/Peering.pm b/lib/NGCP/Panel/Utils/Peering.pm index fb1432682f..7748a9f801 100644 --- a/lib/NGCP/Panel/Utils/Peering.pm +++ b/lib/NGCP/Panel/Utils/Peering.pm @@ -131,7 +131,7 @@ sub lookup { order_by => { -desc => qw/callee_prefix/ }, }); - return undef unless $rs->first; + return unless $rs->first; my %peer_data; my @peer_groups; diff --git a/lib/NGCP/Panel/Utils/Preferences.pm b/lib/NGCP/Panel/Utils/Preferences.pm index b9afdc85c4..c0395597bd 100644 --- a/lib/NGCP/Panel/Utils/Preferences.pm +++ b/lib/NGCP/Panel/Utils/Preferences.pm @@ -1207,7 +1207,7 @@ sub get_provisoning_voip_subscriber_first_int_attr_value { my $prov_subscriber= $params{prov_subscriber}; my $attribute = $params{attribute}; - return undef unless $prov_subscriber; + return unless $prov_subscriber; my $rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs( c => $c, diff --git a/lib/NGCP/Panel/Utils/ProfilePackages.pm b/lib/NGCP/Panel/Utils/ProfilePackages.pm index 97f0bf13be..95aa224d3d 100644 --- a/lib/NGCP/Panel/Utils/ProfilePackages.pm +++ b/lib/NGCP/Panel/Utils/ProfilePackages.pm @@ -859,7 +859,7 @@ sub _get_resized_interval_end { return NGCP::Panel::Utils::DateTime::infinite_future; } } - return undef; + return; } sub _get_interval_start { @@ -905,7 +905,7 @@ sub _add_interval { } return $to; } - return undef; + return; } sub _add_second { @@ -992,7 +992,7 @@ sub get_timely_range { $timely_end = _add_interval(NGCP::Panel::Utils::DateTime::set_local_tz($balance->start),$package->balance_interval_unit,$package->balance_interval_value, _START_MODE_PRESERVE_EOM->{$package->balance_interval_start_mode} ? NGCP::Panel::Utils::DateTime::set_local_tz($contract->create_timestamp // $contract->modify_timestamp) : undef)->subtract(seconds => 1); } - $timely_start = _add_second(_add_interval($timely_end,$timely_duration_unit,-1 * $timely_duration_value),1); + $timely_start = _add_second(scalar(_add_interval($timely_end,$timely_duration_unit,-1 * $timely_duration_value)),1); $timely_start = NGCP::Panel::Utils::DateTime::set_local_tz($balance->start) if $timely_start < NGCP::Panel::Utils::DateTime::set_local_tz($balance->start); $is_timely = ($now >= $timely_start && $now <= $timely_end ? 1 : 0); diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index aa59b597c6..c511aaa900 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -178,7 +178,7 @@ sub lock_provisoning_voip_subscriber { sub get_provisoning_voip_subscriber_lock_level { my %params = @_; - NGCP::Panel::Utils::Preferences::get_provisoning_voip_subscriber_first_int_attr_value(%params, + return NGCP::Panel::Utils::Preferences::get_provisoning_voip_subscriber_first_int_attr_value(%params, attribute => 'lock' ); } diff --git a/t/api-rest/api-customercontacts.t b/t/api-rest/api-customercontacts.t index 4d015546b6..31bb1452e1 100644 --- a/t/api-rest/api-customercontacts.t +++ b/t/api-rest/api-customercontacts.t @@ -361,7 +361,7 @@ sub _delete_customer_contact { $req = HTTP::Request->new('GET', $url); $res = $ua->request($req); is($res->code, 200, "test customer contact is still found"); - return undef; + return; } } @@ -452,7 +452,7 @@ sub _delete_subscriber { $req = HTTP::Request->new('GET', $url); $res = $ua->request($req); is($res->code, 200, "test subscriber is still found"); - return undef; + return; } } diff --git a/t/api-rest/api-journals.t b/t/api-rest/api-journals.t index 4b1c285c76..69ee83990e 100644 --- a/t/api-rest/api-journals.t +++ b/t/api-rest/api-journals.t @@ -860,7 +860,7 @@ sub test_ccmapentries { _test_journal_collection('ccmapentries',$subscriber->{id},$journals); - return undef; + return; } @@ -925,7 +925,7 @@ sub test_callforwards { _test_journal_collection('callforwards',$subscriber->{id},$journals); - return undef; + return; } @@ -2477,7 +2477,7 @@ sub _get_preference_value { } } } - return undef; + return; } sub _to_json { diff --git a/t/api-rest/api-lnp.t b/t/api-rest/api-lnp.t index 5766db76bc..c4c9d00fe9 100644 --- a/t/api-rest/api-lnp.t +++ b/t/api-rest/api-lnp.t @@ -202,7 +202,7 @@ sub _create_lnp_number { return $number; } else { is($res->code, $expected_code, "create test lnp number returns $expected_code"); - return undef; + return; } } @@ -234,7 +234,7 @@ sub _update_lnp_number { is($res->code, 200, "fetch test lnp number"); my $got_number = JSON::from_json($res->decoded_content); is_deeply($got_number,$number,"lnp number unchanged"); - return undef; + return; } } @@ -259,7 +259,7 @@ sub _delete_lnp_number { $req->header('X-Fake-Clienttime' => _get_fake_clienttime_now()); $res = $ua->request($req); is($res->code, 200, "test lnp number is still found"); - return undef; + return; } } @@ -313,7 +313,7 @@ sub _create_lnp_provider { return $carrier; } else { is($res->code, $expected_code, "create test lnp carrier returns $expected_code"); - return undef; + return; } } @@ -336,7 +336,7 @@ sub _delete_lnp_provider { $req = HTTP::Request->new('GET', $url); $res = $ua->request($req); is($res->code, 200, "test lnp carrier is still found"); - return undef; + return; } } diff --git a/t/api-rest/api-systemcontacts.t b/t/api-rest/api-systemcontacts.t index cda9e5fd09..d6360ba304 100644 --- a/t/api-rest/api-systemcontacts.t +++ b/t/api-rest/api-systemcontacts.t @@ -307,7 +307,7 @@ sub _delete_system_contact { $req = HTTP::Request->new('GET', $url); $res = $ua->request($req); is($res->code, 200, "test system contact is still found"); - return undef; + return; } }