Skip to content

Commit

Permalink
Issue #2116: avoid violations of Variables::RequireInitializationForL…
Browse files Browse the repository at this point in the history
…ocalVars

Either with a 'no critic' directive
or by assigning a value in same line as declaration with 'local'.
  • Loading branch information
bschmalhofer committed Jan 16, 2023
1 parent 0072b99 commit 0a5559c
Show file tree
Hide file tree
Showing 45 changed files with 75 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Kernel/Language/es_MX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6393,7 +6393,7 @@ Thanks for your help!
' => '
Estimado cliente,

Lamentablemente no hemos podido detectar un número de ticket válido
Lamentablemente no hemos podido detectar un número de ticket válido
en su asunto, por lo que este correo no puede ser procesado.

Por favor, cree un nuevo ticket a través del panel de cliente.
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/Console/Command/Admin/Package/UpgradeAll.pm
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ sub Run {
eval {
# Localize the standard error, everything will be restored after the eval block.
# Package installation or upgrades always produce messages in STDERR for files and directories.
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)

# Redirect the standard error to a variable.
open STDERR, '>>', \$ErrorMessage; ## no critic qw(OTOBO::ProhibitOpen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ sub Run {
}
else {
# read xml data from STDIN
$SourceXML = do { local $/; <> };
$SourceXML = do { local $/ = undef; <> };
}

for my $DatabaseType (@DatabaseType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ sub Run {
eval {

# Localize the standard error, everything will be restored after the eval block.
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)

# Redirect the standard error to a variable.
open STDERR, '>>', \$ErrorMessage; ## no critic qw(OTOBO::ProhibitOpen)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ sub Connect {
# have the callbacks with the attributes.
# But for now, the Callbacks are not part of the cache key in order to avoid serialised code.
my $CacheKey = do {
local $^W;
local $^W = undef;

join
"!\001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ sub Run {
local $SIG{CHLD} = 'DEFAULT';

# Localize the standard error, everything will be restored after the eval block.
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)

# Redirect the standard error to a variable.
open STDERR, '>>', \$ErrorMessage; ## no critic qw(OTOBO::ProhibitOpen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ sub Run {
local $SIG{CHLD} = 'DEFAULT';

# Localize the standard error, everything will be restored after the eval block.
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)

# Redirect the standard error to a variable.
open STDERR, ">>", \$ErrorMessage; ## no critic qw(OTOBO::ProhibitOpen)
Expand All @@ -148,8 +148,7 @@ sub Run {
# will be clean.
# Prevent used once warning, setting the variable as local and then assign the value
# in the next statement.
local $Kernel::System::Console::BaseCommand::SuppressANSI;
$Kernel::System::Console::BaseCommand::SuppressANSI = 1;
local $Kernel::System::Console::BaseCommand::SuppressANSI = 1;

# Run function on the module with the specified parameters in Data->{Params}
$Result = $ModuleObject->$Function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ sub Run {
local $SIG{CHLD} = 'DEFAULT';

# Localize the standard error, everything will be restored after the eval block.
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)

# Redirect the standard error to a variable.
open STDERR, '>>', \$ErrorMessage; ## no critic qw(OTOBO::ProhibitOpen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ sub Run {
local $SIG{CHLD} = 'DEFAULT';

# Localize the standard error, everything will be restored after the eval block.
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)

# Redirect the standard error to a variable.
open STDERR, '>>', \$ErrorMessage; ## no critic qw(OTOBO::ProhibitOpen)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/Main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ sub FileRead {
}

# read file as string
my $String = do { local $/; <$FH> };
my $String = do { local $/ = undef; <$FH> };
close $FH;

return \$String;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/MigrateFromOTRS/OTOBOPackageSpecifics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ sub _ITSM_ChangeDefinition {
my ( $Result, $ExitCode );

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute();
}
Expand Down
4 changes: 2 additions & 2 deletions Kernel/System/SupportBundleGenerator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ sub Generate {
# add files to the tar archive
open( my $Tar, '<', $Archive ); ## no critic qw(OTOBO::ProhibitOpen)
binmode $Tar;
my $TmpTar = do { local $/; <$Tar> };
my $TmpTar = do { local $/ = undef; <$Tar> };
close $Tar;

# remove all files
Expand Down Expand Up @@ -395,7 +395,7 @@ sub GenerateCustomFilesArchive {
}

binmode $TARFH;
my $TmpTar = do { local $/; <$TARFH> };
my $TmpTar = do { local $/ = undef; <$TARFH> };
close $TARFH;

if ( $Kernel::OM->Get('Kernel::System::Main')->Require('Compress::Zlib') ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sub Run {
my ( $CommandOutput, $ExitCode );

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$CommandOutput; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute();
}
Expand Down
6 changes: 3 additions & 3 deletions bin/otobo.Daemon.pl
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ sub Status {
if ( !flock( $FH, LOCK_EX | LOCK_NB ) ) {

# if no exclusive lock, daemon might be running, send signal to the PID
my $RegisteredPID = do { local $/; <$FH> };
my $RegisteredPID = do { local $/ = undef; <$FH> };
close $FH;

if ($RegisteredPID) {
Expand Down Expand Up @@ -515,7 +515,7 @@ sub _PIDLock {
return;
}

my $RegisteredPID = do { local $/; <$FH> };
my $RegisteredPID = do { local $/ = undef; <$FH> };
close $FH;

if ($RegisteredPID) {
Expand Down Expand Up @@ -551,7 +551,7 @@ sub _PIDUnlock {

# wait if PID is exclusively locked (and do a shared lock for reading)
flock $FH, LOCK_SH;
my $RegisteredPID = do { local $/; <$FH> };
my $RegisteredPID = do { local $/ = undef; <$FH> };
close $FH;

unlink $PIDFile;
Expand Down
4 changes: 2 additions & 2 deletions scripts/test/Console/Command/Admin/Config/FixInvalid.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ my $SysConfigDBObject = $Kernel::OM->Get('Kernel::System::SysConfig::DB');
my ( $Result, $ExitCode );

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute();
}
Expand Down Expand Up @@ -92,7 +92,7 @@ else {
ok( $Success, 'Setting updated' );

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute('--non-interactive');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ my $RunCommand = sub {
$ResultOut = '';

{
local *STDERR;
local *STDOUT;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDERR, '>:utf8', \$ResultErr; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
open STDOUT, '>:utf8', \$ResultOut; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute( '--non-interactive', @Args, );
Expand Down
4 changes: 2 additions & 2 deletions scripts/test/Console/Command/Admin/Config/ListInvalid.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ my $SysConfigDBObject = $Kernel::OM->Get('Kernel::System::SysConfig::DB');
my ( $Result, $ExitCode );

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute();
}
Expand Down Expand Up @@ -97,7 +97,7 @@ $Self->True(
);

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ my $SysConfigDBObject = $Kernel::OM->Get('Kernel::System::SysConfig::DB');
my ( $Result, $ExitCode );

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $ListCommandObject->Execute();
}
Expand All @@ -55,7 +55,7 @@ $Self->True(
);

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $FixCommandObject->Execute();
}
Expand Down Expand Up @@ -139,7 +139,7 @@ for my $SettingName ( sort keys %Settings ) {
}

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $ListCommandObject->Execute();
}
Expand All @@ -161,7 +161,7 @@ $Self->True(
# Have ListInvalid write yml file with invalid config.
my $YAMLFile = $Kernel::OM->Get('Kernel::Config')->Get('Home') . '/var/tmp/ListInvalidFixInvalid.yml';
{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $ListCommandObject->Execute( '--export-to-path', $YAMLFile );
}
Expand Down Expand Up @@ -218,7 +218,7 @@ $Self->True(
);

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $FixCommandObject->Execute( '--values-from-path', $YAMLFile, '--non-interactive' );
}
Expand All @@ -238,7 +238,7 @@ $Self->True(
);

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $ListCommandObject->Execute();
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/Console/Command/Admin/Config/UnlockAll.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ my $CommandObject = $Kernel::OM->Get('Kernel::System::Console::Command::Admin::C

my ( $Result, $ExitCode );
{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:encoding(UTF-8)', \$Result; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute();
$Kernel::OM->Get('Kernel::System::Encode')->EncodeInput( \$Result );
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/Console/Command/Admin/Package/UpgradeAll.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ else {

my ( $Result, $ExitCode );
{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:encoding(UTF-8)', \$Result; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute();
$Kernel::OM->Get('Kernel::System::Encode')->EncodeInput( \$Result );
Expand Down
6 changes: 3 additions & 3 deletions scripts/test/Console/Command/Admin/Queue/List.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ my $QueueID = $Kernel::OM->Get('Kernel::System::Queue')->QueueAdd(
);

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute();
}
Expand All @@ -68,7 +68,7 @@ $Self->True(
$Result = '';

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute('--all');
}
Expand All @@ -87,7 +87,7 @@ $Self->True(
$Result = '';

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute( '--all', '--verbose' );
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/Console/Command/Admin/WebService/List.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ my $CommandObject = $Kernel::OM->Get('Kernel::System::Console::Command::Admin::W
my ( $Result, $ExitCode );

{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute();
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/Console/Command/Dev/Code/CPANAudit.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ my $ExitCode = $CommandObject->Execute();

my $Output;
{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:encoding(UTF-8)', \$Output; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute();
$Kernel::OM->Get('Kernel::System::Encode')->EncodeInput( \$Output );
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/Console/Command/Dev/Package/RepositoryIndex.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');

my $Result;
{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:utf8', \$Result; ## no critic qw(OTOBO::ProhibitOpen InputOutput::RequireEncodingWithUTF8Layer)
$ExitCode = $CommandObject->Execute("$Home/Kernel/Config/Files");
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/Console/Command/Dev/Tools/Config2Docbook.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $Self->Is(

my $Result;
{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:encoding(UTF-8)', \$Result; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute( '--language', 'en' );
$Kernel::OM->Get('Kernel::System::Encode')->EncodeInput( \$Result );
Expand Down
8 changes: 4 additions & 4 deletions scripts/test/Console/Command/Dev/Tools/Migrate/OTRSToOTOBO.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ subtest
sub {
my ( $ExitCode, $Stderr );
{
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDERR, '>:encoding(UTF-8)', \$Stderr; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute(
"--source" => "$Home/Kernel/Config/Files/NotExisting/Source",
Expand All @@ -59,7 +59,7 @@ subtest
sub {
my ( $ExitCode, $Stderr );
{
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDERR, '>:encoding(UTF-8)', \$Stderr; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute(
"--target" => "$Home/Kernel/Config/Files/NotExisting/Target",
Expand All @@ -80,7 +80,7 @@ subtest
sub {
my ( $ExitCode, $Stderr );
{
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDERR, '>:encoding(UTF-8)', \$Stderr; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute(
"--target" => "$Home/Kernel/Config/Files/NotExisting/Target",
Expand Down Expand Up @@ -113,7 +113,7 @@ subtest

my ( $ExitCode, $Stderr );
{
local *STDERR;
local *STDERR; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDERR, '>:encoding(UTF-8)', \$Stderr; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute(
'--cleanxmlconfig',
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/Console/Command/Dev/Tools/Shell.t
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ else {
my $Result;
my $ExitCode;
{
local *STDOUT;
local *STDOUT; ## no critic qw(Variables::RequireInitializationForLocalVars)
open STDOUT, '>:encoding(UTF-8)', \$Result; ## no critic qw(OTOBO::ProhibitOpen)
$ExitCode = $CommandObject->Execute( '--eval', $Test->{Code} );
$Kernel::OM->Get('Kernel::System::Encode')->EncodeInput( \$Result );
Expand Down
Loading

0 comments on commit 0a5559c

Please sign in to comment.