Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the usage of expressions with combined operators #2121

Open
elfring opened this issue Nov 25, 2021 · 7 comments 路 May be fixed by #2685
Open

Increase the usage of expressions with combined operators #2121

elfring opened this issue Nov 25, 2021 · 7 comments 路 May be fixed by #2685

Comments

@elfring
Copy link

elfring commented Nov 25, 2021

Description

馃憖 Some source code analysis tools can help to find opportunities for improving software components.
馃挱 I propose to increase the usage of combined operators accordingly.

Change suggestion

diff --git a/install/db/dbmigrate_3.5-3.6.php b/install/db/dbmigrate_3.5-3.6.php
index 3f754f95a..1cc373bbc 100644
--- a/install/db/dbmigrate_3.5-3.6.php
+++ b/install/db/dbmigrate_3.5-3.6.php
@@ -134,7 +134,7 @@ function updateHash($dbManager, $tableName)
     $dbManager->queryOnce($sql, __METHOD__ . ".update.$tableName.hash");
     $dbManager->commit();
 
-    $totalCount = $totalCount + $numberOfRecords;
+    $totalCount += $numberOfRecords;
     $numberOfRecords = calculateNumberOfRecordsToBeProcessed($dbManager, $tableName, "hash");
     $numberOfRecords = $numberOfRecords[0];
   }
@@ -193,7 +193,7 @@ function updateSHA256($dbManager, $tableName)
     $dbManager->queryOnce($sql, __METHOD__ . ".updatePfile_SHA256");
     $dbManager->commit();
 
-    $totalCount = $totalCount + $numberOfRecords;
+    $totalCount += $numberOfRecords;
     echo "* $totalCount pfile records updated *\n";
 
     $records = calculateNumberOfRecordsToBeProcessed($dbManager, $tableName, $tableName."_sha256");
diff --git a/install/db/dbmigrate_copyright-event.php b/install/db/dbmigrate_copyright-event.php
index 9ac75bde1..ac38039fd 100644
--- a/install/db/dbmigrate_copyright-event.php
+++ b/install/db/dbmigrate_copyright-event.php
@@ -102,7 +102,7 @@ function insertDataInToEventTables($dbManager)
       } else {
         $i = $j;
       }
-      $j = $j + MAX_SIZE_OF_ROW;
+      $j += MAX_SIZE_OF_ROW;
       $dbManager->commit();
       $endTime = microtime(true);
       $totalTime = ($endTime - $startTime);
diff --git a/src/cli/fo_antelink.php b/src/cli/fo_antelink.php
index 18925f817..1187037eb 100755
--- a/src/cli/fo_antelink.php
+++ b/src/cli/fo_antelink.php
@@ -407,7 +407,7 @@ function writeacme_project($project, $Verbose)
    * Watch out for time stamps in milliseconds
    */
   if ($projectDate > 20000000000) {
-    $projectDate = $projectDate / 1000; // convert to seconds if necessary
+    $projectDate /= 1000; // convert to seconds if necessary
   }
   $releasedate = date("Ymd", $projectDate);
 
diff --git a/src/delagent/agent_tests/Functional/ft_cliDelagentTest.php b/src/delagent/agent_tests/Functional/ft_cliDelagentTest.php
index 55a3aaf0a..93cda5d15 100644
--- a/src/delagent/agent_tests/Functional/ft_cliDelagentTest.php
+++ b/src/delagent/agent_tests/Functional/ft_cliDelagentTest.php
@@ -61,7 +61,7 @@ class ft_cliDelagentTest extends \PHPUnit\Framework\TestCase {
       $message = 'FATAL: cannot find executable file, stop testing\n');
     }
     // run it
-    $EXE_PATH = $EXE_PATH." -c $DB_CONF";
+    $EXE_PATH .=" -c $DB_CONF";
     $last = exec("$EXE_PATH -h 2>&1", $out, $rtn);
     $this->assertEquals($usage, $out[0]); // check if executable file delagent is exited
     $this->assertEquals($usageL, $out[6]); // check if the option -L removed
diff --git a/src/mimetype/agent_tests/Functional/cliParamsTest4Mimetype.php b/src/mimetype/agent_tests/Functional/cliParamsTest4Mimetype.php
index 0d8bf7fc5..b57052d5c 100644
--- a/src/mimetype/agent_tests/Functional/cliParamsTest4Mimetype.php
+++ b/src/mimetype/agent_tests/Functional/cliParamsTest4Mimetype.php
@@ -84,7 +84,7 @@ class cliParamsTest4Mimetype extends \PHPUnit\Framework\TestCase {
       $message = 'FATAL: cannot find executable file, stop testing\n');
     }
     // run it
-    $EXE_PATH = $EXE_PATH." -C -c $DB_CONF";
+    $EXE_PATH .=" -C -c $DB_CONF";
     $last = exec("$EXE_PATH -h 2>&1", $out, $rtn);
     $this->assertEquals($usage, $out[0]); // check if executable file mimetype is exited
   }
diff --git a/src/nomos/agent_tests/testdata/NomosTestfiles/Unlicense/bitcoin.php b/src/nomos/agent_tests/testdata/NomosTestfiles/Unlicense/bitcoin.php
index f76421414..2e59ee747 100644
--- a/src/nomos/agent_tests/testdata/NomosTestfiles/Unlicense/bitcoin.php
+++ b/src/nomos/agent_tests/testdata/NomosTestfiles/Unlicense/bitcoin.php
@@ -63,7 +63,7 @@ class Bitcoin {
       $dv = (string) bcdiv($dec, "16", 0);
       $rem = (integer) bcmod($dec, "16");
       $dec = $dv;
-      $return = $return . self::$hexchars[$rem];
+      $return .= self::$hexchars[$rem];
     }
     return strrev($return);
   }
@@ -118,7 +118,7 @@ class Bitcoin {
       $dv = (string) bcdiv($hex, "58", 0);
       $rem = (integer) bcmod($hex, "58");
       $hex = $dv;
-      $return = $return . self::$base58chars[$rem];
+      $return .= self::$base58chars[$rem];
     }
     $return = strrev($return);
 
diff --git a/src/spdx2/agent/spdx2.php b/src/spdx2/agent/spdx2.php
index 058f8201b..0fd2cbe1b 100644
--- a/src/spdx2/agent/spdx2.php
+++ b/src/spdx2/agent/spdx2.php
@@ -240,7 +240,7 @@ class SpdxTwoAgent extends Agent
       case "spdx2tv":
         break;
       case "dep5":
-        $prefix = $prefix . "copyright-";
+        $prefix .= "copyright-";
         break;
     }
     return $prefix . $partname . $postfix;
@@ -259,13 +259,13 @@ class SpdxTwoAgent extends Agent
       $fileName = strtoupper($this->outputFormat)."_".$packageName.'_'.time();
       switch ($this->outputFormat) {
         case "spdx2":
-          $fileName = $fileName ."-spdx.rdf";
+          $fileName .="-spdx.rdf";
           break;
         case "spdx2tv":
-          $fileName = $fileName .".spdx";
+          $fileName .=".spdx";
           break;
         case "dep5":
-          $fileName = $fileName .".txt";
+          $fileName .=".txt";
           break;
       }
       $this->filebasename = $fileName;
diff --git a/src/testing/dataFiles/mailTo.php b/src/testing/dataFiles/mailTo.php
index 3ff3a51c5..17884d511 100644
--- a/src/testing/dataFiles/mailTo.php
+++ b/src/testing/dataFiles/mailTo.php
@@ -32,5 +32,5 @@ $mailTo = "mark.donohoe@hp.com mary.laser@hp.com ";
 $others = "bob.gobeille@hp.com dong.ma@hp.com alex.dav.norton@hp.com  yao-bin.shi@hp.com";
 
 // the whole team, comment out as needed
-$mailTo = $mailTo . $others;
+$mailTo .= $others;
 ?>
\ No newline at end of file
diff --git a/src/wget_agent/agent_tests/Functional/cliParamsTest4WgetAgent.php b/src/wget_agent/agent_tests/Functional/cliParamsTest4WgetAgent.php
index caa6f01c6..b4f0cda06 100644
--- a/src/wget_agent/agent_tests/Functional/cliParamsTest4WgetAgent.php
+++ b/src/wget_agent/agent_tests/Functional/cliParamsTest4WgetAgent.php
@@ -72,7 +72,7 @@ class cliParamsTest4Wget extends \PHPUnit\Framework\TestCase {
       $message = 'FATAL: cannot find executable file, stop testing\n');
     }
     // run it
-    $WGET_PATH = $WGET_PATH." -C -c $db_conf";
+    $WGET_PATH .=" -C -c $db_conf";
     $last = exec("$WGET_PATH -h 2>&1", $out, $rtn);
     $this->assertEquals($usage, $out[0]); // check if executable file wget_agent is exited
   }
@GMishx
Copy link
Member

GMishx commented May 18, 2022

Hey @elfring , would you like to create a PR for the changes proposed?

And I don't think src/nomos/agent_tests/testdata should be considered for this as it contains only testdata, no working code.

@elfring
Copy link
Author

elfring commented May 18, 2022

馃敭 Do you find any of the shown change possibilities acceptable?

@GMishx
Copy link
Member

GMishx commented May 20, 2022

Yes, all the changes suggested make sense.

Please ignore the src/nomos/agent_tests/testdata from any code refactoring.

@elfring
Copy link
Author

elfring commented May 20, 2022

馃挱 I find that adjustments can become helpful also for implementation details in test scripts.
Would you like to compare results from test variants any more? 馃

@GMishx
Copy link
Member

GMishx commented May 20, 2022

The folder mentioned holds test data for nomos scanner. You can consider them as plain text files as they are not executed by us. nomos uses the folder to perform regression tests. So, making changes in the folder is 1) unnecessary work as the code never executes 2) avoided as it can cause issues with the regression tests.

You can fix any code you find in the codebase except anything which has "testdata" in its path.

Sorry for not being clear but I hope this thread brings some clarity.

@elfring
Copy link
Author

elfring commented May 20, 2022

Thanks for your clarification.

I am unsure when the remaining change possibilities will be integrated. 馃

@amanreddy77
Copy link

hey i can fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants