Bug 31333: (QA follow-up) Simplify code

The new syspref is a deny-list. So not being part of the list means you
are allowed. This was not that clear reading the code, so this patch
tries to simplify the logic. Better handling on undef syspref value is
added as well to avoid useless warnings.

This patch does the following changes:
- Uses `any` instead of `grep`. This has the effect of just returning a
  boolean on the first match, instead of keep looping until de array

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2022-10-05 15:14:22 -03:00
parent d08cd5965d
commit 8d2d63f7ae
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 6 additions and 7 deletions

View File

@ -220,14 +220,13 @@ sub can_make_suggestions {
my ( $self ) = @_;
if ( C4::Context->preference('suggestion') ) {
my @patron_categories = split ',', C4::Context->preference('suggestionPatronCategoryExceptions');
if ( @patron_categories ) {
my $categorycode = $self->categorycode;
return if grep {$_ eq $categorycode } @patron_categories;
}
return 1;
my @patron_categories = split ',', C4::Context->preference('suggestionPatronCategoryExceptions') // q{};
return !any {$_ eq $self->categorycode } @patron_categories;
}
return;
return 0;
}
=head2 Internal methods